| { | ||
| "git": { | ||
| "sha1": "e223ec63cab2de544625b8946e372e6d50ab53d2" | ||
| "sha1": "41f8bdb9ec08912a38a1b2da704fcf0a19fcea45" | ||
| }, | ||
| "path_in_vcs": "" | ||
| } |
+1
-1
@@ -7,3 +7,3 @@ # This file is automatically @generated by Cargo. | ||
| name = "bstr" | ||
| version = "1.10.0" | ||
| version = "1.11.0" | ||
| dependencies = [ | ||
@@ -10,0 +10,0 @@ "memchr", |
+3
-2
@@ -14,5 +14,5 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| edition = "2021" | ||
| rust-version = "1.65" | ||
| rust-version = "1.73" | ||
| name = "bstr" | ||
| version = "1.10.0" | ||
| version = "1.11.0" | ||
| authors = ["Andrew Gallant <jamslam@gmail.com>"] | ||
@@ -24,2 +24,3 @@ build = false | ||
| ] | ||
| autolib = false | ||
| autobins = false | ||
@@ -26,0 +27,0 @@ autoexamples = false |
+1
-1
@@ -149,3 +149,3 @@ bstr | ||
| This crate's minimum supported `rustc` version (MSRV) is `1.65`. | ||
| This crate's minimum supported `rustc` version (MSRV) is `1.73`. | ||
@@ -152,0 +152,0 @@ In general, this crate will be conservative with respect to the minimum |
+5
-6
@@ -27,2 +27,4 @@ // The following ~400 lines of code exists for exactly one purpose, which is | ||
| #[cfg(any(test, miri, not(target_arch = "x86_64")))] | ||
| const ALIGN_MASK: usize = core::mem::align_of::<usize>() - 1; | ||
| #[cfg(any(test, miri, not(target_arch = "x86_64")))] | ||
| const FALLBACK_LOOP_SIZE: usize = 2 * USIZE_BYTES; | ||
@@ -57,3 +59,2 @@ | ||
| fn first_non_ascii_byte_fallback(slice: &[u8]) -> usize { | ||
| let align = USIZE_BYTES - 1; | ||
| let start_ptr = slice.as_ptr(); | ||
@@ -74,3 +75,3 @@ let end_ptr = slice[slice.len()..].as_ptr(); | ||
| ptr = ptr_add(ptr, USIZE_BYTES - (start_ptr as usize & align)); | ||
| ptr = ptr_add(ptr, USIZE_BYTES - (start_ptr as usize & ALIGN_MASK)); | ||
| debug_assert!(ptr > start_ptr); | ||
@@ -239,4 +240,3 @@ debug_assert!(ptr_sub(end_ptr, USIZE_BYTES) >= start_ptr); | ||
| unsafe fn ptr_add(ptr: *const u8, amt: usize) -> *const u8 { | ||
| debug_assert!(amt < ::core::isize::MAX as usize); | ||
| ptr.offset(amt as isize) | ||
| ptr.add(amt) | ||
| } | ||
@@ -246,4 +246,3 @@ | ||
| unsafe fn ptr_sub(ptr: *const u8, amt: usize) -> *const u8 { | ||
| debug_assert!(amt < ::core::isize::MAX as usize); | ||
| ptr.offset((amt as isize).wrapping_neg()) | ||
| ptr.sub(amt) | ||
| } | ||
@@ -250,0 +249,0 @@ |
+3
-6
@@ -1,3 +0,1 @@ | ||
| use core::mem; | ||
| #[cfg(feature = "alloc")] | ||
@@ -32,3 +30,2 @@ use alloc::boxed::Box; | ||
| /// replacement codepoint, which looks like this: �. | ||
| #[derive(Hash)] | ||
| #[repr(transparent)] | ||
@@ -64,3 +61,3 @@ pub struct BStr { | ||
| #[inline] | ||
| pub fn new<'a, B: ?Sized + AsRef<[u8]>>(bytes: &'a B) -> &'a BStr { | ||
| pub fn new<B: ?Sized + AsRef<[u8]>>(bytes: &B) -> &BStr { | ||
| BStr::from_bytes(bytes.as_ref()) | ||
@@ -78,3 +75,3 @@ } | ||
| pub(crate) fn from_bytes(slice: &[u8]) -> &BStr { | ||
| unsafe { mem::transmute(slice) } | ||
| unsafe { &*(slice as *const [u8] as *const BStr) } | ||
| } | ||
@@ -84,3 +81,3 @@ | ||
| pub(crate) fn from_bytes_mut(slice: &mut [u8]) -> &mut BStr { | ||
| unsafe { mem::transmute(slice) } | ||
| unsafe { &mut *(slice as *mut [u8] as *mut BStr) } | ||
| } | ||
@@ -87,0 +84,0 @@ |
+1
-1
@@ -41,3 +41,3 @@ use alloc::vec::Vec; | ||
| /// region of memory containing the bytes, a length and a capacity. | ||
| #[derive(Clone, Hash)] | ||
| #[derive(Clone)] | ||
| pub struct BString { | ||
@@ -44,0 +44,0 @@ bytes: Vec<u8>, |
@@ -17,3 +17,3 @@ use memchr::{memchr, memchr2, memchr3, memrchr, memrchr2, memrchr3}; | ||
| match byteset.len() { | ||
| 0 => return None, | ||
| 0 => None, | ||
| 1 => memchr(byteset[0], haystack), | ||
@@ -32,3 +32,3 @@ 2 => memchr2(byteset[0], byteset[1], haystack), | ||
| match byteset.len() { | ||
| 0 => return None, | ||
| 0 => None, | ||
| 1 => memrchr(byteset[0], haystack), | ||
@@ -50,3 +50,3 @@ 2 => memrchr2(byteset[0], byteset[1], haystack), | ||
| match byteset.len() { | ||
| 0 => return Some(0), | ||
| 0 => Some(0), | ||
| 1 => scalar::inv_memchr(byteset[0], haystack), | ||
@@ -71,3 +71,3 @@ 2 => scalar::forward_search_bytes(haystack, |b| { | ||
| match byteset.len() { | ||
| 0 => return Some(haystack.len() - 1), | ||
| 0 => Some(haystack.len() - 1), | ||
| 1 => scalar::inv_memrchr(byteset[0], haystack), | ||
@@ -74,0 +74,0 @@ 2 => scalar::reverse_search_bytes(haystack, |b| { |
@@ -8,2 +8,3 @@ // This is adapted from `fallback.rs` from rust-memchr. It's modified to return | ||
| const USIZE_BYTES: usize = core::mem::size_of::<usize>(); | ||
| const ALIGN_MASK: usize = core::mem::align_of::<usize>() - 1; | ||
@@ -26,3 +27,2 @@ // The number of bytes to loop at in one iteration of memchr/memrchr. | ||
| let loop_size = cmp::min(LOOP_SIZE, haystack.len()); | ||
| let align = USIZE_BYTES - 1; | ||
| let start_ptr = haystack.as_ptr(); | ||
@@ -43,3 +43,3 @@ | ||
| ptr = ptr.add(USIZE_BYTES - (start_ptr as usize & align)); | ||
| ptr = ptr.add(USIZE_BYTES - (start_ptr as usize & ALIGN_MASK)); | ||
| debug_assert!(ptr > start_ptr); | ||
@@ -68,3 +68,2 @@ debug_assert!(end_ptr.sub(USIZE_BYTES) >= start_ptr); | ||
| let loop_size = cmp::min(LOOP_SIZE, haystack.len()); | ||
| let align = USIZE_BYTES - 1; | ||
| let start_ptr = haystack.as_ptr(); | ||
@@ -85,3 +84,3 @@ | ||
| ptr = ptr.sub(end_ptr as usize & align); | ||
| ptr = ptr.sub(end_ptr as usize & ALIGN_MASK); | ||
| debug_assert!(start_ptr <= ptr && ptr <= end_ptr); | ||
@@ -88,0 +87,0 @@ while loop_size == LOOP_SIZE && ptr >= start_ptr.add(loop_size) { |
@@ -15,3 +15,3 @@ /// An iterator of `char` values that represent an escaping of arbitrary bytes. | ||
| impl<'a> EscapeBytes<'a> { | ||
| pub(crate) fn new(bytes: &'a [u8]) -> EscapeBytes { | ||
| pub(crate) fn new(bytes: &'a [u8]) -> EscapeBytes<'a> { | ||
| EscapeBytes { remaining: bytes, state: EscapeState::Start } | ||
@@ -18,0 +18,0 @@ } |
+6
-6
@@ -188,3 +188,3 @@ use core::{fmt, iter, ops, ptr}; | ||
| Ok(Vec::from(os_str.into_vec())) | ||
| Ok(os_str.into_vec()) | ||
| } | ||
@@ -224,6 +224,6 @@ | ||
| #[cfg(feature = "std")] | ||
| fn from_os_str_lossy<'a>(os_str: &'a OsStr) -> Cow<'a, [u8]> { | ||
| fn from_os_str_lossy(os_str: &OsStr) -> Cow<'_, [u8]> { | ||
| #[cfg(unix)] | ||
| #[inline] | ||
| fn imp<'a>(os_str: &'a OsStr) -> Cow<'a, [u8]> { | ||
| fn imp(os_str: &OsStr) -> Cow<'_, [u8]> { | ||
| use std::os::unix::ffi::OsStrExt; | ||
@@ -236,3 +236,3 @@ | ||
| #[inline] | ||
| fn imp<'a>(os_str: &'a OsStr) -> Cow<'a, [u8]> { | ||
| fn imp(os_str: &OsStr) -> Cow<'_, [u8]> { | ||
| match os_str.to_string_lossy() { | ||
@@ -295,3 +295,3 @@ Cow::Borrowed(x) => Cow::Borrowed(x.as_bytes()), | ||
| #[cfg(feature = "std")] | ||
| fn from_path_lossy<'a>(path: &'a Path) -> Cow<'a, [u8]> { | ||
| fn from_path_lossy(path: &Path) -> Cow<'_, [u8]> { | ||
| Vec::from_os_str_lossy(path.as_os_str()) | ||
@@ -965,3 +965,3 @@ } | ||
| { | ||
| self.as_vec_mut().splice(range, replace_with.as_ref().iter().cloned()); | ||
| self.as_vec_mut().splice(range, replace_with.as_ref().iter().copied()); | ||
| } | ||
@@ -968,0 +968,0 @@ |
+100
-7
@@ -21,2 +21,22 @@ macro_rules! impl_partial_eq { | ||
| macro_rules! impl_partial_eq_n { | ||
| ($lhs:ty, $rhs:ty) => { | ||
| impl<'a, 'b, const N: usize> PartialEq<$rhs> for $lhs { | ||
| #[inline] | ||
| fn eq(&self, other: &$rhs) -> bool { | ||
| let other: &[u8] = other.as_ref(); | ||
| PartialEq::eq(self.as_bytes(), other) | ||
| } | ||
| } | ||
| impl<'a, 'b, const N: usize> PartialEq<$lhs> for $rhs { | ||
| #[inline] | ||
| fn eq(&self, other: &$lhs) -> bool { | ||
| let this: &[u8] = self.as_ref(); | ||
| PartialEq::eq(this, other.as_bytes()) | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| #[cfg(feature = "alloc")] | ||
@@ -63,5 +83,25 @@ macro_rules! impl_partial_eq_cow { | ||
| macro_rules! impl_partial_ord_n { | ||
| ($lhs:ty, $rhs:ty) => { | ||
| impl<'a, 'b, const N: usize> PartialOrd<$rhs> for $lhs { | ||
| #[inline] | ||
| fn partial_cmp(&self, other: &$rhs) -> Option<Ordering> { | ||
| let other: &[u8] = other.as_ref(); | ||
| PartialOrd::partial_cmp(self.as_bytes(), other) | ||
| } | ||
| } | ||
| impl<'a, 'b, const N: usize> PartialOrd<$lhs> for $rhs { | ||
| #[inline] | ||
| fn partial_cmp(&self, other: &$lhs) -> Option<Ordering> { | ||
| let this: &[u8] = self.as_ref(); | ||
| PartialOrd::partial_cmp(this, other.as_bytes()) | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| #[cfg(feature = "alloc")] | ||
| mod bstring { | ||
| use core::{cmp::Ordering, fmt, ops, str::FromStr}; | ||
| use core::{cmp::Ordering, fmt, hash, ops, str::FromStr}; | ||
@@ -361,3 +401,3 @@ use alloc::{ | ||
| fn eq(&self, other: &BString) -> bool { | ||
| &self[..] == &other[..] | ||
| self[..] == other[..] | ||
| } | ||
@@ -374,3 +414,12 @@ } | ||
| impl_partial_eq!(BString, &'a BStr); | ||
| impl_partial_eq_n!(BString, [u8; N]); | ||
| impl_partial_eq_n!(BString, &'a [u8; N]); | ||
| impl hash::Hash for BString { | ||
| #[inline] | ||
| fn hash<H: hash::Hasher>(&self, state: &mut H) { | ||
| self.as_bytes().hash(state); | ||
| } | ||
| } | ||
| impl PartialOrd for BString { | ||
@@ -398,2 +447,4 @@ #[inline] | ||
| impl_partial_ord!(BString, &'a BStr); | ||
| impl_partial_ord_n!(BString, [u8; N]); | ||
| impl_partial_ord_n!(BString, &'a [u8; N]); | ||
| } | ||
@@ -405,3 +456,3 @@ | ||
| cmp::Ordering, | ||
| fmt, ops, | ||
| fmt, hash, ops, | ||
| }; | ||
@@ -489,3 +540,3 @@ | ||
| for &b in self[s..e].as_bytes() { | ||
| write!(f, r"\x{:02X}", b)?; | ||
| write!(f, "\\x{:02x}", b)?; | ||
| } | ||
@@ -502,5 +553,8 @@ } | ||
| } | ||
| '\n' | '\r' | '\t' | _ => { | ||
| '\n' | '\r' | '\t' => { | ||
| write!(f, "{}", ch.escape_debug())?; | ||
| } | ||
| _ => { | ||
| write!(f, "{}", ch.escape_debug())?; | ||
| } | ||
| } | ||
@@ -822,2 +876,4 @@ } | ||
| impl_partial_eq!(BStr, &'a str); | ||
| impl_partial_eq_n!(BStr, [u8; N]); | ||
| impl_partial_eq_n!(BStr, &'a [u8; N]); | ||
@@ -839,2 +895,9 @@ #[cfg(feature = "alloc")] | ||
| impl hash::Hash for BStr { | ||
| #[inline] | ||
| fn hash<H: hash::Hasher>(&self, state: &mut H) { | ||
| self.as_bytes().hash(state); | ||
| } | ||
| } | ||
| impl PartialOrd for BStr { | ||
@@ -858,2 +921,4 @@ #[inline] | ||
| impl_partial_ord!(BStr, &'a str); | ||
| impl_partial_ord_n!(BStr, [u8; N]); | ||
| impl_partial_ord_n!(BStr, &'a [u8; N]); | ||
@@ -1242,7 +1307,15 @@ #[cfg(feature = "alloc")] | ||
| assert_eq!( | ||
| b"\"\\xFF\xEF\xBF\xBD\\xFF\"".as_bstr(), | ||
| b"\"\\xff\xef\xbf\xbd\\xff\"".as_bstr(), | ||
| // Before fixing #72, the output here would be: | ||
| // \\xFF\\xEF\\xBF\\xBD\\xFF | ||
| B(&format!("{:?}", b"\xFF\xEF\xBF\xBD\xFF".as_bstr())).as_bstr(), | ||
| B(&format!("{:?}", b"\xff\xef\xbf\xbd\xff".as_bstr())).as_bstr(), | ||
| ); | ||
| // Tests that all ASCII control characters are in lower case. | ||
| assert_eq!( | ||
| b"\"\\xed\\xa0\\x80Aa\\x7f\\x0b\"".as_bstr(), | ||
| // Before fixing #188, the output here would be: | ||
| // \\xED\\xA0\\x80Aa\\x7f\\x0b | ||
| B(&format!("{:?}", b"\xed\xa0\x80Aa\x7f\x0b".as_bstr())).as_bstr(), | ||
| ) | ||
| } | ||
@@ -1266,1 +1339,21 @@ | ||
| } | ||
| #[test] | ||
| #[cfg(feature = "alloc")] | ||
| fn test_eq_ord() { | ||
| use core::cmp::Ordering; | ||
| use crate::{BStr, BString}; | ||
| let b = BStr::new("hello"); | ||
| assert_eq!(b, b"hello"); | ||
| assert_ne!(b, b"world"); | ||
| assert_eq!(b.partial_cmp(b"hello"), Some(Ordering::Equal)); | ||
| assert_eq!(b.partial_cmp(b"world"), Some(Ordering::Less)); | ||
| let b = BString::from("hello"); | ||
| assert_eq!(b, b"hello"); | ||
| assert_ne!(b, b"world"); | ||
| assert_eq!(b.partial_cmp(b"hello"), Some(Ordering::Equal)); | ||
| assert_eq!(b.partial_cmp(b"world"), Some(Ordering::Less)); | ||
| } |
+4
-4
@@ -145,3 +145,3 @@ /*! | ||
| self.for_byte_line_with_terminator(|line| { | ||
| for_each_line(&trim_line_slice(&line)) | ||
| for_each_line(trim_line_slice(line)) | ||
| }) | ||
@@ -197,3 +197,3 @@ } | ||
| self.for_byte_record_with_terminator(terminator, |chunk| { | ||
| for_each_record(&trim_record_slice(&chunk, terminator)) | ||
| for_each_record(trim_record_slice(chunk, terminator)) | ||
| }) | ||
@@ -314,3 +314,3 @@ } | ||
| consumed += record.len(); | ||
| match for_each_record(&record) { | ||
| match for_each_record(record) { | ||
| Ok(false) => break 'outer, | ||
@@ -328,3 +328,3 @@ Err(err) => { | ||
| // contains no remaining terminators. | ||
| bytes.extend_from_slice(&buf); | ||
| bytes.extend_from_slice(buf); | ||
| consumed += buf.len(); | ||
@@ -331,0 +331,0 @@ } |
@@ -222,3 +222,3 @@ use regex_automata::{dfa::Automaton, Anchored, Input}; | ||
| } else { | ||
| const INVALID: &'static str = "\u{FFFD}"; | ||
| const INVALID: &str = "\u{FFFD}"; | ||
| // No match on non-empty bytes implies we found invalid UTF-8. | ||
@@ -242,3 +242,3 @@ let (_, size) = utf8::decode_lossy(bs); | ||
| } else { | ||
| const INVALID: &'static str = "\u{FFFD}"; | ||
| const INVALID: &str = "\u{FFFD}"; | ||
| // No match on non-empty bytes implies we found invalid UTF-8. | ||
@@ -385,4 +385,3 @@ let (_, size) = utf8::decode_last_lossy(bs); | ||
| fn ucdtests() -> Vec<GraphemeClusterBreakTest> { | ||
| const TESTDATA: &'static str = | ||
| include_str!("data/GraphemeBreakTest.txt"); | ||
| const TESTDATA: &str = include_str!("data/GraphemeBreakTest.txt"); | ||
@@ -389,0 +388,0 @@ let mut tests = vec![]; |
@@ -156,3 +156,3 @@ use regex_automata::{dfa::Automaton, Anchored, Input}; | ||
| } else { | ||
| const INVALID: &'static str = "\u{FFFD}"; | ||
| const INVALID: &str = "\u{FFFD}"; | ||
| // No match on non-empty bytes implies we found invalid UTF-8. | ||
@@ -218,4 +218,3 @@ let (_, size) = utf8::decode_lossy(bs); | ||
| fn ucdtests() -> Vec<SentenceBreakTest> { | ||
| const TESTDATA: &'static str = | ||
| include_str!("data/SentenceBreakTest.txt"); | ||
| const TESTDATA: &str = include_str!("data/SentenceBreakTest.txt"); | ||
@@ -222,0 +221,0 @@ let mut tests = vec![]; |
@@ -69,3 +69,3 @@ use regex_automata::{dfa::Automaton, Anchored, Input}; | ||
| fn next(&mut self) -> Option<&'a str> { | ||
| while let Some(word) = self.0.next() { | ||
| for word in self.0.by_ref() { | ||
| let input = | ||
@@ -148,3 +148,3 @@ Input::new(word).anchored(Anchored::Yes).earliest(true); | ||
| fn next(&mut self) -> Option<(usize, usize, &'a str)> { | ||
| while let Some((start, end, word)) = self.0.next() { | ||
| for (start, end, word) in self.0.by_ref() { | ||
| let input = | ||
@@ -324,3 +324,3 @@ Input::new(word).anchored(Anchored::Yes).earliest(true); | ||
| } else { | ||
| const INVALID: &'static str = "\u{FFFD}"; | ||
| const INVALID: &str = "\u{FFFD}"; | ||
| // No match on non-empty bytes implies we found invalid UTF-8. | ||
@@ -420,3 +420,3 @@ let (_, size) = utf8::decode_lossy(bs); | ||
| fn ucdtests() -> Vec<WordBreakTest> { | ||
| const TESTDATA: &'static str = include_str!("data/WordBreakTest.txt"); | ||
| const TESTDATA: &str = include_str!("data/WordBreakTest.txt"); | ||
@@ -423,0 +423,0 @@ let mut tests = vec![]; |
+7
-6
@@ -40,3 +40,3 @@ use core::{char, cmp, fmt, str}; | ||
| /// equivalence classes. | ||
| #[cfg_attr(rustfmt, rustfmt::skip)] | ||
| #[rustfmt::skip] | ||
| const CLASSES: [u8; 256] = [ | ||
@@ -55,4 +55,4 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| /// machine. | ||
| #[cfg_attr(rustfmt, rustfmt::skip)] | ||
| const STATES_FORWARD: &'static [u8] = &[ | ||
| #[rustfmt::skip] | ||
| const STATES_FORWARD: &[u8] = &[ | ||
| 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
@@ -610,3 +610,3 @@ 12, 0, 24, 36, 60, 96, 84, 0, 0, 0, 48, 72, | ||
| let slice = slice.as_ref(); | ||
| match slice.get(0) { | ||
| match slice.first() { | ||
| None => return (None, 0), | ||
@@ -819,6 +819,7 @@ Some(&b) if b <= 0x7F => return (Some(b as char), 1), | ||
| let class = CLASSES[b as usize]; | ||
| let b = u32::from(b); | ||
| if *state == ACCEPT { | ||
| *cp = (0xFF >> class) & (b as u32); | ||
| *cp = (0xFF >> class) & b; | ||
| } else { | ||
| *cp = (b as u32 & 0b111111) | (*cp << 6); | ||
| *cp = (b & 0b0011_1111) | (*cp << 6); | ||
| } | ||
@@ -825,0 +826,0 @@ *state = STATES_FORWARD[*state + class as usize] as usize; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display