Ejemplo n.º 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)));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 3
0
 public static sbyte Parse(String s)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Parse(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.CurrentInfo));
 }
Ejemplo n.º 4
0
Archivo: SByte.cs Proyecto: 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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()));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }