Skip to content

Commit

Permalink
refactor: DRY IfToLower and IfToUpper
Browse files Browse the repository at this point in the history
  • Loading branch information
sixcolors committed Mar 25, 2024
1 parent 3717ffb commit edefd68
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ func IfToLower(s string) string {
if !hasUpper {
return s
}
res := make([]byte, len(s))
copy(res, s)
for i := 0; i < len(res); i++ {
res[i] = toLowerTable[res[i]]
}

return UnsafeString(res)
return ToLower(s)
}

// IfToUpper returns an uppercase version of the input ASCII string.
Expand All @@ -75,11 +69,5 @@ func IfToUpper(s string) string {
if !hasLower {
return s
}
res := make([]byte, len(s))
copy(res, s)
for i := 0; i < len(res); i++ {
res[i] = toUpperTable[res[i]]
}

return UnsafeString(res)
return ToUpper(s)
}

0 comments on commit edefd68

Please # to comment.