Skip to content

Commit

Permalink
Add comment on UTF-16 surrogates
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Apr 9, 2024
1 parent 952d432 commit 19f04a7
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/std/src/sys/pal/windows/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub const fn utf16_len(s: &str) -> usize {
n => n as usize,
};
i += utf8_len;
// Note that UTF-16 surrogates (U+D800 to U+DFFF) are not encodable as UTF-8,
// so (unlike with WTF-8) we don't have to worry about how they'll get re-encoded.
len += if utf8_len < 4 { 1 } else { 2 };
}
len
Expand Down

0 comments on commit 19f04a7

Please sign in to comment.