private/version: replace custom stringsTitle

cases package has an option cases.NoLower for the behavior we need.

Change-Id: Ie5bd4c52384fff45228321e02ab2478b5fecf245
This commit is contained in:
Egon Elbre 2022-03-31 10:36:11 +03:00
parent 2a7b20e8e4
commit d9b14f7902

View File

@ -12,10 +12,11 @@ import (
"reflect"
"strings"
"time"
"unicode"
"github.com/spacemonkeygo/monkit/v3"
"github.com/zeebo/errs"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"storj.io/private/version"
)
@ -126,46 +127,5 @@ func (client *Client) Process(ctx context.Context, processName string) (process
}
func kebabToPascal(str string) string {
return strings.ReplaceAll(stringsTitle(str), "-", "")
}
func stringsTitle(s string) string {
// strings.Title and cases.Title(language.Und) do different things.
// For example:
// s := `StoragenodeUpdater`
// strings.Title(s) == `StoragenodeUpdater`
// cases.Title(language.Und).String(s) == `Storagenodeupdater`
// This reimplements strings.Title to bypass Deprecated notice.
prev := ' '
return strings.Map(
func(r rune) rune {
if isSeparator(prev) {
prev = r
return unicode.ToTitle(r)
}
prev = r
return r
}, s)
}
func isSeparator(r rune) bool {
// ASCII alphanumerics and underscore are not separators
if r <= 0x7F {
switch {
case '0' <= r && r <= '9':
return false
case 'a' <= r && r <= 'z':
return false
case 'A' <= r && r <= 'Z':
return false
case r == '_':
return false
}
return true
}
if unicode.IsLetter(r) || unicode.IsDigit(r) {
return false
}
return unicode.IsSpace(r)
return strings.ReplaceAll(cases.Title(language.Und, cases.NoLower).String(str), "-", "")
}