diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2956e58..69a6ec7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,7 @@ jobs: runs-on: ubuntu-latest env: RUSTFLAGS: -Dwarnings - flags: --feature-powerset --optional-deps --exclude-features 'print_bytes uniquote' --target ${{ matrix.target }} + flags: --feature-powerset --optional-deps --exclude-features 'print_bytes' --target ${{ matrix.target }} steps: - uses: actions/checkout@v1 with: diff --git a/src/common/raw.rs b/src/common/raw.rs index 5096604..070a62c 100644 --- a/src/common/raw.rs +++ b/src/common/raw.rs @@ -25,3 +25,14 @@ pub(crate) fn debug(string: &[u8], f: &mut Formatter<'_>) -> fmt::Result { } Ok(()) } + +#[cfg(feature = "uniquote")] +pub(crate) mod uniquote { + use uniquote::Formatter; + use uniquote::Quote; + use uniquote::Result; + + pub(crate) fn escape(string: &[u8], f: &mut Formatter<'_>) -> Result { + string.escape(f) + } +} diff --git a/src/raw_str.rs b/src/raw_str.rs index d9aa7ad..8166772 100644 --- a/src/raw_str.rs +++ b/src/raw_str.rs @@ -1117,13 +1117,15 @@ mod uniquote { use uniquote::Quote; use uniquote::Result; + use crate::imp::raw; + use super::RawOsStr; use super::RawOsString; impl Quote for RawOsStr { #[inline] fn escape(&self, f: &mut Formatter<'_>) -> Result { - self.0.escape(f) + raw::uniquote::escape(&self.0, f) } } diff --git a/src/wasm32/raw.rs b/src/wasm32/raw.rs index 16f2d80..5b4f933 100644 --- a/src/wasm32/raw.rs +++ b/src/wasm32/raw.rs @@ -26,3 +26,14 @@ pub(crate) fn debug(string: &[u8], _: &mut Formatter<'_>) -> fmt::Result { assert!(string.is_empty()); Ok(()) } + +#[cfg(feature = "uniquote")] +pub(crate) mod uniquote { + use uniquote::Formatter; + use uniquote::Quote; + use uniquote::Result; + + pub(crate) fn escape(string: &[u8], f: &mut Formatter<'_>) -> Result { + string.escape(f) + } +} diff --git a/src/windows/raw.rs b/src/windows/raw.rs index bbf0e91..cb592b3 100644 --- a/src/windows/raw.rs +++ b/src/windows/raw.rs @@ -6,6 +6,10 @@ pub(crate) use crate::util::is_continuation; use super::wtf8; use super::wtf8::CodePoints; +fn encode_wide_unchecked(string: &[u8]) -> impl '_ + Iterator { + wtf8::encode_wide(string).map(|x| x.expect("invalid string")) +} + pub(crate) fn decode_code_point(string: &[u8]) -> u32 { let mut code_points = CodePoints::new(string.iter().copied()); let code_point = code_points @@ -25,8 +29,18 @@ pub(crate) fn starts_with(string: &[u8], prefix: &[u8]) -> bool { } pub(crate) fn debug(string: &[u8], f: &mut Formatter<'_>) -> fmt::Result { - for wchar in wtf8::encode_wide(string) { - write!(f, "\\u{{{:X}}}", wchar.expect("invalid string"))?; + for wchar in encode_wide_unchecked(string) { + write!(f, "\\u{{{:X}}}", wchar)?; } Ok(()) } + +#[cfg(feature = "uniquote")] +pub(crate) mod uniquote { + use uniquote::Formatter; + use uniquote::Result; + + pub(crate) fn escape(string: &[u8], f: &mut Formatter<'_>) -> Result { + f.escape_utf16(super::encode_wide_unchecked(string)) + } +}