diff options
author | Jisi Liu <liujisi@google.com> | 2016-07-27 10:48:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-27 10:48:43 -0700 |
commit | be78976ac8659a2e959afd4fa22a2ddd69c28d71 (patch) | |
tree | f0d61334b9a07fd9c975867d9aff4f462ef118c4 | |
parent | af2fa056f71379808393c20374387aaa4ef0c7a4 (diff) | |
parent | a8aae8989cee8abc214f9942860b11d34a85fd79 (diff) | |
download | protobuf-be78976ac8659a2e959afd4fa22a2ddd69c28d71.tar.gz protobuf-be78976ac8659a2e959afd4fa22a2ddd69c28d71.tar.bz2 protobuf-be78976ac8659a2e959afd4fa22a2ddd69c28d71.zip |
Merge pull request #1861 from jskeet/fix_to_camel_case
Bring C#'s ToPascalCase method in line with C++.
-rw-r--r-- | csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs | 6 | ||||
-rw-r--r-- | csharp/src/Google.Protobuf/JsonFormatter.cs | 12 |
2 files changed, 16 insertions, 2 deletions
diff --git a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs index 51b3ca2d..261ac6a7 100644 --- a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs @@ -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)); diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs index a894ffa1..d8a814d9 100644 --- a/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -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(); } |