Example #1
0
 public static sbyte Parse(String s, IFormatProvider provider)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Parse(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.GetInstance(provider)));
 }
Example #2
0
 public static Decimal Parse(String s, IFormatProvider provider)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseDecimal(s.AsReadOnlySpan(), NumberStyles.Number, provider));
 }
Example #3
0
 public static sbyte Parse(String s)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Parse(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.CurrentInfo));
 }
Example #4
0
File: SByte.cs Project: tedd/corert
 private static sbyte Parse(String s, NumberStyles style, NumberFormatInfo info)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Parse(s.AsReadOnlySpan(), style, info));
 }
Example #5
0
 public static Boolean TryParse(String s, out Decimal result)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.TryParseDecimal(s.AsReadOnlySpan(), NumberStyles.Number, null, out result));
 }
Example #6
0
        //
        // Static Methods
        //

        // Determines whether a String represents true or false.
        //
        public static Boolean Parse(String value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            return(Parse(value.AsReadOnlySpan()));
        }
Example #7
0
 public static Boolean TryParse(String input, IFormatProvider formatProvider, out TimeSpan result)
 {
     if (input == null)
     {
         result = default(TimeSpan);
         return(false);
     }
     return(TimeSpanParse.TryParse(input.AsReadOnlySpan(), formatProvider, out result));
 }
Example #8
0
 public static Boolean TryParse(String s, out TimeSpan result)
 {
     if (s == null)
     {
         result = default(TimeSpan);
         return(false);
     }
     return(TimeSpanParse.TryParse(s.AsReadOnlySpan(), null, out result));
 }
Example #9
0
 public static TimeSpan ParseExact(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles)
 {
     ValidateStyles(styles, nameof(styles));
     if (input == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
     }
     return(TimeSpanParse.ParseExactMultiple(input.AsReadOnlySpan(), formats, formatProvider, styles));
 }
Example #10
0
 public static TimeSpan Parse(String s)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
     }
     /* Constructs a TimeSpan from a string.  Leading and trailing white space characters are allowed. */
     return(TimeSpanParse.Parse(s.AsReadOnlySpan(), null));
 }
Example #11
0
 public static Boolean TryParseExact(String input, String[] formats, IFormatProvider formatProvider, out TimeSpan result)
 {
     if (input == null)
     {
         result = default(TimeSpan);
         return(false);
     }
     return(TimeSpanParse.TryParseExactMultiple(input.AsReadOnlySpan(), formats, formatProvider, TimeSpanStyles.None, out result));
 }
Example #12
0
 public static Decimal Parse(String s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseDecimal(s.AsReadOnlySpan(), style, NumberFormatInfo.CurrentInfo));
 }
Example #13
0
 public static double Parse(String s, NumberStyles style, IFormatProvider provider)
 {
     NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseDouble(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider)));
 }
Example #14
0
 public static ushort Parse(String s, NumberStyles style, IFormatProvider provider)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Parse(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider)));
 }
Example #15
0
 public static Decimal Parse(String s, NumberStyles style, IFormatProvider provider)
 {
     ValidateParseStyleFloatingPoint(style);
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseDecimal(s.AsReadOnlySpan(), style, provider));
 }
Example #16
0
 public static long Parse(String s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseInt64(s.AsReadOnlySpan(), style, NumberFormatInfo.CurrentInfo));
 }
Example #17
0
        public static bool TryParse(String s, out double result)
        {
            if (s == null)
            {
                result = 0;
                return(false);
            }

            return(TryParse(s.AsReadOnlySpan(), NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result));
        }
Example #18
0
        public static Boolean TryParse(String s, out Int64 result)
        {
            if (s == null)
            {
                result = 0;
                return(false);
            }

            return(Number.TryParseInt64(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result));
        }
Example #19
0
 public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out Decimal result)
 {
     ValidateParseStyleFloatingPoint(style);
     if (s == null)
     {
         result = 0;
         return(false);
     }
     return(Number.TryParseDecimal(s.AsReadOnlySpan(), style, provider, out result));
 }
Example #20
0
        public static Boolean TryParse(String s, out Decimal result)
        {
            if (s == null)
            {
                result = 0;
                return(false);
            }

            return(Number.TryParseDecimal(s.AsReadOnlySpan(), NumberStyles.Number, null, out result));
        }
