diff --git a/src/lib.rs b/src/lib.rs index e0179ad..40154c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,8 +21,8 @@ //! However, the following invariants will always be upheld: //! //! - The encoding will be compatible with UTF-8. In particular, splitting an -//! encoded byte sequence by a UTF-8–encoded character always produces other -//! valid byte sequences. They can be re-encoded without error using +//! encoded byte sequence by a UTF-8–encoded character always produces +//! other valid byte sequences. They can be re-encoded without error using //! [`RawOsString::into_os_string`] and similar methods. //! //! - All characters valid in platform strings are representable. [`OsStr`] and diff --git a/src/windows/wtf8/code_points.rs b/src/windows/wtf8/code_points.rs index 0b7e937..15e8753 100644 --- a/src/windows/wtf8/code_points.rs +++ b/src/windows/wtf8/code_points.rs @@ -15,7 +15,7 @@ where { iter: Peekable, surrogate: bool, - utf8: bool, + still_utf8: bool, } impl CodePoints @@ -29,12 +29,12 @@ where Self { iter: string.into_iter().peekable(), surrogate: false, - utf8: true, + still_utf8: true, } } pub(super) fn is_still_utf8(&self) -> bool { - self.utf8 + self.still_utf8 } fn consume_next(&mut self, code_point: &mut u32) -> Result<()> { @@ -107,7 +107,7 @@ where } else if code_point & 0xFE0 == 0x360 { if code_point & 0x10 == 0 { self.surrogate = true; - self.utf8 = false; + self.still_utf8 = false; } else if prev_surrogate { // Decoding a broken surrogate pair would be lossy. invalid = true; diff --git a/src/windows/wtf8/string.rs b/src/windows/wtf8/string.rs index 961c5c4..b3523a2 100644 --- a/src/windows/wtf8/string.rs +++ b/src/windows/wtf8/string.rs @@ -3,17 +3,20 @@ use crate::util; const SURROGATE_LENGTH: usize = 3; pub(crate) fn ends_with(string: &[u8], mut suffix: &[u8]) -> bool { - let index = match string.len().checked_sub(suffix.len()) { - Some(index) => index, - None => return false, + let index = if let Some(index) = string.len().checked_sub(suffix.len()) { + index + } else { + return false; }; if let Some(&byte) = string.get(index) { if util::is_continuation(byte) { let index = expect_encoded!(index.checked_sub(1)); - let mut wide_surrogate = match suffix.get(..SURROGATE_LENGTH) { - Some(surrogate) => super::encode_wide(surrogate), - None => return false, - }; + let mut wide_surrogate = + if let Some(surrogate) = suffix.get(..SURROGATE_LENGTH) { + super::encode_wide(surrogate) + } else { + return false; + }; let surrogate_wchar = wide_surrogate .next() .expect("failed decoding non-empty suffix"); @@ -35,9 +38,12 @@ pub(crate) fn ends_with(string: &[u8], mut suffix: &[u8]) -> bool { pub(crate) fn starts_with(string: &[u8], mut prefix: &[u8]) -> bool { if let Some(&byte) = string.get(prefix.len()) { if util::is_continuation(byte) { - let index = match prefix.len().checked_sub(SURROGATE_LENGTH) { - Some(index) => index, - None => return false, + let index = if let Some(index) = + prefix.len().checked_sub(SURROGATE_LENGTH) + { + index + } else { + return false; }; let (substring, surrogate) = prefix.split_at(index); let mut wide_surrogate = super::encode_wide(surrogate);