private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) { StringCollection retVal = new StringCollection(); if (string.IsNullOrEmpty(val)) { retVal.Add(val); return(retVal); } string[] strArray = SplitLines(val); for (int i = 0; i < strArray.Length; i++) { if ((strArray[i] == null) || (displayCells.Length(strArray[i]) <= firstLineLen)) { retVal.Add(strArray[i]); continue; } SplitLinesAccumulator accumulator = new SplitLinesAccumulator(retVal, firstLineLen, followingLinesLen); int offset = 0; while (true) { int activeLen = accumulator.ActiveLen; int num5 = displayCells.Length(strArray[i], offset) - activeLen; if (num5 <= 0) { break; } int length = displayCells.GetHeadSplitLength(strArray[i], offset, activeLen); if (length <= 0) { length = 1; accumulator.AddLine("?"); } else { accumulator.AddLine(strArray[i].Substring(offset, length)); } offset += length; } accumulator.AddLine(strArray[i].Substring(offset)); } return(retVal); }
private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) { StringCollection retVal = new StringCollection(); if (string.IsNullOrEmpty(val)) { retVal.Add(val); return retVal; } string[] strArray = SplitLines(val); for (int i = 0; i < strArray.Length; i++) { if ((strArray[i] == null) || (displayCells.Length(strArray[i]) <= firstLineLen)) { retVal.Add(strArray[i]); continue; } SplitLinesAccumulator accumulator = new SplitLinesAccumulator(retVal, firstLineLen, followingLinesLen); int offset = 0; while (true) { int activeLen = accumulator.ActiveLen; int num5 = displayCells.Length(strArray[i], offset) - activeLen; if (num5 <= 0) { break; } int length = displayCells.GetHeadSplitLength(strArray[i], offset, activeLen); if (length <= 0) { length = 1; accumulator.AddLine("?"); } else { accumulator.AddLine(strArray[i].Substring(offset, length)); } offset += length; } accumulator.AddLine(strArray[i].Substring(offset)); } return retVal; }
private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) { StringCollection retVal = new StringCollection(); if (string.IsNullOrEmpty(val)) { // if null or empty, just add and we are done retVal.Add(val); return(retVal); } // break string on newlines and process each line separately string[] lines = SplitLines(val); for (int k = 0; k < lines.Length; k++) { string currentLine = lines[k]; if (currentLine == null || displayCells.Length(currentLine) <= firstLineLen) { // we do not need to split further, just add retVal.Add(currentLine); continue; } // the string does not fit, so we have to wrap around on multiple lines // for each of these lines in the string, the first line will have // a (potentially) different length (indentation or hanging) // for each line, start a new state SplitLinesAccumulator accumulator = new SplitLinesAccumulator(retVal, firstLineLen, followingLinesLen); int offset = 0; // offset into the line we are splitting while (offset < currentLine.Length) { // acquire the current active display line length (it can very from call to call) int currentDisplayLen = accumulator.ActiveLen; // determine if the current tail would fit or not // for the remaining part of the string, determine its display cell count int currentCellsToFit = displayCells.Length(currentLine, offset); // determine if we fit into the line int excessCells = currentCellsToFit - currentDisplayLen; if (excessCells > 0) { // we are not at the end of the string, select a sub string // that would fit in the remaining display length int charactersToAdd = displayCells.TruncateTail(currentLine, offset, currentDisplayLen); if (charactersToAdd <= 0) { // corner case: we have a two cell character and the current // display length is one. // add a single cell arbitrary character instead of the original // one and keep going charactersToAdd = 1; accumulator.AddLine("?"); } else { // of the given length, add it to the accumulator accumulator.AddLine(currentLine.VtSubstring(offset, charactersToAdd)); } // increase the offset by the # of characters added offset += charactersToAdd; } else { // we reached the last (partial) line, we add it all accumulator.AddLine(currentLine.VtSubstring(offset)); break; } } } return(retVal); }
private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displayCells, string val, int firstLineLen, int followingLinesLen) { StringCollection retVal = new StringCollection(); if (string.IsNullOrEmpty(val)) { // if null or empty, just add and we are done retVal.Add(val); return retVal; } // break string on newlines and process each line separately string[] lines = SplitLines(val); for (int k = 0; k < lines.Length; k++) { if (lines[k] == null || displayCells.Length(lines[k]) <= firstLineLen) { // we do not need to split further, just add retVal.Add(lines[k]); continue; } // the string does not fit, so we have to wrap around on multiple lines // for each of these lines in the string, the first line will have // a (potentially) different length (indentation or hanging) // for each line, start a new state SplitLinesAccumulator accumulator = new SplitLinesAccumulator(retVal, firstLineLen, followingLinesLen); int offset = 0; // offset into the line we are splitting while (true) { // acquire the current active display line length (it can very from call to call) int currentDisplayLen = accumulator.ActiveLen; // determine if the current tail would fit or not // for the remaining part of the string, determine its display cell count int currentCellsToFit = displayCells.Length(lines[k], offset); // determine if we fit into the line int excessCells = currentCellsToFit - currentDisplayLen; if (excessCells > 0) { // we are not at the end of the string, select a sub string // that would fit in the remaining display length int charactersToAdd = displayCells.GetHeadSplitLength(lines[k], offset, currentDisplayLen); if (charactersToAdd <= 0) { // corner case: we have a two cell character and the current // display length is one. // add a single cell arbitrary character instead of the original // one and keep going charactersToAdd = 1; accumulator.AddLine("?"); } else { // of the given length, add it to the accumulator accumulator.AddLine(lines[k].Substring(offset, charactersToAdd)); } // increase the offset by the # of characters added offset += charactersToAdd; } else { // we reached the last (partial) line, we add it all accumulator.AddLine(lines[k].Substring(offset)); break; } } } return retVal; }