TryParseInt32() static private method

static private TryParseInt32 ( String s, NumberStyles style, NumberFormatInfo info, Int32 &result ) : Boolean
s String
style NumberStyles
info NumberFormatInfo
result Int32
return Boolean
Exemplo n.º 1
0
        private static bool TryParse(string s, NumberStyles style, NumberFormatInfo info, out short result)
        {
            int num;

            result = 0;
            if (!Number.TryParseInt32(s, style, info, out num))
            {
                return(false);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if ((num < 0) || (num > 0xffff))
                {
                    return(false);
                }
                result = (short)num;
                return(true);
            }
            if ((num < -32768) || (num > 0x7fff))
            {
                return(false);
            }
            result = (short)num;
            return(true);
        }
Exemplo n.º 2
0
        // Token: 0x060012F9 RID: 4857 RVA: 0x00038120 File Offset: 0x00036320
        private static bool TryParse(string s, NumberStyles style, NumberFormatInfo info, out sbyte result)
        {
            result = 0;
            int num;

            if (!Number.TryParseInt32(s, style, info, out num))
            {
                return(false);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if (num < 0 || num > 255)
                {
                    return(false);
                }
                result = (sbyte)num;
                return(true);
            }
            else
            {
                if (num < -128 || num > 127)
                {
                    return(false);
                }
                result = (sbyte)num;
                return(true);
            }
        }
Exemplo n.º 3
0
        private static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info, out Int16 result)
        {
            result = 0;
            int i;

            if (!Number.TryParseInt32(s, style, info, out i))
            {
                return(false);
            }

            // We need this check here since we don't allow signs to specified in hex numbers. So we fixup the result
            // for negative numbers
            if ((style & NumberStyles.AllowHexSpecifier) != 0)
            { // We are parsing a hexadecimal number
                if ((i < 0) || i > UInt16.MaxValue)
                {
                    return(false);
                }
                result = (Int16)i;
                return(true);
            }

            if (i < MinValue || i > MaxValue)
            {
                return(false);
            }
            result = (Int16)i;
            return(true);
        }
Exemplo n.º 4
0
        private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out SByte result)
        {
            result = 0;
            int i;

            if (!Number.TryParseInt32(s, style, info, out i))
            {
                return(false);
            }

            if ((style & NumberStyles.AllowHexSpecifier) != 0)
            { // We are parsing a hexadecimal number
                if ((i < 0) || i > Byte.MaxValue)
                {
                    return(false);
                }
                result = (sbyte)i;
                return(true);
            }

            if (i < MinValue || i > MaxValue)
            {
                return(false);
            }
            result = (sbyte)i;
            return(true);
        }
Exemplo n.º 5
0
        private static bool TryParse(string s, NumberStyles style, NumberFormatInfo info, out short result)
        {
            result = (short)0;
            int result1;

            if (!Number.TryParseInt32(s, style, info, out result1))
            {
                return(false);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if (result1 < 0 || result1 > (int)ushort.MaxValue)
                {
                    return(false);
                }
                result = (short)result1;
                return(true);
            }
            if (result1 < (int)short.MinValue || result1 > (int)short.MaxValue)
            {
                return(false);
            }
            result = (short)result1;
            return(true);
        }
Exemplo n.º 6
0
        // Parses an integer from a String. Returns false rather
        // than throwing exceptin if input is invalid
        //
        public static bool TryParse(string s, out int result)
        {
            if (s == null)
            {
                result = 0;
                return(false);
            }

            return(Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result));
        }
Exemplo n.º 7
0
        // Parses an integer from a String. Returns false rather
        // than throwing exceptin if input is invalid
        //
        public static bool TryParse(String s, out Int32 result)
        {
            if (s == null)
            {
                result = 0;
                return(false);
            }

            return(Number.TryParseInt32(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result));
        }
Exemplo n.º 8
0
        // Parses an integer from a String in the given style. Returns false rather
        // than throwing exceptin if input is invalid
        //
        public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int32 result)
        {
            NumberFormatInfo.ValidateParseStyleInteger(style);

            if (s == null)
            {
                result = 0;
                return(false);
            }

            return(Number.TryParseInt32(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result));
        }
