Exemplo n.º 1
0
        private static object ParseNumber(char[] json, ref int index, ref bool success)
        {
            SimpleJson.EatWhitespace(json, ref index);
            int    lastIndexOfNumber = SimpleJson.GetLastIndexOfNumber(json, index);
            int    length            = lastIndexOfNumber - index + 1;
            string text = new string(json, index, length);
            object result;

            if (text.IndexOf(".", StringComparison.OrdinalIgnoreCase) != -1 || text.IndexOf("e", StringComparison.OrdinalIgnoreCase) != -1)
            {
                double num;
                success = double.TryParse(new string(json, index, length), NumberStyles.Any, CultureInfo.InvariantCulture, out num);
                result  = num;
            }
            else
            {
                long num2;
                success = long.TryParse(new string(json, index, length), NumberStyles.Any, CultureInfo.InvariantCulture, out num2);
                result  = num2;
            }
            index = lastIndexOfNumber + 1;
            return(result);
        }
Exemplo n.º 2
0
        private static int NextToken(char[] json, ref int index)
        {
            SimpleJson.EatWhitespace(json, ref index);
            if (index == json.Length)
            {
                return(0);
            }
            char c = json[index];

            index++;
            char c2 = c;

            switch (c2)
            {
            case '"':
                return(7);

            case '#':
            case '$':
            case '%':
            case '&':
            case '\'':
            case '(':
            case ')':
            case '*':
            case '+':
            case '.':
            case '/':
IL_8D:
                switch (c2)
                {
                case '[':
                    return(3);

                case '\\':
                {
IL_A2:
                    switch (c2)
                    {
                    case '{':
                        return(1);

                    case '}':
                        return(2);
                    }
                    index--;
                    int num = json.Length - index;
                    if (num >= 5 && json[index] == 'f' && json[index + 1] == 'a' && json[index + 2] == 'l' && json[index + 3] == 's' && json[index + 4] == 'e')
                    {
                        index += 5;
                        return(10);
                    }
                    if (num >= 4 && json[index] == 't' && json[index + 1] == 'r' && json[index + 2] == 'u' && json[index + 3] == 'e')
                    {
                        index += 4;
                        return(9);
                    }
                    if (num >= 4 && json[index] == 'n' && json[index + 1] == 'u' && json[index + 2] == 'l' && json[index + 3] == 'l')
                    {
                        index += 4;
                        return(11);
                    }
                    return(0);
                }

                case ']':
                    return(4);
                }
                goto IL_A2;

            case ',':
                return(6);

            case '-':
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                return(8);

            case ':':
                return(5);
            }
            goto IL_8D;
        }
