Skip to content

Commit edefd68

Browse files
committed
refactor: DRY IfToLower and IfToUpper
1 parent 3717ffb commit edefd68

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

strings.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ func IfToLower(s string) string {
4646
if !hasUpper {
4747
return s
4848
}
49-
res := make([]byte, len(s))
50-
copy(res, s)
51-
for i := 0; i < len(res); i++ {
52-
res[i] = toLowerTable[res[i]]
53-
}
54-
55-
return UnsafeString(res)
49+
return ToLower(s)
5650
}
5751

5852
// IfToUpper returns an uppercase version of the input ASCII string.
@@ -75,11 +69,5 @@ func IfToUpper(s string) string {
7569
if !hasLower {
7670
return s
7771
}
78-
res := make([]byte, len(s))
79-
copy(res, s)
80-
for i := 0; i < len(res); i++ {
81-
res[i] = toUpperTable[res[i]]
82-
}
83-
84-
return UnsafeString(res)
72+
return ToUpper(s)
8573
}

0 commit comments

Comments
 (0)