splitQuotePrefix function

(String, String) splitQuotePrefix(
  1. String line
)

Splits a line into its quote prefix and the remaining body text.

Returns a record so callers reuse one regex pass; the prefix keeps its trailing space (if present) so re-joining preserves the original spacing.

Example:

splitQuotePrefix('> > hi'); // ('> > ', 'hi')

Audited: 2026-06-12 11:26 EDT

Implementation

(String prefix, String body) splitQuotePrefix(String line) {
  final RegExpMatch? match = _kQuotePrefix.firstMatch(line);
  if (match == null) return ('', line);
  final String prefix = match.group(0)!;
  // Strip exactly the matched prefix (anchored at ^) to get the body; using
  // replaceFirst avoids a length-based substring() and its RangeError surface.
  return (prefix, line.replaceFirst(prefix, ''));
}