Merge branch 'master' of https://github.com/Tydude4Christ/Newtonsoft.Json into Tydude4Christ-master

This commit is contained in:
James Newton-King
2016-03-04 20:32:40 +13:00
2 changed files with 13 additions and 12 deletions
@@ -55,6 +55,7 @@ namespace Newtonsoft.Json.Tests.Utilities
Assert.AreEqual("iPhone", StringUtils.ToCamelCase("IPhone")); Assert.AreEqual("iPhone", StringUtils.ToCamelCase("IPhone"));
Assert.AreEqual("i Phone", StringUtils.ToCamelCase("I Phone")); Assert.AreEqual("i Phone", StringUtils.ToCamelCase("I Phone"));
Assert.AreEqual(" IPhone", StringUtils.ToCamelCase(" IPhone")); Assert.AreEqual(" IPhone", StringUtils.ToCamelCase(" IPhone"));
Assert.AreEqual("isCIA", StringUtils.ToCamelCase("IsCIA"));
} }
} }
} }
+12 -12
View File
@@ -170,26 +170,26 @@ namespace Newtonsoft.Json.Utilities
public static string ToCamelCase(string s) public static string ToCamelCase(string s)
{ {
if (string.IsNullOrEmpty(s)) if (string.IsNullOrEmpty(s) || !char.IsUpper(s[0]))
{
return s;
}
if (!char.IsUpper(s[0]))
{ {
return s; return s;
} }
char[] chars = s.ToCharArray(); char[] chars = s.ToCharArray();
for (int i = 0; i < chars.Length; i++) int toLowerUntilIndex = 1;
while (toLowerUntilIndex < chars.Length && char.IsUpper(chars[toLowerUntilIndex]))
{ {
bool hasNext = (i + 1 < chars.Length); ++toLowerUntilIndex;
if (i > 0 && hasNext && !char.IsUpper(chars[i + 1])) }
{ // decrement if starts with consecutive upper case letters but is not all upper
break; if (toLowerUntilIndex > 1 && toLowerUntilIndex < chars.Length)
} {
--toLowerUntilIndex;
}
for (int i = 0; i < toLowerUntilIndex; ++i)
{
#if !(DOTNET || PORTABLE) #if !(DOTNET || PORTABLE)
chars[i] = char.ToLower(chars[i], CultureInfo.InvariantCulture); chars[i] = char.ToLower(chars[i], CultureInfo.InvariantCulture);
#else #else