|
18 | 18 | #[cfg(test)]
|
19 | 19 | mod tests;
|
20 | 20 |
|
21 |
| -use core::char::{encode_utf8_raw, encode_utf16_raw}; |
| 21 | +use core::char::{MAX_LEN_UTF8, MAX_LEN_UTF16, encode_utf8_raw, encode_utf16_raw}; |
22 | 22 | use core::clone::CloneToUninit;
|
23 | 23 | use core::str::next_code_point;
|
24 | 24 |
|
@@ -117,7 +117,7 @@ impl CodePoint {
|
117 | 117 |
|
118 | 118 | /// Returns a Unicode scalar value for the code point.
|
119 | 119 | ///
|
120 |
| - /// Returns `'\u{FFFD}'` (the replacement character “�”) |
| 120 | + /// Returns `'\u{FFFD}'` (the replacement character “ ”) |
121 | 121 | /// if the code point is a surrogate (from U+D800 to U+DFFF).
|
122 | 122 | #[inline]
|
123 | 123 | pub fn to_char_lossy(&self) -> char {
|
@@ -240,7 +240,7 @@ impl Wtf8Buf {
|
240 | 240 | /// Copied from String::push
|
241 | 241 | /// This does **not** include the WTF-8 concatenation check or `is_known_utf8` check.
|
242 | 242 | fn push_code_point_unchecked(&mut self, code_point: CodePoint) {
|
243 |
| - let mut bytes = [0; 4]; |
| 243 | + let mut bytes = [0; MAX_LEN_UTF8]; |
244 | 244 | let bytes = encode_utf8_raw(code_point.value, &mut bytes);
|
245 | 245 | self.bytes.extend_from_slice(bytes)
|
246 | 246 | }
|
@@ -438,7 +438,7 @@ impl Wtf8Buf {
|
438 | 438 | ///
|
439 | 439 | /// This does not copy the data (but may overwrite parts of it in place).
|
440 | 440 | ///
|
441 |
| - /// Surrogates are replaced with `"\u{FFFD}"` (the replacement character “�”) |
| 441 | + /// Surrogates are replaced with `"\u{FFFD}"` (the replacement character “ ”) |
442 | 442 | pub fn into_string_lossy(mut self) -> String {
|
443 | 443 | // Fast path: If we already have UTF-8, we can return it immediately.
|
444 | 444 | if self.is_known_utf8 {
|
@@ -668,7 +668,7 @@ impl Wtf8 {
|
668 | 668 | /// Lossily converts the string to UTF-8.
|
669 | 669 | /// Returns a UTF-8 `&str` slice if the contents are well-formed in UTF-8.
|
670 | 670 | ///
|
671 |
| - /// Surrogates are replaced with `"\u{FFFD}"` (the replacement character “�”). |
| 671 | + /// Surrogates are replaced with `"\u{FFFD}"` (the replacement character “ ”). |
672 | 672 | ///
|
673 | 673 | /// This only copies the data if necessary (if it contains any surrogate).
|
674 | 674 | pub fn to_string_lossy(&self) -> Cow<'_, str> {
|
@@ -1001,7 +1001,7 @@ impl<'a> Iterator for EncodeWide<'a> {
|
1001 | 1001 | return Some(tmp);
|
1002 | 1002 | }
|
1003 | 1003 |
|
1004 |
| - let mut buf = [0; 2]; |
| 1004 | + let mut buf = [0; MAX_LEN_UTF16]; |
1005 | 1005 | self.code_points.next().map(|code_point| {
|
1006 | 1006 | let n = encode_utf16_raw(code_point.value, &mut buf).len();
|
1007 | 1007 | if n == 2 {
|
|
0 commit comments