Exemple #1
0
        // TODO: format should be ReadOnlySpan<T>
        public static Format.Parsed Parse(Span <char> format)
        {
            if (format.Length == 0)
            {
                return(default(Format.Parsed));
            }

            uint precision = NoPrecision;

            if (format.Length > 1)
            {
                var span = format.Slice(1, format.Length - 1);

                if (!InvariantParser.TryParse(span, out precision))
                {
                    throw new NotImplementedException(Properties.Resources.UnableToParsePrecision);
                }

                if (precision > Parsed.MaxPrecision)
                {
                    // TODO: this is a contract violation
                    throw new Exception(Properties.Resources.PrecisionValueOutOfRange);
                }
            }

            // TODO: this is duplicated from above. It needs to be refactored
            var specifier = format[0];

            return(new Parsed(specifier, (byte)precision));
        }
Exemple #2
0
        // once we have a non allocating conversion from string to ReadOnlySpan<char>, we can remove this overload
        public static Format.Parsed Parse(string format)
        {
            if (format == null || format.Length == 0)
            {
                return(default(Format.Parsed));
            }

            uint precision = NoPrecision;

            if (format.Length > 1)
            {
                if (!InvariantParser.TryParse(format, 1, format.Length - 1, out precision))
                {
                    throw new NotImplementedException("Unable to parse precision specification");
                }

                if (precision > Parsed.MaxPrecision)
                {
                    // TODO: this is a contract violation
                    throw new Exception(Properties.Resources.PrecisionValueOutOfRange);
                }
            }

            var specifier = format[0];

            return(new Parsed(specifier, (byte)precision));
        }