internal static QuantityFormat <TUnit> Create( PaddedFormat valueFormat, PaddedFormat symbolFormat, TUnit unit) { var errorFormat = CreateErrorFormat(valueFormat, symbolFormat); string padding = null; if (valueFormat.PostPadding == null && symbolFormat.PrePadding == null) { if (ShouldSpace(symbolFormat.Format)) { padding = NoBreakingSpaceString; } } else { padding = valueFormat.PostPadding + symbolFormat.PrePadding; } return(new QuantityFormat <TUnit>( valueFormat.PrePadding, valueFormat.Format, padding, symbolFormat.Format, symbolFormat.PostPadding, errorFormat, unit)); }
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 QuantityFormat <TUnit> Create(PaddedFormat valueFormat, PaddedFormat symbolFormat, TUnit unit) { var errorFormat = CreateErrorFormat(valueFormat, symbolFormat); string?padding = null; if (valueFormat.PostPadding is null && symbolFormat.PrePadding is null) { if (ShouldSpace(symbolFormat.Format)) { padding = NoBreakingSpaceString; } }
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)); }