Beispiel #1
0
        protected static int lookAhead(char[] json, int index)
        {
            int num = index;

            return(MiniJSON.nextToken(json, ref num));
        }
Beispiel #2
0
        protected static int nextToken(char[] json, ref int index)
        {
            MiniJSON.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;
        }
Beispiel #3
0
        protected static string parseString(char[] json, ref int index)
        {
            string text = string.Empty;

            MiniJSON.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 == '"')
                    {
                        text += '"';
                    }
                    else if (c == '\\')
                    {
                        text += '\\';
                    }
                    else if (c == '/')
                    {
                        text += '/';
                    }
                    else if (c == 'b')
                    {
                        text += '\b';
                    }
                    else if (c == 'f')
                    {
                        text += '\f';
                    }
                    else if (c == 'n')
                    {
                        text += '\n';
                    }
                    else if (c == 'r')
                    {
                        text += '\r';
                    }
                    else if (c == 't')
                    {
                        text += '\t';
                    }
                    else if (c == 'u')
                    {
                        int num = json.Length - index;
                        if (num < 4)
                        {
                            break;
                        }
                        char[] array = new char[4];
                        Array.Copy(json, index, array, 0, 4);
                        text   = text + "&#x" + new string(array) + ";";
                        index += 4;
                    }
                }
                else
                {
                    text += c;
                }
            }
            if (!flag)
            {
                return(null);
            }
            return(text);
        }