Example #1
0
 internal ListFormatter(ListFormat format, StringBuilder outputBuilder, int itemIndex)
 {
     Delimiter     = format.Delimiter;
     Escape        = format.Escape;
     NoItems       = format.NoItems;
     OutputBuilder = outputBuilder;
     ItemIndex     = itemIndex;
 }
Example #2
0
 public SymbolListFormatter(char delimiter, char escape = '\\')
 {
     DelimiterChar    = delimiter;
     EscapeChar       = escape;
     Delimiter        = delimiter.ToString();
     Escape           = escape.ToString();
     EscapedDelimiter = $"{Escape}{Delimiter}";
     EscapedEscape    = $"{Escape}{Escape}";
     ListFormat       = new ListFormat(delimiter, escape);
 }
Example #3
0
 public static string ManyToOne(IEnumerable <string> values, ListFormat listFormat)
 {
     using var f = listFormat.CreateFormatter();
     foreach (var value in values)
     {
         f.Append(value);
     }
     f.AppendEnd();
     return(f.OutputBuilder.ToString());
 }
Example #4
0
        public static string ManyToOne(IEnumerable <string> values, ListFormat listFormat)
        {
            var formatter = listFormat.CreateFormatter(StringBuilderEx.Acquire());

            foreach (var value in values)
            {
                formatter.Append(value);
            }
            formatter.AppendEnd();
            return(formatter.OutputBuilder.ToStringAndRelease());
        }
Example #5
0
        public static string[] OneToMany(string value, ListFormat listFormat)
        {
            if (value == "")
            {
                return(Array.Empty <string>());
            }
            using var p = listFormat.CreateParser(value);
            var buffer = MemoryBuffer <string> .Lease(true);

            try {
                while (p.TryParseNext())
                {
                    buffer.Add(p.Item);
                }
                return(buffer.ToArray());
            }
            finally {
                buffer.Release();
            }
        }