Use new features of "uniquote"

This commit is contained in:
dylni
2021-09-06 14:20:38 -04:00
parent 9edfece40b
commit beaf7685cc
5 changed files with 42 additions and 4 deletions
+1 -1
View File
@@ -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:
+11
View File
@@ -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)
}
}
+3 -1
View File
@@ -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)
}
}
+11
View File
@@ -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)
}
}
+16 -2
View File
@@ -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<Item = u16> {
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))
}
}