Add CollapseWhitespace to squeeze runs of whitespace into single spaces #8
Reference in New Issue
Block a user
Delete Branch "clawbot/util:proposal-collapse-whitespace"
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?
Adds
CollapseWhitespace(s string) string, which replaces every run ofwhitespace with a single space and removes whitespace at the start and end.
This belongs here because text that comes from a form field, a scraped page or
a pasted document is full of stray tabs, newlines and double spaces, and
flattening it is a step before almost any comparison, display or storage.
Things to know:
strings.Fields, which splits on whitespace as Unicodedefines it, so a non-breaking space or a line separator counts too. A regular
expression using
\swould not have caught those, since Go's regularexpressions treat
\sas ASCII only.this is the wrong function.
pasting the character, so that the interesting test case is visible to
someone reading the source.
whitespace.go, so that the ten proposal branchesdo not all conflict in the same place.
make teston this branch reports one failure,TestNowUnixMicro. That testalready fails on
masterand is unrelated to this change.Model: opus-5