#[macro_export]
#[doc(hidden)]
macro_rules! sub {
($a:expr, $b:expr) => {{
debug_assert!($b <= $a);
($a as usize) - ($b as usize)
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! index {
($a:ident[$b:expr]) => {{
unsafe { *$a.as_ptr().add($b) }
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! escape_body {
($i:expr, $start:ident, $fmt:ident, $bytes:ident, $quote:expr) => {{
if $start < $i {
#[allow(unused_unsafe)]
$fmt.write_str(unsafe { std::str::from_utf8_unchecked(&$bytes[$start..$i]) })?;
}
$fmt.write_str($quote)?;
$start = $i + 1;
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! mask_body {
($i:expr, $start:ident, $fmt:ident, $bytes:ident, $quote:expr) => {{
let i = $i;
$crate::escape_body!(i, $start, $fmt, $bytes, $quote);
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! bodies {
($T:ident, $Q:ident, $Q_LEN:ident, $i:expr, $b:expr, $start:ident, $fmt:ident, $bytes:ident, $callback:path) => {
let c = $crate::index!($T[$b as usize]) as usize;
if c < $Q_LEN {
$callback!($i, $start, $fmt, $bytes, $crate::index!($Q[c]));
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! bodies_exact {
($T:ident, $Q:ident, $Q_LEN:ident, $i:expr, $b:expr, $start:ident, $fmt:ident, $bytes:ident, $callback:path) => {
debug_assert_ne!($T[$b as usize] as usize, $Q_LEN as usize);
$callback!(
$i,
$start,
$fmt,
$bytes,
$crate::index!($Q[$crate::index!($T[$b as usize]) as usize])
);
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! bodies_exact_one {
($char:expr, $quote:expr, $_non:expr, $i:expr, $b:expr, $start:ident, $fmt:ident, $bytes:ident, $callback:path) => {
debug_assert_eq!($char, $b);
$callback!($i, $start, $fmt, $bytes, $quote);
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! escape_body_ptr {
($i:expr, $start:ident, $cur:ident, $buf:ident, $src_start:ident, $quote:expr) => {{
if $start < $i {
$crate::write_ptr!($cur, $buf, $src_start.add($start), $i - $start);
}
let quote = $quote;
$crate::write_ptr!(
$cur,
$buf,
(quote.as_bytes() as *const _ as *const u8),
quote.len()
);
$start = $i + 1;
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! mask_body_ptr {
($i:expr, $start:ident, $cur:ident, $buf:ident, $src_start:ident, $quote:expr) => {{
let i = $i;
$crate::escape_body_ptr!(i, $start, $cur, $buf, $src_start, $quote);
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! write_ptr {
($cur:ident, $buf:ident, $src:expr, $len:expr) => {
if $buf.len() < $cur + $len {
return None;
} else {
std::ptr::copy_nonoverlapping($src, ($buf as *mut _ as *mut u8).add($cur), $len);
$cur += $len;
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! bodies_ptr {
($T:ident, $Q:ident, $Q_LEN:ident, $i:expr, $b:expr, $start:ident, $cur:ident, $buf:ident, $src_start:ident, $callback:path) => {
let c = $crate::index!($T[$b as usize]) as usize;
if c < $Q_LEN {
$callback!($i, $start, $cur, $buf, $src_start, $crate::index!($Q[c]));
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! bodies_exact_ptr {
($T:ident, $Q:ident, $Q_LEN:ident, $i:expr, $b:expr, $start:ident, $cur:ident, $buf:ident, $src_start:ident, $callback:path) => {
debug_assert_ne!($T[$b as usize] as usize, $Q_LEN as usize);
$callback!(
$i,
$start,
$cur,
$buf,
$src_start,
$crate::index!($Q[$crate::index!($T[$b as usize]) as usize])
);
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! bodies_exact_one_ptr {
($char:expr, $quote:expr, $_non:expr, $i:expr, $b:expr, $start:ident, $cur:ident, $buf:ident, $src_start:ident, $callback:path) => {
debug_assert_eq!($char, $b);
$callback!($i, $start, $cur, $buf, $src_start, $quote);
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! escape_body_bytes {
($i:expr, $start:ident, $bytes:ident, $buf:ident, $quote:expr) => {{
if $start < $i {
$crate::write_bytes!(&$bytes[$start..$i], $buf);
}
$crate::write_bytes!($quote.as_bytes(), $buf);
$start = $i + 1;
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! mask_body_bytes {
($i:expr, $start:ident, $bytes:ident, $buf:ident, $quote:expr) => {{
let i = $i;
$crate::escape_body_bytes!(i, $start, $bytes, $buf, $quote);
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! write_bytes {
($bytes:expr, $buf:ident) => {
$buf.extend_from_slice($bytes);
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! bodies_bytes {
($T:ident, $Q:ident, $Q_LEN:ident, $i:expr, $b:expr, $start:ident, $bytes:ident, $buf:ident, $callback:path) => {
let c = $crate::index!($T[$b as usize]) as usize;
if c < $Q_LEN {
$callback!($i, $start, $bytes, $buf, $crate::index!($Q[c]));
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! bodies_exact_bytes {
($T:ident, $Q:ident, $Q_LEN:ident, $i:expr, $b:expr, $start:ident, $bytes:ident, $buf:ident, $callback:path) => {
debug_assert_ne!($T[$b as usize] as usize, $Q_LEN as usize);
$callback!(
$i,
$start,
$bytes,
$buf,
$crate::index!($Q[$crate::index!($T[$b as usize]) as usize])
);
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! bodies_exact_one_bytes {
($char:expr, $quote:expr, $_non:expr, $i:expr, $b:expr, $start:ident, $bytes:ident, $buf:ident, $callback:path) => {
debug_assert_eq!($char, $b);
$callback!($i, $start, $bytes, $buf, $quote);
};
}