Exemplo n.º 1
0
        public static double GetDouble(string value)
        {
            double val = 0;

            if (double.TryParse(value, out val))
            {
                return(val);
            }

            throw TokenizerError.ErrorWithName("get-double", "improperly formed float value", value);
        }
Exemplo n.º 2
0
        public static float GetFloat(string value)
        {
            float val = 0;

            if (float.TryParse(value, out val))
            {
                return(val);
            }

            throw TokenizerError.ErrorWithName("get-float", "improperly formed float value", value);
        }
Exemplo n.º 3
0
 public static int GetInteger(string value)
 {
     try
     {
         var val = int.Parse(value, NumberStyles.AllowLeadingSign);
         return(val);
     }
     catch (System.Exception)
     {
         throw TokenizerError.ErrorWithName("get-integer", "improperly formed int value", value);
     }
 }
Exemplo n.º 4
0
 public static int GetHexadecimal(string value)
 {
     try
     {
         UnityEngine.Debug.Assert(value.Length > 2, "Error in hex literal");
         var hval = int.Parse(value.Substring(2), NumberStyles.AllowHexSpecifier);
         return(hval);
     }
     catch (System.Exception ex)
     {
         throw TokenizerError.ErrorWithName("get-hexadecimal", "improperly formed int value", value);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Return double value from any type of string
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double GetNumerical(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw TokenizerError.ErrorWithName("get-double", "unexpected empty string", value);
            }
            if (char.IsDigit(value[0]))
            {
                return(GetDouble(value));
            }

            if (value[0] == '#')
            {
                return(GetHexadecimal(value));
            }

            throw TokenizerError.ErrorWithName("get-numerical", "improperly formed numerical value", value);
        }