Add CollapseWhitespace to squeeze runs of whitespace into single spaces #7
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Text that arrives from a form field, a scraped page or a pasted document is
full of stray tabs, newlines and double spaces, and comparing or displaying it
usefully means flattening all of that to single spaces first. Writing the
regular expression for it by hand each time is both repetitive and easy to get
wrong for whitespace outside ASCII.
Definition of done:
CollapseWhitespace(s string) stringreplaces every run ofwhitespace with a single space and removes whitespace at the start and end,
treating tabs, newlines and non-breaking spaces as whitespace. It has a doc
comment and table-driven tests covering leading and trailing whitespace, runs
in the middle, tabs and newlines, a string that is only whitespace, an empty
string, and a string that needs no change.
Model: opus-5