sanitizeSingleLine function

String sanitizeSingleLine(
  1. String input
)

sanitizeForDisplay for a ONE-LINE label: newlines, carriage returns, and tabs collapse to a single space FIRST, then the usual unsafe-rune sanitizing runs. Order matters — sanitizeForDisplay treats \r\n\t as C0 controls and rewrites them to replacementCharacter, so a caller that sanitizes then strips breaks gets � where a space belonged (the break is already gone). Use this for single-line labels — table/tree rows, tool cards, log lines, menu options — instead of hand-rolling the order per widget.

Implementation

String sanitizeSingleLine(String input) {
  // Nothing to rewrite, the common case: return it without the regex pass.
  // Callers that copy text rely on this, rather than a pre-check of their
  // own that could miss a control.
  if (isSanitizedForDisplay(input)) return input;
  return sanitizeForDisplay(input.replaceAll(_singleLineBreaks, ' '));
}