Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for decode string contains emoji char #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions Assets/Plugins/MiniJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,37 @@ protected static string parseString( char[] json, ref int index )
s += "&#x" + new string( unicodeCharArray ) + ";";

/*
uint codePoint = UInt32.Parse(new string(unicodeCharArray), NumberStyles.HexNumber);
// convert the integer codepoint to a unicode char and add to string
s += Char.ConvertFromUtf32((int)codePoint);
*/
uint codePoint = UInt32.Parse(new string(unicodeCharArray), NumberStyles.HexNumber);
// convert the integer codepoint to a unicode char and add to string
try
{
s += Char.ConvertFromUtf32((int)codePoint);
// skip 4 chars
index += 4;
}
catch (ArgumentOutOfRangeException ex)
{
if (remainingLength >= 10)
{
try
{
char[] highSurrogateCharArray = unicodeCharArray;
char[] lowSurrogateCharArray = new char[4];
// skip highSurrogateCharArray and \u, like E1EC\u total 6 char = 4 HEX chars + \u
Array.Copy(json, index + 6, lowSurrogateCharArray, 0, 4);
int highSurrogateCharCodePoint = Int32.Parse(new string(highSurrogateCharArray), NumberStyles.HexNumber);
int lowSurrogateCharCodePoint = Int32.Parse(new string(lowSurrogateCharArray), NumberStyles.HexNumber);
s += ("" + Convert.ToChar(highSurrogateCharCodePoint) + Convert.ToChar(lowSurrogateCharCodePoint));
// skip a unicode char array like \uE1EC , total 6 char = \u + 4 HEX chars
index += (4 + 6);
}
catch(Exception e)
{
index += 4;
}
}
}
*/

// skip 4 chars
index += 4;
Expand Down Expand Up @@ -385,7 +412,7 @@ protected static int getLastIndexOfNumber( char[] json, int index )
protected static void eatWhitespace( char[] json, ref int index )
{
for( ; index < json.Length; index++ )
if( " \t\n\r".IndexOf( json[index] ) == -1 )
if( " \t\n\r\u200B\uFEFF".IndexOf( json[index] ) == -1 )
{
break;
}
Expand Down