pub(crate) mod error;
pub(crate) mod tracks;
use nom::bytes::complete::take_while_m_n;
use nom::{AsBytes, InputIter, InputLength, InputTake, Offset, Slice};
use std::ops::{RangeFrom, RangeTo};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum DebugWidth {
Short,
Medium,
Long,
}
impl From<Option<usize>> for DebugWidth {
fn from(value: Option<usize>) -> Self {
match value {
None | Some(0) => DebugWidth::Short,
Some(1) => DebugWidth::Medium,
Some(2) => DebugWidth::Long,
_ => DebugWidth::Short,
}
}
}
pub(crate) fn restrict_str<T: AsBytes + Copy>(w: DebugWidth, text: T) -> T
where
T: Offset
+ InputTake
+ InputIter
+ InputLength
+ Slice<RangeFrom<usize>>
+ Slice<RangeTo<usize>>,
{
match w {
DebugWidth::Short => restrict_str_n(20, text),
DebugWidth::Medium => restrict_str_n(40, text),
DebugWidth::Long => restrict_str_n(60, text),
}
}
pub(crate) fn restrict_str_n<T: AsBytes + Copy>(max_len: usize, text: T) -> T
where
T: Offset
+ InputTake
+ InputIter
+ InputLength
+ Slice<RangeFrom<usize>>
+ Slice<RangeTo<usize>>,
{
match take_while_m_n::<_, _, nom::error::Error<T>>(0, max_len, |_c| true)(text) {
Ok((_, v)) => v,
Err(_) => text,
}
}
pub(crate) fn restrict<I>(w: DebugWidth, span: I) -> I
where
I: Copy,
I: Offset
+ InputTake
+ InputIter
+ InputLength
+ Slice<RangeFrom<usize>>
+ Slice<RangeTo<usize>>,
{
match w {
DebugWidth::Short => restrict_n(20, span),
DebugWidth::Medium => restrict_n(40, span),
DebugWidth::Long => restrict_n(60, span),
}
}
pub(crate) fn restrict_n<I>(max_len: usize, span: I) -> I
where
I: Copy,
I: Offset
+ InputTake
+ InputIter
+ InputLength
+ Slice<RangeFrom<usize>>
+ Slice<RangeTo<usize>>,
{
match take_while_m_n::<_, _, nom::error::Error<I>>(0, max_len, |_c| true)(span) {
Ok((_, v)) => v,
Err(_) => span,
}
}