Пример #1
0
 private static ScannerData ScanNull(string json, int index)
 {
     return(new ScannerData(JSONObject.CreateNull(), ExpectConstant(json, index, "null")));
 }
Пример #2
0
        private static ScannerData ScanNumber(string json, int index)
        {
            var negative         = false;
            var fractional       = false;
            var negativeExponent = false;

            if (json[index] == '-')
            {
                negative = true;
                ++index;
            }

            ulong integerPart = 0;

            if (json[index] != '0')
            {
                while (json.Length > index && char.IsNumber(json[index]))
                {
                    integerPart = (integerPart * 10) + (ulong)(json[index] - '0');
                    ++index;
                }
            }
            else
            {
                ++index;
            }

            ulong fractionalPart       = 0;
            int   fractionalPartLength = 0;

            if (json.Length > index && json[index] == '.')
            {
                fractional = true;

                ++index;
                while (json.Length > index && char.IsNumber(json[index]))
                {
                    fractionalPart = (fractionalPart * 10) + (ulong)(json[index] - '0');
                    ++index;
                    ++fractionalPartLength;
                }
            }

            ulong exponent = 0;

            if (json.Length > index && (json[index] == 'e' || json[index] == 'E'))
            {
                fractional = true;
                ++index;

                if (json[index] == '-')
                {
                    negativeExponent = true;
                    ++index;
                }
                else if (json[index] == '+')
                {
                    ++index;
                }

                while (json.Length > index && char.IsNumber(json[index]))
                {
                    exponent = (exponent * 10) + (ulong)(json[index] - '0');
                    ++index;
                }
            }

            return(new ScannerData(JSONObject.CreateNumber(negative, fractional, negativeExponent, integerPart, fractionalPart, fractionalPartLength, exponent), index));
        }
Пример #3
0
 private static ScannerData ScanFalse(string json, int index)
 {
     return(new ScannerData(JSONObject.CreateBoolean(false), ExpectConstant(json, index, "false")));
 }
Пример #4
0
 public ScannerData(JSONObject result, int index)
 {
     Result = result;
     Index  = index;
 }
Пример #5
0
		public void WriteJObject(JSONObject obj)
		{
			switch (obj.Kind) {
				case JSONObjectType.Array:
					BeginArray();
					foreach (var elem in obj.ArrayValue) {
						WriteJObject(elem);
					}
					EndArray();
					break;
				case JSONObjectType.Boolean:
					WriteBool(obj.BooleanValue);
					break;
				case JSONObjectType.Null:
					WriteNull();
					break;
				case JSONObjectType.Number:
					if (obj.IsFractional) {
						WriteNumber(obj.DoubleValue);
					} else if (obj.IsNegative) {
						WriteNumber(obj.LongValue);
					} else {
						WriteNumber(obj.ULongValue);
					}
					break;
				case JSONObjectType.Object:
					BeginObject();
					foreach (var pair in obj.ObjectValue) {
						WriteKey(pair.Key);
						WriteJObject(pair.Value);
					}
					EndObject();
					break;
				case JSONObjectType.String:
					WriteString(obj.StringValue);
					break;
			}
		}
Пример #6
0
		public static bool EqualNumber(JSONObject o1, JSONObject o2)
		{
			if (o1.MinFloat != o2.MinFloat ||
			             o1.MinInteger != o2.MinInteger ||
			             o1.IsNegative != o2.IsNegative ||
			             o1.IsFractional != o2.IsFractional)
				return false;

			if (o1.IsFractional) {
				return o1.DoubleValue == o2.DoubleValue;
			}
			if (o1.IsNegative) {
				return o1.LongValue == o2.LongValue;
			}

			return o1.ULongValue == o2.ULongValue;
		}
Пример #7
0
			public ScannerData(JSONObject result, int index)
			{
				Result = result;
				Index = index;
			}