Skip to main content

Module js_text

Module js_text 

Source
Expand description

Text operations with the exact semantics of JavaScript’s built-ins. What: Text operations with the exact semantics of the JavaScript built-ins the incumbent applies to strings it shares with the native wrapper. Why: Durable strings such as process birth identities are produced by .trim() in the incumbent; the native wrapper must produce byte-identical strings, and Rust’s str::trim uses a different whitespace set (it trims U+0085 and keeps U+FEFF).

In TS you’d write (pseudocode):

text.trim()

Functions§

is_javascript_whitespace
What: Whether a character is whitespace or a line terminator to ECMAScript trim. char is one Unicode scalar value. Why: ECMA-262 TrimString removes WhiteSpace (tab, vertical tab, form feed, space, no-break space, U+FEFF and every Zs character) and LineTerminator (LF, CR, U+2028, U+2029); nothing else.
trim_javascript
What: Remove leading and trailing JavaScript whitespace, as String.prototype.trim. &str borrows text; the result borrows a slice of it. Why: Shared strings must be trimmed exactly as the incumbent trims them.
trim_javascript_end
What: Remove trailing JavaScript whitespace, as String.prototype.trimEnd. &str borrows text; the result borrows a slice of it. Why: Git’s PID file text is trimmed at the end only before its pid prefix is read.