internal List<ConsoleHostUserInterface.Word> ChopTextIntoWords(string text, int maxWidthInBufferCells) { List<ConsoleHostUserInterface.Word> words = new List<ConsoleHostUserInterface.Word>(); if (!string.IsNullOrEmpty(text)) { if (maxWidthInBufferCells >= 1) { text = text.Replace('\t', ' '); words = new List<ConsoleHostUserInterface.Word>(); int num = 0; int num1 = 0; bool flag = false; while (num1 < text.Length) { if (text[num1] != '\n') { if (text[num1] != ' ') { if (flag) { this.AddWord(text, num, num1, maxWidthInBufferCells, flag, ref words); num = num1; } flag = false; } else { if (!flag) { this.AddWord(text, num, num1, maxWidthInBufferCells, flag, ref words); num = num1; } flag = true; } num1++; } else { if (num < num1) { this.AddWord(text, num, num1, maxWidthInBufferCells, flag, ref words); } ConsoleHostUserInterface.Word word = new ConsoleHostUserInterface.Word(); word.Flags = ConsoleHostUserInterface.WordFlags.IsNewline; words.Add(word); num1++; num = num1; flag = false; } } if (num != num1) { this.AddWord(text, num, text.Length, maxWidthInBufferCells, flag, ref words); } return words; } else { return words; } } else { return words; } }
internal void AddWord(string text, int startIndex, int endIndex, int maxWidthInBufferCells, bool isWhitespace, ref List<ConsoleHostUserInterface.Word> result) { while (startIndex < endIndex) { int num = Math.Min(endIndex, startIndex + maxWidthInBufferCells); ConsoleHostUserInterface.Word word = new ConsoleHostUserInterface.Word(); if (isWhitespace) { word.Flags = ConsoleHostUserInterface.WordFlags.IsWhitespace; } while (true) { word.Text = text.Substring(startIndex, num - startIndex); word.CellCount = this.RawUI.LengthInBufferCells(word.Text); if (word.CellCount <= maxWidthInBufferCells) { break; } num--; } result.Add(word); startIndex = num; } }