Merge pull request #1861 from jskeet/fix_to_camel_case
Bring C#'s ToPascalCase method in line with C++.
This commit is contained in:
commit
be78976ac8
@ -230,6 +230,12 @@ namespace Google.Protobuf
|
||||
[TestCase("foo_bar", "fooBar")]
|
||||
[TestCase("bananaBanana", "bananaBanana")]
|
||||
[TestCase("BANANABanana", "bananaBanana")]
|
||||
[TestCase("simple", "simple")]
|
||||
[TestCase("ACTION_AND_ADVENTURE", "actionAndAdventure")]
|
||||
[TestCase("action_and_adventure", "actionAndAdventure")]
|
||||
[TestCase("kFoo", "kFoo")]
|
||||
[TestCase("HTTPServer", "httpServer")]
|
||||
[TestCase("CLIENT", "client")]
|
||||
public void ToCamelCase(string original, string expected)
|
||||
{
|
||||
Assert.AreEqual(expected, JsonFormatter.ToCamelCase(original));
|
||||
|
@ -274,7 +274,6 @@ namespace Google.Protobuf
|
||||
}
|
||||
|
||||
// Converted from src/google/protobuf/util/internal/utility.cc ToCamelCase
|
||||
// TODO: Use the new field in FieldDescriptor.
|
||||
internal static string ToCamelCase(string input)
|
||||
{
|
||||
bool capitalizeNext = false;
|
||||
@ -305,6 +304,7 @@ namespace Google.Protobuf
|
||||
(!wasCap || (i + 1 < input.Length && char.IsLower(input[i + 1]))))
|
||||
{
|
||||
firstWord = false;
|
||||
result.Append(input[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -320,8 +320,16 @@ namespace Google.Protobuf
|
||||
result.Append(char.ToUpperInvariant(input[i]));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Append(input[i]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Append(char.ToLowerInvariant(input[i]));
|
||||
}
|
||||
result.Append(input[i]);
|
||||
}
|
||||
return result.ToString();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user