Exemplo n.º 3
0
        private static string ParseString(char[] json, ref int index, ref bool success)
        {
            StringBuilder stringBuilder = new StringBuilder(2000);

            SimpleJson.EatWhitespace(json, ref index);
            char c    = json[index++];
            bool flag = false;

            while (!flag)
            {
                if (index == json.Length)
                {
                    break;
                }
                c = json[index++];
                if (c == '"')
                {
                    flag = true;
                    break;
                }
                if (c == '\\')
                {
                    if (index == json.Length)
                    {
                        break;
                    }
                    c = json[index++];
                    if (c == '"')
                    {
                        stringBuilder.Append('"');
                    }
                    else if (c == '\\')
                    {
                        stringBuilder.Append('\\');
                    }
                    else if (c == '/')
                    {
                        stringBuilder.Append('/');
                    }
                    else if (c == 'b')
                    {
                        stringBuilder.Append('\b');
                    }
                    else if (c == 'f')
                    {
                        stringBuilder.Append('\f');
                    }
                    else if (c == 'n')
                    {
                        stringBuilder.Append('\n');
                    }
                    else if (c == 'r')
                    {
                        stringBuilder.Append('\r');
                    }
                    else if (c == 't')
                    {
                        stringBuilder.Append('\t');
                    }
                    else if (c == 'u')
                    {
                        int num = json.Length - index;
                        if (num < 4)
                        {
                            break;
                        }
                        uint num2;
                        if (!(success = uint.TryParse(new string(json, index, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out num2)))
                        {
                            return(string.Empty);
                        }
                        if (55296u <= num2 && num2 <= 56319u)
                        {
                            index += 4;
                            num    = json.Length - index;
                            uint num3;
                            if (num < 6 || !(new string(json, index, 2) == "\\u") || !uint.TryParse(new string(json, index + 2, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out num3) || 56320u > num3 || num3 > 57343u)
                            {
                                success = false;
                                return(string.Empty);
                            }
                            stringBuilder.Append((char)num2);
                            stringBuilder.Append((char)num3);
                            index += 6;
                        }
                        else
                        {
                            stringBuilder.Append(SimpleJson.ConvertFromUtf32((int)num2));
                            index += 4;
                        }
                    }
                }
                else
                {
                    stringBuilder.Append(c);
                }
            }
            if (!flag)
            {
                success = false;
                return(null);
            }
            return(stringBuilder.ToString());
        }
Exemplo n.º 4
0
        private static int NextToken(char[] json, ref int index)
        {
            SimpleJson.EatWhitespace(json, ref index);
            int result;

            if (index == json.Length)
            {
                result = 0;
            }
            else
            {
                char c = json[index];
                index++;
                switch (c)
                {
                case ',':
                    result = 6;
                    break;

                case '-':
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    result = 8;
                    break;

                default:
                    switch (c)
                    {
                    case '[':
                        result = 3;
                        break;

                    default:
                        switch (c)
                        {
                        case '{':
                            result = 1;
                            break;

                        default:
                            if (c != '"')
                            {
                                index--;
                                int num = json.Length - index;
                                if (num >= 5)
                                {
                                    if (json[index] == 'f' && json[index + 1] == 'a' && json[index + 2] == 'l' && json[index + 3] == 's' && json[index + 4] == 'e')
                                    {
                                        index += 5;
                                        result = 10;
                                        break;
                                    }
                                }
                                if (num >= 4)
                                {
                                    if (json[index] == 't' && json[index + 1] == 'r' && json[index + 2] == 'u' && json[index + 3] == 'e')
                                    {
                                        index += 4;
                                        result = 9;
                                        break;
                                    }
                                }
                                if (num >= 4)
                                {
                                    if (json[index] == 'n' && json[index + 1] == 'u' && json[index + 2] == 'l' && json[index + 3] == 'l')
                                    {
                                        index += 4;
                                        result = 11;
                                        break;
                                    }
                                }
                                result = 0;
                            }
                            else
                            {
                                result = 7;
                            }
                            break;

                        case '}':
                            result = 2;
                            break;
                        }
                        break;

                    case ']':
                        result = 4;
                        break;
                    }
                    break;

                case ':':
                    result = 5;
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        // Token: 0x0601590A RID: 88330 RVA: 0x0057E2C8 File Offset: 0x0057C4C8
        private static int NextToken(char[] json, ref int index)
        {
            SimpleJson.EatWhitespace(json, ref index);
            if (index == json.Length)
            {
                return(0);
            }
            char c = json[index];

            index++;
            switch (c)
            {
            case ',':
                return(6);

            case '-':
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                return(8);

            default:
                switch (c)
                {
                case '[':
                    return(3);

                default:
                    switch (c)
                    {
                    case '{':
                        return(1);

                    default:
                    {
                        if (c == '"')
                        {
                            return(7);
                        }
                        index--;
                        int num = json.Length - index;
                        if (num >= 5 && json[index] == 'f' && json[index + 1] == 'a' && json[index + 2] == 'l' && json[index + 3] == 's' && json[index + 4] == 'e')
                        {
                            index += 5;
                            return(10);
                        }
                        if (num >= 4 && json[index] == 't' && json[index + 1] == 'r' && json[index + 2] == 'u' && json[index + 3] == 'e')
                        {
                            index += 4;
                            return(9);
                        }
                        if (num >= 4 && json[index] == 'n' && json[index + 1] == 'u' && json[index + 2] == 'l' && json[index + 3] == 'l')
                        {
                            index += 4;
                            return(11);
                        }
                        return(0);
                    }

                    case '}':
                        return(2);
                    }
                    break;

                case ']':
                    return(4);
                }
                break;

            case ':':
                return(5);
            }
        }
Exemplo n.º 6
0
        private static int NextToken(char[] json, ref int index)
        {
            SimpleJson.EatWhitespace(json, ref index);
            int result;

            if (index != json.Length)
            {
                char c = json[index];
                index++;
                switch (c)
                {
                case ',':
                    result = 6;
                    return(result);

                case '-':
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    result = 8;
                    return(result);

                case '.':
                case '/':
IL_69:
                    switch (c)
                    {
                    case '[':
                        result = 3;
                        return(result);

                    case '\\':
IL_7E:
                        switch (c)
                        {
                        case '{':
                            result = 1;
                            return(result);

                        case '|':
IL_93:
                            if (c != '"')
                            {
                                index--;
                                int num = json.Length - index;
                                if (num >= 5)
                                {
                                    if (json[index] == 'f' && json[index + 1] == 'a' && json[index + 2] == 'l' && json[index + 3] == 's' && json[index + 4] == 'e')
                                    {
                                        index += 5;
                                        result = 10;
                                        return(result);
                                    }
                                }
                                if (num >= 4)
                                {
                                    if (json[index] == 't' && json[index + 1] == 'r' && json[index + 2] == 'u' && json[index + 3] == 'e')
                                    {
                                        index += 4;
                                        result = 9;
                                        return(result);
                                    }
                                }
                                if (num >= 4)
                                {
                                    if (json[index] == 'n' && json[index + 1] == 'u' && json[index + 2] == 'l' && json[index + 3] == 'l')
                                    {
                                        index += 4;
                                        result = 11;
                                        return(result);
                                    }
                                }
                                result = 0;
                                return(result);
                            }
                            result = 7;
                            return(result);

                        case '}':
                            result = 2;
                            return(result);
                        }
                        goto IL_93;

                    case ']':
                        result = 4;
                        return(result);
                    }
                    goto IL_7E;

                case ':':
                    result = 5;
                    return(result);
                }
                goto IL_69;
            }
            result = 0;
            return(result);
        }
Exemplo n.º 7
0
        private static string ParseString(char[] json, ref int index, ref bool success)
        {
            StringBuilder stringBuilder = new StringBuilder(2000);

            SimpleJson.EatWhitespace(json, ref index);
            char   c    = json[index++];
            bool   flag = false;
            string result;

            while (!flag)
            {
                if (index == json.Length)
                {
                    break;
                }
                c = json[index++];
                if (c == '"')
                {
                    flag = true;
                    break;
                }
                if (c == '\\')
                {
                    if (index == json.Length)
                    {
                        break;
                    }
                    c = json[index++];
                    if (c == '"')
                    {
                        stringBuilder.Append('"');
                    }
                    else if (c == '\\')
                    {
                        stringBuilder.Append('\\');
                    }
                    else if (c == '/')
                    {
                        stringBuilder.Append('/');
                    }
                    else if (c == 'b')
                    {
                        stringBuilder.Append('\b');
                    }
                    else if (c == 'f')
                    {
                        stringBuilder.Append('\f');
                    }
                    else if (c == 'n')
                    {
                        stringBuilder.Append('\n');
                    }
                    else if (c == 'r')
                    {
                        stringBuilder.Append('\r');
                    }
                    else if (c == 't')
                    {
                        stringBuilder.Append('\t');
                    }
                    else if (c == 'u')
                    {
                        int num = json.Length - index;
                        if (num >= 4)
                        {
                            uint num2;
                            if (!(success = uint.TryParse(new string(json, index, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out num2)))
                            {
                                result = "";
                            }
                            else
                            {
                                if (55296u > num2 || num2 > 56319u)
                                {
                                    stringBuilder.Append(SimpleJson.ConvertFromUtf32((int)num2));
                                    index += 4;
                                    continue;
                                }
                                index += 4;
                                num    = json.Length - index;
                                if (num >= 6)
                                {
                                    uint num3;
                                    if (new string(json, index, 2) == "\\u" && uint.TryParse(new string(json, index + 2, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out num3))
                                    {
                                        if (56320u <= num3 && num3 <= 57343u)
                                        {
                                            stringBuilder.Append((char)num2);
                                            stringBuilder.Append((char)num3);
                                            index += 6;
                                            continue;
                                        }
                                    }
                                }
                                success = false;
                                result  = "";
                            }
                            return(result);
                        }
                        break;
                    }
                }
                else
                {
                    stringBuilder.Append(c);
                }
            }
            if (!flag)
            {
                success = false;
                result  = null;
                return(result);
            }
            result = stringBuilder.ToString();
            return(result);
        }