コード例 #1
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
        private static bool parseObject(JSONParser.Context ctx, object obj)
        {
            Type type = obj == null ? (Type)null : obj.GetType();

            JSONParser.forward(ctx);
            if (!JSONParser.match(ctx, '{'))
            {
                throw new JSONParser.UnexpectedCharacterException(ctx);
            }
            while (true)
            {
                JSONParser.forward(ctx);
                if (!JSONParser.match(ctx, '}'))
                {
                    if ((int)ctx.src[ctx.pos] == 34)
                    {
                        JSONParser.parseString(ctx);
                        if (ctx.sb.Length > 0)
                        {
                            JSONParser.forward(ctx);
                            if ((int)ctx.src[ctx.pos] == 58)
                            {
                                ++ctx.pos;
                                JSONParser.forward(ctx);
                                FieldInfo fieldInfo = (object)type == null ? (FieldInfo)null : type.GetField(ctx.sb.ToString());
                                if ((object)fieldInfo == null)
                                {
                                    if ((int)ctx.src[ctx.pos] == 34)
                                    {
                                        JSONParser.parseString(ctx);
                                    }
                                    else if ((int)ctx.src[ctx.pos] == 123)
                                    {
                                        JSONParser.parseObject(ctx, (object)null);
                                    }
                                    else if ((int)ctx.src[ctx.pos] == 91)
                                    {
                                        JSONParser.parseArray(ctx, (Type)null);
                                    }
                                    else if ((int)ctx.src[ctx.pos] == 45 || 48 <= (int)ctx.src[ctx.pos] && (int)ctx.src[ctx.pos] <= 57)
                                    {
                                        JSONParser.parseNumber(ctx, false);
                                    }
                                }
                                else
                                {
                                    Type fieldType = fieldInfo.FieldType;
                                    if (fieldType.IsValueType || (object)fieldType == (object)typeof(string))
                                    {
                                        if ((object)fieldType == (object)typeof(int))
                                        {
                                            JSONParser.parseNumber(ctx, true);
                                            fieldInfo.SetValue(obj, (object)int.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(long))
                                        {
                                            JSONParser.parseNumber(ctx, true);
                                            fieldInfo.SetValue(obj, (object)long.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(float))
                                        {
                                            JSONParser.parseNumber(ctx, false);
                                            fieldInfo.SetValue(obj, (object)float.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(double))
                                        {
                                            JSONParser.parseNumber(ctx, false);
                                            fieldInfo.SetValue(obj, (object)double.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(short))
                                        {
                                            JSONParser.parseNumber(ctx, true);
                                            fieldInfo.SetValue(obj, (object)short.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(byte))
                                        {
                                            JSONParser.parseNumber(ctx, true);
                                            fieldInfo.SetValue(obj, (object)byte.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(string))
                                        {
                                            JSONParser.parseString(ctx);
                                            fieldInfo.SetValue(obj, (object)ctx.sb.ToString());
                                        }
                                        else
                                        {
                                            goto label_33;
                                        }
                                    }
                                    else if (fieldType.IsArray)
                                    {
                                        if ((int)ctx.src[ctx.pos] == 91 && (int)ctx.src[ctx.pos + 1] == 93)
                                        {
                                            ctx.pos += 2;
                                        }
                                        else
                                        {
                                            Type   elementType = fieldType.GetElementType();
                                            object array       = JSONParser.parseArray(ctx, elementType);
                                            fieldInfo.SetValue(obj, array);
                                        }
                                    }
                                    else if ((int)ctx.src[ctx.pos] == 123 && (int)ctx.src[ctx.pos + 1] == 125)
                                    {
                                        ctx.pos += 2;
                                    }
                                    else
                                    {
                                        object obj1;
                                        if (JSONParser.match(ctx, 'n'))
                                        {
                                            if (ctx.pos + 3 <= ctx.src.Length)
                                            {
                                                if ((int)ctx.src[ctx.pos] == 117 && (int)ctx.src[ctx.pos + 1] == 108 && (int)ctx.src[ctx.pos + 2] == 108)
                                                {
                                                    ctx.pos += 3;
                                                    obj1     = (object)null;
                                                }
                                                else
                                                {
                                                    goto label_45;
                                                }
                                            }
                                            else
                                            {
                                                goto label_42;
                                            }
                                        }
                                        else
                                        {
                                            obj1 = Activator.CreateInstance(fieldType);
                                            JSONParser.parseObject(ctx, obj1);
                                        }
                                        fieldInfo.SetValue(obj, obj1);
                                    }
                                }
                                JSONParser.forward(ctx);
                                if ((int)ctx.src[ctx.pos] == 44)
                                {
                                    ++ctx.pos;
                                }
                                else
                                {
                                    goto label_50;
                                }
                            }
                            else
                            {
                                goto label_8;
                            }
                        }
                        else
                        {
                            goto label_6;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    goto label_53;
                }
            }
            throw new JSONParser.UnexpectedCharacterException(ctx);
label_6:
            throw new JSONParser.InvalidKeyException(ctx);
label_8:
            throw new JSONParser.UnexpectedCharacterException(ctx);
label_33:
            throw new JSONParser.UnsupportedTypeException(ctx);
label_42:
            throw new JSONParser.UnexpectedEOFException(ctx);
label_45:
            throw new JSONParser.UnexpectedCharacterException(ctx);
label_50:
            if ((int)ctx.src[ctx.pos] != 125)
            {
                throw new JSONParser.InvalidCharacterException(ctx);
            }
            ++ctx.pos;
label_53:
            return(true);
        }
コード例 #2
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
 private static float floatParser(JSONParser.Context ctx, Type type)
 {
     JSONParser.parseNumber(ctx, false);
     return(float.Parse(ctx.sb.ToString()));
 }
コード例 #3
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
 private static double doubleParser(JSONParser.Context ctx, Type type)
 {
     JSONParser.parseNumber(ctx, false);
     return(double.Parse(ctx.sb.ToString()));
 }
コード例 #4
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
 private static long longParser(JSONParser.Context ctx, Type type)
 {
     JSONParser.parseNumber(ctx, true);
     return(long.Parse(ctx.sb.ToString()));
 }
コード例 #5
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
 private static int intParser(JSONParser.Context ctx, Type type)
 {
     JSONParser.parseNumber(ctx, true);
     return(int.Parse(ctx.sb.ToString()));
 }
コード例 #6
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
 private static byte byteParser(JSONParser.Context ctx, Type type)
 {
     JSONParser.parseNumber(ctx, true);
     return(byte.Parse(ctx.sb.ToString()));
 }
コード例 #7
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
 private static string stringParser(JSONParser.Context ctx, Type type)
 {
     JSONParser.parseString(ctx);
     return(ctx.sb.ToString());
 }
コード例 #8
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
        private static bool parseString(JSONParser.Context ctx)
        {
            if (ctx.pos >= ctx.src.Length || (int)ctx.src[ctx.pos] != 34)
            {
                throw new JSONParser.InvalidStringException(ctx);
            }
            ++ctx.pos;
            ctx.sb.Length = 0;
            for (; ctx.pos < ctx.src.Length; ++ctx.pos)
            {
                if (char.IsControl(ctx.src[ctx.pos]))
                {
                    throw new JSONParser.InvalidCharacterException(ctx);
                }
                if ((int)ctx.src[ctx.pos] == 92)
                {
                    ++ctx.pos;
                    if (ctx.pos >= ctx.src.Length)
                    {
                        throw new JSONParser.InvalidStringException(ctx);
                    }
                    char ch = ctx.src[ctx.pos];
                    switch (ch)
                    {
                    case 'n':
                        ctx.sb.Append('\n');
                        continue;

                    case 'r':
                        ctx.sb.Append('\r');
                        continue;

                    case 't':
                        ctx.sb.Append('\t');
                        continue;

                    case 'u':
                        ++ctx.pos;
                        uint num = (uint)((int)JSONParser.parseHex(ctx) << 12 | (int)JSONParser.parseHex(ctx) << 8 | (int)JSONParser.parseHex(ctx) << 4) | JSONParser.parseHex(ctx);
                        ctx.sb.Append((char)num);
                        --ctx.pos;
                        continue;

                    default:
                        switch (ch)
                        {
                        case '"':
                            ctx.sb.Append('"');
                            continue;

                        case '/':
                            ctx.sb.Append('/');
                            continue;

                        case '\\':
                            ctx.sb.Append('\\');
                            continue;

                        case 'b':
                            ctx.sb.Append('\b');
                            continue;

                        case 'f':
                            ctx.sb.Append('\f');
                            continue;

                        default:
                            throw new JSONParser.InvalidStringException(ctx);
                        }
                    }
                }
                else
                {
                    if ((int)ctx.src[ctx.pos] == 34)
                    {
                        ++ctx.pos;
                        break;
                    }
                    ctx.sb.Append(ctx.src[ctx.pos]);
                }
            }
            return(true);
        }