#![doc(html_logo_url = "https://raw.githubusercontent.com/V0ldek/rsonpath/main/img/rsonquery-logo.svg")]
#![cfg_attr(
not(debug_assertions),
warn(
missing_docs,
clippy::cargo_common_metadata,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::too_long_first_doc_paragraph
)
)]
#![cfg_attr(not(debug_assertions), warn(rustdoc::missing_crate_level_docs))]
#![cfg_attr(not(test), warn(clippy::panic, clippy::panic_in_result_fn, clippy::unwrap_used))]
#![cfg_attr(
not(debug_assertions),
warn(clippy::print_stderr, clippy::print_stdout, clippy::todo, clippy::dbg_macro)
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
pub mod automaton;
pub mod classification;
mod depth;
pub mod engine;
pub mod error;
pub mod input;
pub mod result;
pub(crate) mod string_pattern;
pub use string_pattern::StringPattern;
cfg_if::cfg_if! {
if #[cfg(target_pointer_width = "32")] {
pub(crate) const BLOCK_SIZE: usize = 32;
pub(crate) type MaskType = u32;
}
else if #[cfg(target_pointer_width = "64")] {
pub(crate) const BLOCK_SIZE: usize = 64;
pub(crate) type MaskType = u64;
}
}
#[cfg(debug_assertions)]
#[allow(unused_macros, reason = "crate-wide debug macros for convenience, may be unused")]
macro_rules! debug {
(target: $target:expr, $($arg:tt)+) => (log::debug!(target: $target, $($arg)+));
($($arg:tt)+) => (log::debug!($($arg)+))
}
#[allow(unused_macros, reason = "crate-wide debug macros for convenience, may be unused")]
macro_rules! block {
($b:expr) => {
crate::debug!(
"{: >24}: {}",
"block",
std::str::from_utf8(
&$b.iter()
.map(|x| if x.is_ascii_whitespace() { b' ' } else { *x })
.collect::<Vec<_>>()
)
.unwrap_or("[INVALID UTF8]")
);
};
}
#[cfg(not(debug_assertions))]
#[allow(unused_macros, reason = "crate-wide debug macros for convenience, may be unused")]
macro_rules! debug {
(target: $target:expr, $($arg:tt)+) => {};
($($arg:tt)+) => {};
}
#[allow(unused_macros, reason = "crate-wide debug macros for convenience, may be unused")]
macro_rules! bin_u64 {
($name:expr, $e:expr) => {
$crate::debug!(
"{: >24}: {:064b} ({})",
$name,
{
let mut res = 0_u64;
for i in 0..64 {
let bit = (($e) & (1 << i)) >> i;
res |= bit << (63 - i);
}
res
},
$e
);
};
}
#[allow(unused_macros, reason = "crate-wide debug macros for convenience, may be unused")]
macro_rules! bin_u32 {
($name:expr, $e:expr) => {
$crate::debug!(
"{: >24}: {:032b} ({})",
$name,
{
let mut res = 0_u32;
for i in 0..32 {
let bit = (($e) & (1 << i)) >> i;
res |= bit << (31 - i);
}
res
},
$e
);
};
}
#[allow(unused_imports, reason = "crate-wide debug macros for convenience, may be unused")]
pub(crate) use bin_u32;
#[allow(unused_imports, reason = "crate-wide debug macros for convenience, may be unused")]
pub(crate) use bin_u64;
#[allow(unused_imports, reason = "crate-wide debug macros for convenience, may be unused")]
pub(crate) use block;
#[allow(unused_imports, reason = "crate-wide debug macros for convenience, may be unused")]
pub(crate) use debug;
pub trait FallibleIterator {
type Item;
type Error: std::error::Error;
fn next(&mut self) -> Result<Option<Self::Item>, Self::Error>;
#[inline]
fn collect<B>(self) -> Result<B, Self::Error>
where
B: FromIterator<Self::Item>,
Self: Sized,
{
let iter = FallibleIntoIter { src: self };
iter.collect()
}
}
struct FallibleIntoIter<F> {
src: F,
}
impl<F: FallibleIterator> Iterator for FallibleIntoIter<F> {
type Item = Result<F::Item, F::Error>;
fn next(&mut self) -> Option<Self::Item> {
match self.src.next() {
Ok(item) => item.map(Ok),
Err(e) => Some(Err(e)),
}
}
}
pub(crate) const JSON_SPACE_BYTE: u8 = b' ';
pub(crate) const JSON_WHITESPACE_BYTES: [u8; 4] = [b' ', b'\t', b'\n', b'\r'];
#[inline(always)]
#[must_use]
pub(crate) fn is_json_whitespace(x: u8) -> bool {
JSON_WHITESPACE_BYTES.contains(&x)
}