Skip to main content

cmp_units

Function cmp_units 

Source
pub fn cmp_units(a: &str, b: &str) -> Ordering
Expand description

Lexicographic order over UTF-16 code units — the order JS’s </<=/>/>= and the default sort comparator use (7.2.13 IsLessThan step 3.d compares “the code unit at index k”).

Rust’s str: Ord compares UTF-8 bytes, which is code-point order. The two disagree exactly when one string reaches an astral character where the other has a BMP character at or above U+E000: "\u{1D4B3}" < "\u{FFFF}" is true in JS (leading surrogate 0xD835 < 0xFFFF) and false by code point (0x1D4B3 > 0xFFFF).

Decoding is lazy per unit, so the common all-BMP case never allocates.