зеркало из https://github.com/arthurnn/twirp-ruby.git
Fix modules with numbers in them.
Protoc ruby will output 'A2z' for package name 'a2z'.
This commit is contained in:
Родитель
a44e56b70d
Коммит
1960079afa
|
@ -242,13 +242,9 @@ func camelCase(s string) string {
|
|||
// case letter. Digits are treated as words.
|
||||
for ; i < len(s); i++ {
|
||||
c := s[i]
|
||||
if c == '_' && i+1 < len(s) && isASCIILower(s[i+1]) {
|
||||
if c == '_' && i+1 < len(s) && (isASCIILower(s[i+1]) || isASCIIDigit(s[i+1])) {
|
||||
continue // Skip the underscore in s.
|
||||
}
|
||||
if isASCIIDigit(c) {
|
||||
t = append(t, c)
|
||||
continue
|
||||
}
|
||||
// Assume we have a letter now - if not, it's a bogus identifier. The next
|
||||
// word is a sequence of characters that must start upper case.
|
||||
if isASCIILower(c) {
|
||||
|
@ -256,7 +252,7 @@ func camelCase(s string) string {
|
|||
}
|
||||
t = append(t, c) // Guaranteed not lower case.
|
||||
// Accept lower case sequence that follows.
|
||||
for i+1 < len(s) && isASCIILower(s[i+1]) {
|
||||
for i+1 < len(s) && (isASCIILower(s[i+1]) || isASCIIDigit(s[i+1])) {
|
||||
i++
|
||||
t = append(t, s[i])
|
||||
}
|
||||
|
|
|
@ -78,6 +78,8 @@ func TestCamelCase(t *testing.T) {
|
|||
{camelCase("FooBar"), "FooBar"},
|
||||
{camelCase("fooBar"), "FooBar"},
|
||||
{camelCase("myLong_miXEDName"), "MyLongMiXEDName"},
|
||||
{camelCase("a2z"), "A2z"},
|
||||
{camelCase("a_2z"), "A2z"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if tt.expected != tt.actual {
|
||||
|
|
Загрузка…
Ссылка в новой задаче