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
示例#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);
        }
示例#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);
            }
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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));
        }
示例#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));
        }
示例#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));
        }
示例#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);
        }
示例#10
0
文件: Int32.cs 项目: mateoatr/runtime
        // 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);
        }
示例#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);
 }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#15
0
文件: Byte.cs 项目: 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);
        }
示例#16
0
文件: Int32.cs 项目: mateoatr/runtime
 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);
 }
示例#17
0
文件: Int32.cs 项目: shrah/coreclr
 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));
 }
示例#18
0
文件: Int32.cs 项目: shrah/coreclr
 public static bool TryParse(String s, out Int32 result)
 {
     return(Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result));
 }
示例#19
0
文件: Int32.cs 项目: wecing/coreclr
 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));
 }
示例#20
0
 public static bool TryParse(ReadOnlySpan <char> s, out int result)
 {
     return(Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result));
 }