Ejemplo n.º 1
0
        public IList <string> SplitText(string text, int count)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            text = _whitespace.Replace(text, " ").Trim();

            if (count == 1)
            {
                return new[] { text }
            }
            ;

            if (text.Contains(";"))
            {
                return(text.Split(';', count).TrimAll().PadToLength(count, ""));
            }

            var words = _whitespace.Split(text);

            if (words.Length <= count)
            {
                return(words.PadToLength(count, ""));
            }

            TextLineStack best     = null;
            long          bestCost = long.MaxValue;

            foreach (var stack in AllSplits(words, count))
            {
                var cost = stack.Cost;
                if (cost < bestCost)
                {
                    best     = stack;
                    bestCost = cost;
                }
            }

            return(best.GetLines().PadToLength(count, ""));
        }
Ejemplo n.º 2
0
 public TextLineStack(TextLine line, TextLineStack stack)
 {
     _stack      = stack._stack.Push(line);
     LongestLine = Math.Max(line.Length, stack.LongestLine);
 }