-Minor fixes

This commit is contained in:
James Newton-King
2016-05-31 00:27:51 +12:00
parent 77a3a7d28d
commit 9eb14a6590
5 changed files with 19 additions and 7 deletions
@@ -64,6 +64,10 @@ namespace Newtonsoft.Json.Tests.Utilities
Assert.AreEqual("snA__kEcAsE", StringUtils.ToCamelCase("SnA__kEcAsE")); Assert.AreEqual("snA__kEcAsE", StringUtils.ToCamelCase("SnA__kEcAsE"));
Assert.AreEqual("snA__ kEcAsE", StringUtils.ToCamelCase("SnA__ kEcAsE")); Assert.AreEqual("snA__ kEcAsE", StringUtils.ToCamelCase("SnA__ kEcAsE"));
Assert.AreEqual("already_snake_case_ ", StringUtils.ToCamelCase("already_snake_case_ ")); Assert.AreEqual("already_snake_case_ ", StringUtils.ToCamelCase("already_snake_case_ "));
Assert.AreEqual("isJSONProperty", StringUtils.ToCamelCase("IsJSONProperty"));
Assert.AreEqual("shoutinG_CASE", StringUtils.ToCamelCase("SHOUTING_CASE"));
Assert.AreEqual("9999-12-31T23:59:59.9999999Z", StringUtils.ToCamelCase("9999-12-31T23:59:59.9999999Z"));
Assert.AreEqual("hi!! This is text. Time to test.", StringUtils.ToCamelCase("Hi!! This is text. Time to test."));
} }
[Test] [Test]
@@ -89,6 +93,10 @@ namespace Newtonsoft.Json.Tests.Utilities
Assert.AreEqual("sn_a__k_ec_as_e", StringUtils.ToSnakeCase("SnA__kEcAsE")); Assert.AreEqual("sn_a__k_ec_as_e", StringUtils.ToSnakeCase("SnA__kEcAsE"));
Assert.AreEqual("sn_a__k_ec_as_e", StringUtils.ToSnakeCase("SnA__ kEcAsE")); Assert.AreEqual("sn_a__k_ec_as_e", StringUtils.ToSnakeCase("SnA__ kEcAsE"));
Assert.AreEqual("already_snake_case_", StringUtils.ToSnakeCase("already_snake_case_ ")); Assert.AreEqual("already_snake_case_", StringUtils.ToSnakeCase("already_snake_case_ "));
Assert.AreEqual("is_json_property", StringUtils.ToSnakeCase("IsJSONProperty"));
Assert.AreEqual("shouting_case", StringUtils.ToSnakeCase("SHOUTING_CASE"));
Assert.AreEqual("9999-12-31_t23:59:59.9999999_z", StringUtils.ToSnakeCase("9999-12-31T23:59:59.9999999Z"));
Assert.AreEqual("hi!!_this_is_text._time_to_test.", StringUtils.ToSnakeCase("Hi!! This is text. Time to test."));
} }
} }
} }
@@ -53,7 +53,7 @@ namespace Newtonsoft.Json
public string Description { get; set; } public string Description { get; set; }
/// <summary> /// <summary>
/// Gets the collection's items converter. /// Gets or sets the collection's items converter.
/// </summary> /// </summary>
/// <value>The collection's items converter.</value> /// <value>The collection's items converter.</value>
public Type ItemConverterType { get; set; } public Type ItemConverterType { get; set; }
@@ -70,7 +70,7 @@ namespace Newtonsoft.Json
public object[] ItemConverterParameters { get; set; } public object[] ItemConverterParameters { get; set; }
/// <summary> /// <summary>
/// Gets the <see cref="Type"/> of the <see cref="NamingStrategy"/>. /// Gets or sets the <see cref="Type"/> of the <see cref="NamingStrategy"/>.
/// </summary> /// </summary>
/// <value>The <see cref="Type"/> of the <see cref="NamingStrategy"/>.</value> /// <value>The <see cref="Type"/> of the <see cref="NamingStrategy"/>.</value>
public Type NamingStrategyType public Type NamingStrategyType
+1 -1
View File
@@ -66,7 +66,7 @@ namespace Newtonsoft.Json
public object[] ItemConverterParameters { get; set; } public object[] ItemConverterParameters { get; set; }
/// <summary> /// <summary>
/// Gets the <see cref="Type"/> of the <see cref="NamingStrategy"/>. /// Gets or sets the <see cref="Type"/> of the <see cref="NamingStrategy"/>.
/// </summary> /// </summary>
/// <value>The <see cref="Type"/> of the <see cref="NamingStrategy"/>.</value> /// <value>The <see cref="Type"/> of the <see cref="NamingStrategy"/>.</value>
public Type NamingStrategyType { get; set; } public Type NamingStrategyType { get; set; }
@@ -23,7 +23,7 @@
/// </summary> /// </summary>
/// <param name="name">The initial property name.</param> /// <param name="name">The initial property name.</param>
/// <param name="hasSpecifiedName">A flag indicating whether the property has had a name explicitly specfied.</param> /// <param name="hasSpecifiedName">A flag indicating whether the property has had a name explicitly specfied.</param>
/// <returns>A property name.</returns> /// <returns>The serialized property name.</returns>
public virtual string GetPropertyName(string name, bool hasSpecifiedName) public virtual string GetPropertyName(string name, bool hasSpecifiedName)
{ {
if (hasSpecifiedName && !OverrideSpecifiedNames) if (hasSpecifiedName && !OverrideSpecifiedNames)
@@ -38,7 +38,7 @@
/// Gets the serialized key for a given dictionary key. /// Gets the serialized key for a given dictionary key.
/// </summary> /// </summary>
/// <param name="key">The initial dictionary key.</param> /// <param name="key">The initial dictionary key.</param>
/// <returns>A dictionary key.</returns> /// <returns>The serialized dictionary key.</returns>
public virtual string GetDictionaryKey(string key) public virtual string GetDictionaryKey(string key)
{ {
if (!ProcessDictionaryKeys) if (!ProcessDictionaryKeys)
+6 -2
View File
@@ -213,9 +213,13 @@ namespace Newtonsoft.Json.Utilities
{ {
case SnakeCaseState.Upper: case SnakeCaseState.Upper:
bool hasNext = (i + 1 < s.Length); bool hasNext = (i + 1 < s.Length);
if (i > 0 && hasNext && !char.IsUpper(s[i + 1])) if (i > 0 && hasNext)
{ {
sb.Append('_'); char nextChar = s[i + 1];
if (!char.IsUpper(nextChar) && nextChar != '_')
{
sb.Append('_');
}
} }
break; break;
case SnakeCaseState.Lower: case SnakeCaseState.Lower: