That’s why on windows Rust’s OsStr is an extension of UTF8 called WTF8, which allows surrogates (then again “traditional” unix paths are just bags of bytes so it’s not like windows is any worse).
That’s why on windows Rust’s OsStr is an extension of UTF8 called WTF8, which allows surrogates (then again “traditional” unix paths are just bags of bytes so it’s not like windows is any worse).
MS's approach is better in the case where we're all good stewards of the filesystem but the edges are sharp when someone isn't.
So in practice the only way invalid UTF-16 shows up is from malicious programs (or people testing their handling of non-unicode).
I doubt even really old NT programs (pre 2000) using UCS-2 would have included unpaired surrogates because IIRC those code points were never mapped to actual characters so I don't think that's an issue in practice.
Lone surrogates regularly show up in any environment which allows them.