Example #1
0
        private JValue ParseNumber()
        {
            var isFloat = false;
            var start   = pos;
            var ch      = json[pos];

            if (ch == JsonTokens.Negtive)
            {
                MovePosition();
                if (!IsDigit(json[pos]) || json[pos] == JsonTokens.Digit0)
                {
                    throw new ArgumentException(Messages.InvalidFormat);
                }
            }
            else if (ch == JsonTokens.Digit0)
            {
                if (pos < len - 1)
                {
                    if (IsDigit(json[++pos]))
                    {
                        throw new ArgumentException(Messages.InvalidFormat);
                    }
                }
            }

            while (pos < len && IsDigit(json[pos]))
            {
                ++pos;
            }
            if (pos < len && json[pos] == JsonTokens.Dot)
            {
                isFloat = true;
                MovePosition();
                if (!IsDigit(json[pos]))
                {
                    throw new ArgumentException(Messages.InvalidFormat);
                }
            }
            while (pos < len && IsDigit(json[pos]))
            {
                pos++;
            }

            if (pos < len && char.ToLower(json[pos]) == JsonTokens.Exp)
            {
                isFloat = true;
                MovePosition();
                var next = json[pos];
                if (IsDigit(next))
                {
                    while (pos < len && IsDigit(json[pos++]))
                    {
                        ;
                    }
                }
                else if (next == JsonTokens.Plus || next == JsonTokens.Minus)
                {
                    MovePosition();
                    if (!IsDigit(json[pos]))
                    {
                        throw new ArgumentException(Messages.InvalidFormat);
                    }
                    while (pos < len && IsDigit(json[pos++]))
                    {
                        ;
                    }
                }
                else
                {
                    throw new ArgumentException(Messages.InvalidFormat);
                }
            }

            var numStr = json.Substring(start, pos - start);

            JValue result;

            if (isFloat)
            {
                result = new JNumber(numStr, NumberType.Decimal);
            }
            else
            {
                result = new JNumber(numStr, NumberType.Integer);
            }
            return(result);
        }
Example #2
0
 public void SetDouble(string key, double v)
 {
     values[key] = new JNumber(v);
 }
Example #3
0
 public void SetDecimal(string key, decimal v)
 {
     values[key] = new JNumber(v);
 }
Example #4
0
 public void SetFloat(string key, float v)
 {
     values[key] = new JNumber(v);
 }
Example #5
0
 public void SetSByte(string key, sbyte v)
 {
     values[key] = new JNumber(v);
 }
Example #6
0
 public void SetUInt16(string key, ushort v)
 {
     values[key] = new JNumber(v);
 }
Example #7
0
 public void SetUInt64(string key, ulong v)
 {
     values[key] = new JNumber(v);
 }
Example #8
0
#pragma warning disable 3001, 3002

        public void SetUInt32(string key, uint v)
        {
            values[key] = new JNumber(v);
        }