From f5fbd6fd3c29af44764b184a2a3cec377e208a6c Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 4 Mar 2016 21:31:36 +1300 Subject: [PATCH] -Refactored ToCamelCase --- Src/Newtonsoft.Json/Utilities/StringUtils.cs | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Src/Newtonsoft.Json/Utilities/StringUtils.cs b/Src/Newtonsoft.Json/Utilities/StringUtils.cs index 122fc837..09130116 100644 --- a/Src/Newtonsoft.Json/Utilities/StringUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/StringUtils.cs @@ -177,19 +177,19 @@ namespace Newtonsoft.Json.Utilities char[] chars = s.ToCharArray(); - int toLowerUntilIndex = 1; - while (toLowerUntilIndex < chars.Length && char.IsUpper(chars[toLowerUntilIndex])) + for (int i = 0; i < chars.Length; i++) { - ++toLowerUntilIndex; - } - // decrement if starts with consecutive upper case letters but is not all upper - if (toLowerUntilIndex > 1 && toLowerUntilIndex < chars.Length) - { - --toLowerUntilIndex; - } + if (i == 1 && !char.IsUpper(chars[i])) + { + break; + } + + bool hasNext = (i + 1 < chars.Length); + if (i > 0 && hasNext && !char.IsUpper(chars[i + 1])) + { + break; + } - for (int i = 0; i < toLowerUntilIndex; ++i) - { #if !(DOTNET || PORTABLE) chars[i] = char.ToLower(chars[i], CultureInfo.InvariantCulture); #else