Example #21
0
 public static Boolean TryParseExact(String input, String format, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result)
 {
     ValidateStyles(styles, nameof(styles));
     if (input == null)
     {
         result = default(TimeSpan);
         return(false);
     }
     return(TimeSpanParse.TryParseExact(input.AsReadOnlySpan(), format, formatProvider, styles, out result));
 }
Example #22
0
        // Determines whether a String represents true or false.
        //
        public static Boolean TryParse(String value, out Boolean result)
        {
            if (value == null)
            {
                result = false;
                return(false);
            }

            return(TryParse(value.AsReadOnlySpan(), out result));
        }
Example #23
0
        public static bool TryParse(String s, out UInt16 result)
        {
            if (s == null)
            {
                result = 0;
                return(false);
            }

            return(TryParse(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result));
        }
Example #24
0
        public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out Single result)
        {
            NumberFormatInfo.ValidateParseStyleFloatingPoint(style);

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

            return(TryParse(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result));
        }
Example #25
0
        public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt16 result)
        {
            NumberFormatInfo.ValidateParseStyleInteger(style);

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

            return(TryParse(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result));
        }
Example #26
0
        public static Boolean TryParse(String input, out DateTimeOffset result)
        {
            TimeSpan offset;
            DateTime dateResult;
            Boolean  parsed = DateTimeParse.TryParse(input.AsReadOnlySpan(),
                                                     DateTimeFormatInfo.CurrentInfo,
                                                     DateTimeStyles.None,
                                                     out dateResult,
                                                     out offset);

            result = new DateTimeOffset(dateResult.Ticks, offset);
            return(parsed);
        }
Example #27
0
        // Constructs a DateTimeOffset from a string. The string must specify a
        // date and optionally a time in a culture-specific or universal format.
        // Leading and trailing whitespace characters are allowed.
        //
        public static DateTimeOffset Parse(String input)
        {
            if (input == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.index);                // TODO: index => input
            }
            TimeSpan offset;
            DateTime dateResult = DateTimeParse.Parse(input.AsReadOnlySpan(),
                                                      DateTimeFormatInfo.CurrentInfo,
                                                      DateTimeStyles.None,
                                                      out offset);

            return(new DateTimeOffset(dateResult.Ticks, offset));
        }
Example #28
0
        public static DateTimeOffset Parse(String input, IFormatProvider formatProvider, DateTimeStyles styles)
        {
            styles = ValidateStyles(styles, nameof(styles));
            if (input == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.index);                // TODO: index => input
            }
            TimeSpan offset;
            DateTime dateResult = DateTimeParse.Parse(input.AsReadOnlySpan(),
                                                      DateTimeFormatInfo.GetInstance(formatProvider),
                                                      styles,
                                                      out offset);

            return(new DateTimeOffset(dateResult.Ticks, offset));
        }
Example #29
0
        public static Boolean TryParse(String input, IFormatProvider formatProvider, DateTimeStyles styles, out DateTimeOffset result)
        {
            styles = ValidateStyles(styles, nameof(styles));
            if (input == null)
            {
                result = default(DateTimeOffset);
                return(false);
            }

            TimeSpan offset;
            DateTime dateResult;
            Boolean  parsed = DateTimeParse.TryParse(input.AsReadOnlySpan(),
                                                     DateTimeFormatInfo.GetInstance(formatProvider),
                                                     styles,
                                                     out dateResult,
                                                     out offset);

            result = new DateTimeOffset(dateResult.Ticks, offset);
            return(parsed);
        }
Example #30
0
        public static bool TryParse(ReadOnlySpan <char> value, out bool result)
        {
            ReadOnlySpan <char> trueSpan = TrueLiteral.AsReadOnlySpan();

            if (StringSpanHelpers.Equals(trueSpan, value, StringComparison.OrdinalIgnoreCase))
            {
                result = true;
                return(true);
            }

            ReadOnlySpan <char> falseSpan = FalseLiteral.AsReadOnlySpan();

            if (StringSpanHelpers.Equals(falseSpan, value, StringComparison.OrdinalIgnoreCase))
            {
                result = false;
                return(true);
            }

            // Special case: Trim whitespace as well as null characters.
            value = TrimWhiteSpaceAndNull(value);

            if (StringSpanHelpers.Equals(trueSpan, value, StringComparison.OrdinalIgnoreCase))
            {
                result = true;
                return(true);
            }

            if (StringSpanHelpers.Equals(falseSpan, value, StringComparison.OrdinalIgnoreCase))
            {
                result = false;
                return(true);
            }

            result = false;
            return(false);
        }