Symbol chars used instead of single length strings

This commit is contained in:
Bruce Bowyer-Smyth
2014-07-28 16:30:10 +10:00
parent 490895716c
commit 432d262dcd
6 changed files with 27 additions and 16 deletions
@@ -1352,7 +1352,7 @@ namespace Newtonsoft.Json.Converters
string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName); string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);
if (propertyName.StartsWith("@", StringComparison.Ordinal)) if (propertyName.StartsWith('@'))
{ {
string attributeName = propertyName.Substring(1); string attributeName = propertyName.Substring(1);
string attributeValue = reader.Value.ToString(); string attributeValue = reader.Value.ToString();
+4 -4
View File
@@ -60,14 +60,14 @@ namespace Newtonsoft.Json
{ {
case JsonContainerType.Object: case JsonContainerType.Object:
if (sb.Length > 0) if (sb.Length > 0)
sb.Append("."); sb.Append('.');
sb.Append(PropertyName); sb.Append(PropertyName);
break; break;
case JsonContainerType.Array: case JsonContainerType.Array:
case JsonContainerType.Constructor: case JsonContainerType.Constructor:
sb.Append("["); sb.Append('[');
sb.Append(Position); sb.Append(Position);
sb.Append("]"); sb.Append(']');
break; break;
} }
} }
@@ -96,7 +96,7 @@ namespace Newtonsoft.Json
{ {
message = message.Trim(); message = message.Trim();
if (!message.EndsWith(".", StringComparison.Ordinal)) if (!message.EndsWith('.'))
message += "."; message += ".";
message += " "; message += " ";
+6 -6
View File
@@ -158,7 +158,7 @@ namespace Newtonsoft.Json
{ {
InternalWriteStart(JsonToken.StartObject, JsonContainerType.Object); InternalWriteStart(JsonToken.StartObject, JsonContainerType.Object);
_writer.Write("{"); _writer.Write('{');
} }
/// <summary> /// <summary>
@@ -168,7 +168,7 @@ namespace Newtonsoft.Json
{ {
InternalWriteStart(JsonToken.StartArray, JsonContainerType.Array); InternalWriteStart(JsonToken.StartArray, JsonContainerType.Array);
_writer.Write("["); _writer.Write('[');
} }
/// <summary> /// <summary>
@@ -181,7 +181,7 @@ namespace Newtonsoft.Json
_writer.Write("new "); _writer.Write("new ");
_writer.Write(name); _writer.Write(name);
_writer.Write("("); _writer.Write('(');
} }
/// <summary> /// <summary>
@@ -193,13 +193,13 @@ namespace Newtonsoft.Json
switch (token) switch (token)
{ {
case JsonToken.EndObject: case JsonToken.EndObject:
_writer.Write("}"); _writer.Write('}');
break; break;
case JsonToken.EndArray: case JsonToken.EndArray:
_writer.Write("]"); _writer.Write(']');
break; break;
case JsonToken.EndConstructor: case JsonToken.EndConstructor:
_writer.Write(")"); _writer.Write(')');
break; break;
default: default:
throw JsonWriterException.Create(this, "Invalid JsonToken: " + token, null); throw JsonWriterException.Create(this, "Invalid JsonToken: " + token, null);
+3 -3
View File
@@ -206,7 +206,7 @@ namespace Newtonsoft.Json.Linq
JProperty property = (JProperty)current; JProperty property = (JProperty)current;
if (sb.Length > 0) if (sb.Length > 0)
sb.Append("."); sb.Append('.');
sb.Append(property.Name); sb.Append(property.Name);
break; break;
@@ -214,9 +214,9 @@ namespace Newtonsoft.Json.Linq
case JTokenType.Constructor: case JTokenType.Constructor:
int index = ((IList<JToken>)current).IndexOf(next); int index = ((IList<JToken>)current).IndexOf(next);
sb.Append("["); sb.Append('[');
sb.Append(index); sb.Append(index);
sb.Append("]"); sb.Append(']');
break; break;
} }
} }
+2 -2
View File
@@ -341,8 +341,8 @@ namespace Newtonsoft.Json.Linq
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
return _initialPath; return _initialPath;
if (_initialPath.EndsWith("]", StringComparison.Ordinal) if (_initialPath.EndsWith(']')
|| path.StartsWith("[", StringComparison.Ordinal)) || path.StartsWith('['))
path = _initialPath + path; path = _initialPath + path;
else else
path = _initialPath + "." + path; path = _initialPath + "." + path;
@@ -197,5 +197,16 @@ namespace Newtonsoft.Json.Utilities
return (c >= 56320 && c <= 57343); return (c >= 56320 && c <= 57343);
#endif #endif
} }
public static bool StartsWith(this string source, char value)
{
return (source.Length != 0 && source[0] == value);
}
public static bool EndsWith(this string source, char value)
{
int sourceLen = source.Length;
return (sourceLen != 0 && source[sourceLen - 1] == value);
}
} }
} }