Commit a8aae898 authored by Jon Skeet's avatar Jon Skeet

Bring C#'s ToPascalCase method in line with C++.

(This still doesn't fix the conformance tests, but at least
we're now consistent with the C++ code.)
parent ba52f2b6
...@@ -230,6 +230,12 @@ namespace Google.Protobuf ...@@ -230,6 +230,12 @@ namespace Google.Protobuf
[TestCase("foo_bar", "fooBar")] [TestCase("foo_bar", "fooBar")]
[TestCase("bananaBanana", "bananaBanana")] [TestCase("bananaBanana", "bananaBanana")]
[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) public void ToCamelCase(string original, string expected)
{ {
Assert.AreEqual(expected, JsonFormatter.ToCamelCase(original)); Assert.AreEqual(expected, JsonFormatter.ToCamelCase(original));
......
...@@ -274,7 +274,6 @@ namespace Google.Protobuf ...@@ -274,7 +274,6 @@ namespace Google.Protobuf
} }
// Converted from src/google/protobuf/util/internal/utility.cc ToCamelCase // Converted from src/google/protobuf/util/internal/utility.cc ToCamelCase
// TODO: Use the new field in FieldDescriptor.
internal static string ToCamelCase(string input) internal static string ToCamelCase(string input)
{ {
bool capitalizeNext = false; bool capitalizeNext = false;
...@@ -305,6 +304,7 @@ namespace Google.Protobuf ...@@ -305,6 +304,7 @@ namespace Google.Protobuf
(!wasCap || (i + 1 < input.Length && char.IsLower(input[i + 1])))) (!wasCap || (i + 1 < input.Length && char.IsLower(input[i + 1]))))
{ {
firstWord = false; firstWord = false;
result.Append(input[i]);
} }
else else
{ {
...@@ -320,8 +320,16 @@ namespace Google.Protobuf ...@@ -320,8 +320,16 @@ namespace Google.Protobuf
result.Append(char.ToUpperInvariant(input[i])); result.Append(char.ToUpperInvariant(input[i]));
continue; continue;
} }
} else
{
result.Append(input[i]); result.Append(input[i]);
continue;
}
}
else
{
result.Append(char.ToLowerInvariant(input[i]));
}
} }
return result.ToString(); return result.ToString();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment