예제 #1
0
        protected static double parseNumber(char[] json, ref int index)
        {
            MUJson.eatWhitespace(json, ref index);
            int lastIndex  = MUJson.getLastIndexOfNumber(json, index);
            int charLength = lastIndex - index + 1;

            char[] numberCharArray = new char[charLength];
            Array.Copy(json, index, numberCharArray, 0, charLength);
            index = lastIndex + 1;
            return(double.Parse(new string(numberCharArray)));
        }
예제 #2
0
        protected static int nextToken(char[] json, ref int index)
        {
            MUJson.eatWhitespace(json, ref index);
            int result;

            if (index == json.Length)
            {
                result = 0;
            }
            else
            {
                char c = json[index];
                index++;
                char c2 = c;
                switch (c2)
                {
                case '"':
                    return(7);

                case '#':
                case '$':
                case '%':
                case '&':
                case '\'':
                case '(':
                case ')':
                case '*':
                case '+':
                case '.':
                case '/':
                    break;

                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);

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

                    case '\\':
                        break;

                    case ']':
                        return(4);

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

                        case '}':
                            return(2);
                        }
                        break;
                    }
                    break;
                }
                index--;
                int remainingLength = json.Length - index;
                if (remainingLength >= 5)
                {
                    if (json[index] == 'f' && json[index + 1] == 'a' && json[index + 2] == 'l' && json[index + 3] == 's' && json[index + 4] == 'e')
                    {
                        index += 5;
                        return(10);
                    }
                }
                if (remainingLength >= 4)
                {
                    if (json[index] == 't' && json[index + 1] == 'r' && json[index + 2] == 'u' && json[index + 3] == 'e')
                    {
                        index += 4;
                        return(9);
                    }
                }
                if (remainingLength >= 4)
                {
                    if (json[index] == 'n' && json[index + 1] == 'u' && json[index + 2] == 'l' && json[index + 3] == 'l')
                    {
                        index += 4;
                        return(11);
                    }
                }
                result = 0;
            }
            return(result);
        }
예제 #3
0
        protected static string parseString(char[] json, ref int index)
        {
            string s = "";

            MUJson.eatWhitespace(json, ref index);
            char c        = json[index++];
            bool complete = false;

            while (!complete)
            {
                if (index == json.Length)
                {
                    break;
                }
                c = json[index++];
                if (c == '"')
                {
                    complete = true;
                    break;
                }
                if (c == '\\')
                {
                    if (index == json.Length)
                    {
                        break;
                    }
                    c = json[index++];
                    if (c == '"')
                    {
                        s += '"';
                    }
                    else if (c == '\\')
                    {
                        s += '\\';
                    }
                    else if (c == '/')
                    {
                        s += '/';
                    }
                    else if (c == 'b')
                    {
                        s += '\b';
                    }
                    else if (c == 'f')
                    {
                        s += '\f';
                    }
                    else if (c == 'n')
                    {
                        s += '\n';
                    }
                    else if (c == 'r')
                    {
                        s += '\r';
                    }
                    else if (c == 't')
                    {
                        s += '\t';
                    }
                    else if (c == 'u')
                    {
                        int remainingLength = json.Length - index;
                        if (remainingLength < 4)
                        {
                            break;
                        }
                        char[] unicodeCharArray = new char[4];
                        Array.Copy(json, index, unicodeCharArray, 0, 4);
                        s      = s + "&#x" + new string(unicodeCharArray) + ";";
                        index += 4;
                    }
                }
                else
                {
                    s += c;
                }
            }
            string result;

            if (!complete)
            {
                result = null;
            }
            else
            {
                result = s;
            }
            return(result);
        }