private static List<String> wrap(String text, int maxLineLength,
			WhitespaceHandler whitespacer) {

		List<String> lines = new ArrayList<>();
		int start = 0;
		int size = 0;
		boolean breakNeeded = false;
		boolean hasForcedBreak = false;

		int length = text.length();
		for (int i = 0; i < length; i++) {
			char c = text.charAt(i);
			size += (c == '\t') ? 4 : 1;

			boolean hitMaxLength = size >= maxLineLength;
			boolean isWhitespace = Character.isWhitespace(c);
			if (breakNeeded) {
				if (isWhitespace) { // we found a whitespace--break!
					String line = text.substring(start, i);
					lines.add(line);

					// left-justify by moving past spaces
					i += whitespacer.countSpaces(text, i);
					start = i;
					size = 0;
					breakNeeded = false;
				}
				// looking for a break; no whitespace--are we past the hard limit?
				else if (size - maxLineLength >= MAX_WORD_LENGTH) {

					// past hard limit; just chop at the original desired length
					hasForcedBreak = true;
					breakNeeded = false;
					int end = start + maxLineLength;
					lines.add(text.substring(start, end));
					start = end;
					size = i - start;
				}
			}
			else if (hitMaxLength) {

				breakNeeded = false;
				String line = text.substring(start, i);
				if (!isWhitespace) { // not on a whitespace; look for whitespace to split on

					int end = StringUtils.lastIndexOfAny(line, " ", "\t");
					if (end < 0) {
						// delay breaking for whitespace
						breakNeeded = true;
						continue;
					}

					// +1 to include the space; it will get trimmed below as needed
					line = line.substring(0, end + 1);
				}

				lines.add(whitespacer.trim(line));
				start = start + line.length();

				// left-justify by moving past spaces
				start += whitespacer.countSpaces(text, start);
				i = Math.max(i, start); // adjust for removed spaces

				// i != start when we chopped the line on a space before 'i'
				size = i - start;
			}
		}

		// handle any trailing text; don't split if no breaks were forced (this keeps the text
		// consistent--either break all text or break none)
		String line = whitespacer.trim(text.substring(start, length));
		int splitOn = hasForcedBreak ? maxLineLength : -1;
		List<String> remainder = forceSplitOn(line, splitOn);
		lines.addAll(remainder);

		return lines;
	}
Splits the given line into multiple lines based upon the given max length.

<P>Once the maximum provided length is passed, the algorithm attempts to split on a word
boundary by first looking backwards in the given line (since the last split value) to
find a space.  If no space is found in that direction, then the algorithm will keep
walking forward until either a space is found or {@link #MAX_WORD_LENGTH} is passed,
at which point the line will be ended, splitting any word that surrounds that index.

@param text the text to wrap
@param maxLineLength the max desired length of each output line
@param whitespacer the object that knows how to manipulate whitespace depending 
       upon client preferences
@return the new lines
Ghidra/Framework/Gui/src/main/java/ghidra/util/html/HtmlLineSplitter.java