Skip to content

Commit

Permalink
Merge pull request protocolbuffers#1861 from jskeet/fix_to_camel_case
Browse files Browse the repository at this point in the history
Bring C#'s ToPascalCase method in line with C++.
  • Loading branch information
liujisi authored Jul 27, 2016
2 parents af2fa05 + a8aae89 commit be78976
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ public void InvalidSurrogatePairsFail()
[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));
Expand Down
12 changes: 10 additions & 2 deletions csharp/src/Google.Protobuf/JsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ private static string ToCamelCaseForFieldMask(string input)
}

// 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;
Expand Down Expand Up @@ -305,6 +304,7 @@ internal static string ToCamelCase(string input)
(!wasCap || (i + 1 < input.Length && char.IsLower(input[i + 1]))))
{
firstWord = false;
result.Append(input[i]);
}
else
{
Expand All @@ -320,8 +320,16 @@ internal static string ToCamelCase(string input)
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();
}
Expand Down

0 comments on commit be78976

Please sign in to comment.