Exemplo n.º 1
0
 public static IEnumerable <string> WrappedLines(string self, IEnumerable <int> widths)
 {
     if (widths == null)
     {
         throw new ArgumentNullException("widths");
     }
     return(StringCoda.CreateWrappedLinesIterator(self, widths));
 }
Exemplo n.º 2
0
        private static IEnumerable <string> CreateWrappedLinesIterator(string self, IEnumerable <int> widths)
        {
            if (string.IsNullOrEmpty(self))
            {
                yield return(string.Empty);
            }
            else
            {
                using (IEnumerator <int> enumerator = widths.GetEnumerator())
                {
                    bool?hw    = new bool?();
                    int  width = StringCoda.GetNextWidth(enumerator, int.MaxValue, ref hw);
                    int  start = 0;
                    do
                    {
                        int  end = StringCoda.GetLineEnd(start, width, self);
                        char c   = self[end - 1];
                        if (char.IsWhiteSpace(c))
                        {
                            --end;
                        }
                        bool   needContinuation = end != self.Length && !StringCoda.IsEolChar(c);
                        string continuation     = "";
                        if (needContinuation)
                        {
                            --end;
                            continuation = "-";
                        }
                        string line = self.Substring(start, end - start) + continuation;
                        yield return(line);

                        start = end;
                        if (char.IsWhiteSpace(c))
                        {
                            ++start;
                        }
                        width = StringCoda.GetNextWidth(enumerator, width, ref hw);
                    }while (start < self.Length);
                }
            }
        }
Exemplo n.º 3
0
        private static int GetLineEnd(int start, int length, string description)
        {
            int num1 = Math.Min(start + length, description.Length);
            int num2 = -1;

            for (int index = start; index < num1; ++index)
            {
                if ((int)description[index] == 10)
                {
                    return(index + 1);
                }
                if (StringCoda.IsEolChar(description[index]))
                {
                    num2 = index + 1;
                }
            }
            if (num2 == -1 || num1 == description.Length)
            {
                return(num1);
            }
            return(num2);
        }
Exemplo n.º 4
0
 private static IEnumerable <string> GetLines(string description)
 {
     return(StringCoda.WrappedLines(description,
                                    80 - OptionWidth,
                                    80 - OptionWidth - 2));
 }
Exemplo n.º 5
0
 private static IEnumerable <string> GetLines(string description, int firstWidth, int remWidth)
 {
     return(StringCoda.WrappedLines(description, firstWidth, remWidth));
 }
Exemplo n.º 6
0
        public static IEnumerable <string> WrappedLines(string self, params int[] widths)
        {
            IEnumerable <int> widths1 = (IEnumerable <int>)widths;

            return(StringCoda.WrappedLines(self, widths1));
        }