TryStringToNumber() private static method

private static TryStringToNumber ( String str, NumberStyles options, NumberBuffer &number, NumberFormatInfo numfmt, Boolean parseDecimal ) : Boolean
str String
options NumberStyles
number NumberBuffer
numfmt NumberFormatInfo
parseDecimal Boolean
return Boolean
コード例 #1
0
        internal static unsafe double ParseDouble(string value, NumberStyles options, NumberFormatInfo numfmt)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            byte *stackBuffer = stackalloc byte[Number.NumberBuffer.NumberBufferBytes];

            Number.NumberBuffer number = new Number.NumberBuffer(stackBuffer);
            double num = 0.0;

            if (!Number.TryStringToNumber(value, options, ref number, numfmt, false))
            {
                string str = value.Trim();
                if (str.Equals(numfmt.PositiveInfinitySymbol))
                {
                    return(double.PositiveInfinity);
                }
                if (str.Equals(numfmt.NegativeInfinitySymbol))
                {
                    return(double.NegativeInfinity);
                }
                if (str.Equals(numfmt.NaNSymbol))
                {
                    return(double.NaN);
                }
                throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
            }
            if (!Number.NumberBufferToDouble(number.PackForNative(), ref num))
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Double"));
            }
            return(num);
        }
コード例 #2
0
        internal unsafe static bool TryParseSingle(string value, NumberStyles options, NumberFormatInfo numfmt, out float result)
        {
            byte *stackBuffer = stackalloc byte[checked (unchecked ((UIntPtr)Number.NumberBuffer.NumberBufferBytes) * 1)];

            Number.NumberBuffer numberBuffer = new Number.NumberBuffer(stackBuffer);
            result = 0f;
            double num = 0.0;

            if (!Number.TryStringToNumber(value, options, ref numberBuffer, numfmt, false))
            {
                return(false);
            }
            if (!Number.NumberBufferToDouble(numberBuffer.PackForNative(), ref num))
            {
                return(false);
            }
            float num2 = (float)num;

            if (float.IsInfinity(num2))
            {
                return(false);
            }
            result = num2;
            return(true);
        }
コード例 #3
0
        internal static unsafe bool TryParseDouble(string value, NumberStyles options, NumberFormatInfo numfmt, out double result)
        {
            byte *stackBuffer = stackalloc byte[Number.NumberBuffer.NumberBufferBytes];

            Number.NumberBuffer number = new Number.NumberBuffer(stackBuffer);
            result = 0.0;
            return(Number.TryStringToNumber(value, options, ref number, numfmt, false) && Number.NumberBufferToDouble(number.PackForNative(), ref result));
        }
コード例 #4
0
        internal unsafe static bool TryParseDecimal(string value, NumberStyles options, NumberFormatInfo numfmt, out decimal result)
        {
            byte *stackBuffer = stackalloc byte[checked (unchecked ((UIntPtr)Number.NumberBuffer.NumberBufferBytes) * 1)];

            Number.NumberBuffer numberBuffer = new Number.NumberBuffer(stackBuffer);
            result = 0m;
            return(Number.TryStringToNumber(value, options, ref numberBuffer, numfmt, true) && Number.NumberBufferToDecimal(numberBuffer.PackForNative(), ref result));
        }
コード例 #5
0
        internal unsafe static float ParseSingle(string value, NumberStyles options, NumberFormatInfo numfmt)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            byte *stackBuffer = stackalloc byte[checked (unchecked ((UIntPtr)Number.NumberBuffer.NumberBufferBytes) * 1)];

            Number.NumberBuffer numberBuffer = new Number.NumberBuffer(stackBuffer);
            double num = 0.0;

            if (!Number.TryStringToNumber(value, options, ref numberBuffer, numfmt, false))
            {
                string text = value.Trim();
                if (text.Equals(numfmt.PositiveInfinitySymbol))
                {
                    return(float.PositiveInfinity);
                }
                if (text.Equals(numfmt.NegativeInfinitySymbol))
                {
                    return(float.NegativeInfinity);
                }
                if (text.Equals(numfmt.NaNSymbol))
                {
                    return(float.NaN);
                }
                throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
            }
            else
            {
                if (!Number.NumberBufferToDouble(numberBuffer.PackForNative(), ref num))
                {
                    throw new OverflowException(Environment.GetResourceString("Overflow_Single"));
                }
                float num2 = (float)num;
                if (float.IsInfinity(num2))
                {
                    throw new OverflowException(Environment.GetResourceString("Overflow_Single"));
                }
                return(num2);
            }
        }
コード例 #6
0
        internal static unsafe bool TryParseSingle(string value, NumberStyles options, NumberFormatInfo numfmt, out float result)
        {
            byte *stackBuffer = stackalloc byte[Number.NumberBuffer.NumberBufferBytes];

            Number.NumberBuffer number = new Number.NumberBuffer(stackBuffer);
            result = 0.0f;
            double num = 0.0;

            if (!Number.TryStringToNumber(value, options, ref number, numfmt, false) || !Number.NumberBufferToDouble(number.PackForNative(), ref num))
            {
                return(false);
            }
            float f = (float)num;

            if (float.IsInfinity(f))
            {
                return(false);
            }
            result = f;
            return(true);
        }
コード例 #7
0
        internal static unsafe bool TryParseUInt64(string s, NumberStyles style, NumberFormatInfo info, out ulong result)
        {
            byte *stackBuffer = stackalloc byte[Number.NumberBuffer.NumberBufferBytes];

            Number.NumberBuffer number = new Number.NumberBuffer(stackBuffer);
            result = 0UL;
            if (!Number.TryStringToNumber(s, style, ref number, info, false))
            {
                return(false);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if (!Number.HexNumberToUInt64(ref number, ref result))
                {
                    return(false);
                }
            }
            else if (!Number.NumberToUInt64(ref number, ref result))
            {
                return(false);
            }
            return(true);
        }
コード例 #8
0
        internal unsafe static bool TryParseUInt32(string s, NumberStyles style, NumberFormatInfo info, out uint result)
        {
            byte *stackBuffer = stackalloc byte[checked (unchecked ((UIntPtr)Number.NumberBuffer.NumberBufferBytes) * 1)];

            Number.NumberBuffer numberBuffer = new Number.NumberBuffer(stackBuffer);
            result = 0U;
            if (!Number.TryStringToNumber(s, style, ref numberBuffer, info, false))
            {
                return(false);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if (!Number.HexNumberToUInt32(ref numberBuffer, ref result))
                {
                    return(false);
                }
            }
            else if (!Number.NumberToUInt32(ref numberBuffer, ref result))
            {
                return(false);
            }
            return(true);
        }
コード例 #9
0
 internal static bool TryStringToNumber(string str, NumberStyles options, ref Number.NumberBuffer number, NumberFormatInfo numfmt, bool parseDecimal)
 {
     return(Number.TryStringToNumber(str, options, ref number, (StringBuilder)null, numfmt, parseDecimal));
 }