Skip to content

Commit ae03f89

Browse files
committed
Add comment on UTF-16 surrogates
1 parent 3bcd03a commit ae03f89

File tree

1 file changed

+2
-0
lines changed
  • library/std/src/sys/pal/windows

1 file changed

+2
-0
lines changed

library/std/src/sys/pal/windows/api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub const fn utf16_len(s: &str) -> usize {
7373
n => n as usize,
7474
};
7575
i += utf8_len;
76+
// Note that UTF-16 surrogates (U+D800 to U+DFFF) are not encodable as UTF-8,
77+
// so (unlike with WTF-8) we don't have to worry about how they'll get re-encoded.
7678
len += if utf8_len < 4 { 1 } else { 2 };
7779
}
7880
len

0 commit comments

Comments
 (0)