Skip to content

Commit

Permalink
Fixed the issue in serialization of emoji chars
Browse files Browse the repository at this point in the history
  • Loading branch information
crimsonred committed Apr 23, 2014
1 parent bebad51 commit 24a7204
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/JsonFx/Json/JsonFormatter.cs
Expand Up @@ -511,12 +511,12 @@ protected virtual void WriteNaN(TextWriter writer)

protected virtual void WriteString(TextWriter writer, string value)
{
int start = 0,
length = value.Length;
int start = 0,
length = value.Length;

writer.Write(JsonGrammar.OperatorStringDelim);

writer.Write(JsonGrammar.OperatorStringDelim);

for (int i=start; i<length; i++)
for (int i=start; i<length; i++)
{
char ch = value[i];

Expand Down Expand Up @@ -568,9 +568,24 @@ protected virtual void WriteString(TextWriter writer, string value)
}
default:
{
writer.Write("\\u");
writer.Write(CharUtility.ConvertToUtf32(value, i).ToString("X4"));
continue;
#if SILVERLIGHT
if (((ch >= 55296)
&& (ch <= 56319)) || ((ch >= 56320) && (ch <= 57343)))
{
#else
if (char.IsSurrogate(ch))
{
#endif
writer.Write("\\u");
writer.Write(((int)ch).ToString("x4"));
continue;
}
else
{
writer.Write("\\u");
writer.Write(CharUtility.ConvertToUtf32(value, i).ToString("X4"));
continue;
}
}
}
}
Expand Down

0 comments on commit 24a7204

Please sign in to comment.