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) string replaces every run of
whitespace 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
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) string` replaces every run of
whitespace 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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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