Example #1
0
    //---------------------------------------------------------------------------------
    // ReadValue
    //---------------------------------------------------------------------------------
    private IJSONFieldValue ReadValue()
    {
        SkipWhitespace();
        char peek = (char)reader.Peek();

        // Is it a string ?
        //Console.WriteLine("character found at beginning of value " + peek);
        if (peek == '"' || peek == '\'')
        {
            return(new JSONStringFieldValue(ReadString()));
        }
        else if (FlashCompatibleConvert.IsDigit(peek) || peek == '-')
        {
            return(new JSONNumberFieldValue(ReadNumber()));
        }
        else if (peek == '[')
        {
            return(new JSONListFieldValue(ReadList()));
        }
        else if (peek == '{')
        {
            return(new JSONObjectFieldValue(ReadObject()));
        }
        else if (peek == 't' || peek == 'f')
        {
            return(new JSONBooleanFieldValue(ReadBoolean()));
        }
        else if (peek == 'n')
        {
            ReadNull();
            return(new JSONNullFieldValue());
        }
        return(null);
    }
Example #2
0
 public XMLInStream AttributeOptional(string name, ref int value)
 {
     if (current.attributes.ContainsKey(name))
     {
         value = FlashCompatibleConvert.ToInt32(GetAttribute(name));
     }
     return(this);
 }
Example #3
0
 //---------------------------------------------------------------------------------
 // GetDouble Utility
 //---------------------------------------------------------------------------------
 private double GetDouble(string val)
 {
     try
     {
         return(FlashCompatibleConvert.ToDouble(val));
     }
     catch
     {
         if (val.Contains("."))
         {
             return(FlashCompatibleConvert.ToDouble(val.Replace('.', ',')));
         }
         return(FlashCompatibleConvert.ToDouble(val.Replace(',', '.')));
     }
 }
Example #4
0
    private double ReadNumber()
    {
        string text = string.Empty;

        while (true)
        {
            int num = reader.Peek();
            if (num == -1 || num == 44 || num == 125 || num == 93 || char.IsWhiteSpace((char)num))
            {
                break;
            }
            text += ((char)(ushort)reader.Read()).ToString();
        }
        return(FlashCompatibleConvert.ToDouble(text));
    }
Example #5
0
    //---------------------------------------------------------------------------------
    // ReadNumber
    //---------------------------------------------------------------------------------
    private double ReadNumber()
    {
        string result = "";

        while (true)
        {
            int peek = reader.Peek();
            if (peek == -1 || peek == ',' || peek == '}' || peek == ']' || Char.IsWhiteSpace((char)peek))
            {
                return(FlashCompatibleConvert.ToDouble(result));
            }
            else
            {
                result += ((char)reader.Read()).ToString();
            }
        }
    }
    private double GetDouble(string val)
    {
        try
        {
            return(FlashCompatibleConvert.ToDouble(val));

IL_000c:
            double result;
            return(result);
        }
        catch
        {
            if (!val.Contains("."))
            {
                return(FlashCompatibleConvert.ToDouble(val.Replace(',', '.')));
            }
            return(FlashCompatibleConvert.ToDouble(val.Replace('.', ',')));

IL_004c:
            double result;
            return(result);
        }
    }
Example #7
0
    private IJSONFieldValue ReadValue()
    {
        SkipWhitespace();
        char c = (char)reader.Peek();

        if (c == '"' || c == '\'')
        {
            return(new JSONStringFieldValue(ReadString()));
        }
        if (!FlashCompatibleConvert.IsDigit(c))
        {
            switch (c)
            {
            case '-':
                break;

            case '[':
                return(new JSONListFieldValue(ReadList()));

            case '{':
                return(new JSONObjectFieldValue(ReadObject()));

            case 'f':
            case 't':
                return(new JSONBooleanFieldValue(ReadBoolean()));

            case 'n':
                ReadNull();
                return(new JSONNullFieldValue());

            default:
                return(null);
            }
        }
        return(new JSONNumberFieldValue(ReadNumber()));
    }
Example #8
0
 public XMLInStream Attribute(string name, out bool value)
 {
     value = FlashCompatibleConvert.ToBoolean(GetAttribute(name));
     return(this);
 }
Example #9
0
 public XMLInStream Attribute(string name, out Int32 value)
 {
     value = FlashCompatibleConvert.ToInt32(GetAttribute(name));
     return(this);
 }
Example #10
0
 public XMLInStream Content(out Int32 value)
 {
     value = FlashCompatibleConvert.ToInt32(current.content);
     return(this);
 }
Example #11
0
 public XMLInStream Content(out bool value)
 {
     value = FlashCompatibleConvert.ToBoolean(current.content);
     return(this);
 }
    public static double ToDouble(string s)
    {
        if (s == null)
        {
            throw new Exception("FlashCompatibleConvert.ToDouble was passed a null string as argument");
        }

        if (s.Length == 0)
        {
            throw new Exception("FlashCompatibleConvert.ToDouble was passed an empty string as argument");
        }

        // Search the index of the coma
        int indexComa = -1;

        for (int i = 0; i < s.Length; ++i)
        {
            if (CharToInt32(s[i]) == -2)
            {
                indexComa = i;
                break;
            }
        }

        // End of the string to be parsed
        int end = s.Length;

        // Search the index of the exponent
        int indexExponent = -1;

        for (int i = 0; i < s.Length; ++i)
        {
            if (CharToInt32(s[i]) == -3)
            {
                indexExponent = i;
                end           = i;
                break;
            }
        }

        // Check if negative
        bool negative         = s[0] == '-';
        int  offsetIfNegative = negative ? 1 : 0;

        int intPartLength = s.Length;

        if (indexComa != -1)
        {
            intPartLength = indexComa;
        }

        // Manage the main value with decimal
        double result = 0;

        for (int i = offsetIfNegative; i < end; ++i)
        {
            if (i == indexComa)
            {
                continue;
            }

            int n = CharToInt32(s[i]);
            if (n == -1)
            {
                throw new Exception("FlashCompatibleConvert.ToDouble was passed a wrong argument: " + s);
            }

            if (indexComa != -1 && i > indexComa)
            {
                result += n * Math.Pow(0.1, i - indexComa);
            }
            else
            {
                result += n * Math.Pow(10, intPartLength - i - 1);
            }
        }

        // Manage the exponent
        if (indexExponent != -1)
        {
            double exp = FlashCompatibleConvert.ToDouble(s.Substring(indexExponent + 1));
            result = result * Math.Pow(10, exp);
        }

        return(result * (negative ? -1 : 1));
    }