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 6fcf9cd commit 5a92a79
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 @@ -89,13 +89,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 @@ -118,11 +112,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 5a92a79

Please sign in to comment.