Exemplo n.º 9
0
        private static bool TryParse(string s, NumberStyles style, NumberFormatInfo info, out byte result)
        {
            result = (byte)0;
            int result1;

            if (!Number.TryParseInt32(s, style, info, out result1) || result1 < 0 || result1 > (int)byte.MaxValue)
            {
                return(false);
            }
            result = (byte)result1;
            return(true);
        }
Exemplo n.º 10
0
        // Parses an integer from a String in the given style. Returns false rather
        // than throwing an exception if input is invalid.
        //
        public static bool TryParse([NotNullWhen(true)] string?s, NumberStyles style, IFormatProvider?provider, out int result)
        {
            NumberFormatInfo.ValidateParseStyleInteger(style);

            if (s == null)
            {
                result = 0;
                return(false);
            }

            return(Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK);
        }
Exemplo n.º 11
0
 private static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info, out sbyte result)
 {
     // For hex number styles AllowHexSpecifier >> 2 == 0x80 and cancels out MinValue so the check is effectively: (uint)i > byte.MaxValue
     // For integer styles it's zero and the effective check is (uint)(i - MinValue) > byte.MaxValue
     if (Number.TryParseInt32(s, style, info, out int i) != Number.ParsingStatus.OK ||
         (uint)(i - MinValue - ((int)(style & NumberStyles.AllowHexSpecifier) >> 2)) > byte.MaxValue)
     {
         result = 0;
         return(false);
     }
     result = (sbyte)i;
     return(true);
 }
Exemplo n.º 12
0
        private static sbyte Parse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info)
        {
            Number.ParsingStatus status = Number.TryParseInt32(s, style, info, out int i);
            if (status != Number.ParsingStatus.OK)
            {
                Number.ThrowOverflowOrFormatException(status, TypeCode.SByte);
            }

            // For hex number styles AllowHexSpecifier >> 2 == 0x80 and cancels out MinValue so the check is effectively: (uint)i > byte.MaxValue
            // For integer styles it's zero and the effective check is (uint)(i - MinValue) > byte.MaxValue
            if ((uint)(i - MinValue - ((int)(style & NumberStyles.AllowHexSpecifier) >> 2)) > byte.MaxValue)
            {
                Number.ThrowOverflowException(TypeCode.SByte);
            }
            return((sbyte)i);
        }
Exemplo n.º 13
0
        private static bool TryParse(string s, NumberStyles style, NumberFormatInfo info, out byte result)
        {
            int num;

            result = 0;
            if (!Number.TryParseInt32(s, style, info, out num))
            {
                return(false);
            }
            if ((num < 0) || (num > 0xff))
            {
                return(false);
            }
            result = (byte)num;
            return(true);
        }
Exemplo n.º 14
0
        private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out Byte result)
        {
            result = 0;
            int i;

            if (!Number.TryParseInt32(s, style, info, out i))
            {
                return(false);
            }
            if (i < MinValue || i > MaxValue)
            {
                return(false);
            }
            result = (byte)i;
            return(true);
        }
Exemplo n.º 15
0
Arquivo: Byte.cs Projeto: z1c0/corert
        private static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info, out byte result)
        {
            result = 0;
            int i;

            if (!Number.TryParseInt32(s, style, info, out i, out _))
            {
                return(false);
            }
            if (i < MinValue || i > MaxValue)
            {
                return(false);
            }
            result = (byte)i;
            return(true);
        }
Exemplo n.º 16
0
 public static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, IFormatProvider?provider, out int result)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result) == Number.ParsingStatus.OK);
 }
Exemplo n.º 17
0
 public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int32 result)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result));
 }
Exemplo n.º 18
0
 public static bool TryParse(String s, out Int32 result)
 {
     return(Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result));
 }
Exemplo n.º 19
0
 public static bool TryParse(ReadOnlySpan <char> s, out int result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result));
 }
Exemplo n.º 20
0
 public static bool TryParse(ReadOnlySpan <char> s, out int result)
 {
     return(Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result));
 }