Unicode-escape hygiene for model-authored edit TEXT.
Public surface: decode-unicode-escapes — undo the \uXXXX drift a model
writes when it means the character itself, and nothing else.
Unicode-escape hygiene for model-authored edit TEXT. Public surface: `decode-unicode-escapes` — undo the `\uXXXX` drift a model writes when it means the character itself, and nothing else.
(decode-unicode-escapes s)Decode the \uXXXX escapes in edit text that can only be model drift.
A literal \u2014 handed to struct_patch code used
to be written to disk as those six characters, so edited files grew
\u2014 where an em dash belonged. Here it becomes the em dash, while every
escape a real file may legitimately carry is returned untouched: a doubled
\\uXXXX, an ASCII or control escape, a lone surrogate, and anything that
would decode into invisible or unreal ink -- private use, an unassigned
point, a bidi override, a zero-width joiner, a line separator, a space that
does not look like one. A surrogate PAIR is judged by the code point it
builds, so emoji survive the trip and an invisible U+E0020 tag character
cannot sneak in as one.
Pure and total: a non-string, or a string with no escape in it, is returned
as-is. Text between backslashes is never walked character by character --
indexOf finds the next candidate and the span is bulk-copied -- so the
common edit, which carries no escape at all or one, costs a scan.
Decode the `\uXXXX` escapes in edit text that can only be model drift. A literal `\u2014` handed to `struct_patch` `code` used to be written to disk as those six characters, so edited files grew `\u2014` where an em dash belonged. Here it becomes the em dash, while every escape a real file may legitimately carry is returned untouched: a doubled `\\uXXXX`, an ASCII or control escape, a lone surrogate, and anything that would decode into invisible or unreal ink -- private use, an unassigned point, a bidi override, a zero-width joiner, a line separator, a space that does not look like one. A surrogate PAIR is judged by the code point it builds, so emoji survive the trip and an invisible U+E0020 tag character cannot sneak in as one. Pure and total: a non-string, or a string with no escape in it, is returned as-is. Text between backslashes is never walked character by character -- `indexOf` finds the next candidate and the span is bulk-copied -- so the common edit, which carries no escape at all or one, costs a scan.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |