Exemple #1
0
        internal static PaddedFormat GetOrCreate(string format, ref int pos, out TUnit unit)
        {
            var start = pos;

            WhiteSpaceReader.TryRead(format, ref pos, out string prePadding);
            if (format == null ||
                pos == format.Length)
            {
                pos  = start;
                unit = Unit <TUnit> .Default;
                return(PaddedFormat.CreateUnknown(prePadding, null));
            }

            if (Cache.TryGetUnitForSymbol(format, ref pos, out string symbol, out unit))
            {
                if (WhiteSpaceReader.IsRestWhiteSpace(format, pos))
                {
                    WhiteSpaceReader.TryRead(format, ref pos, out string postPadding);
                    return(new PaddedFormat(prePadding, symbol, postPadding));
                }

                pos -= symbol.Length;
            }

            if (SymbolAndPowerReader.TryRead(format, ref pos, out IReadOnlyList <SymbolAndPower> symbolsAndPowers))
            {
                symbol = format.Substring(start, pos - start);

                WhiteSpaceReader.TryRead(format, ref pos, out string postPadding);
                if (!WhiteSpaceReader.IsRestWhiteSpace(format, pos))
                {
                    pos  = start;
                    unit = Unit <TUnit> .Default;
                    return(PaddedFormat.CreateUnknown(prePadding, format.Substring(start)));
                }

                if (Cache.TryGetUnitForParts(symbolsAndPowers, out unit))
                {
                    Cache.Add(symbol, symbolsAndPowers);
                    Cache.Add(symbol, unit);
                }
                else
                {
                    pos  = start;
                    unit = Unit <TUnit> .Default;
                    return(PaddedFormat.CreateUnknown(prePadding, format.Substring(start)));
                }

                return(new PaddedFormat(prePadding, symbol, postPadding));
            }

            pos = start;
            return(PaddedFormat.CreateUnknown(prePadding, format));
        }
        internal static PaddedFormat GetOrCreate(string format, ref int pos)
        {
            string prePadding;

            WhiteSpaceReader.TryRead(format, ref pos, out prePadding);
            string valueFormat;

            if (DoubleFormatReader.TryRead(format, ref pos, out valueFormat))
            {
                string postPadding;
                WhiteSpaceReader.TryRead(format, ref pos, out postPadding);
                return(new PaddedFormat(prePadding, valueFormat, postPadding));
            }

            return(PaddedFormat.CreateUnknown(prePadding, format));
        }