Unify two places checking if text was preceded by whitespace.
This commit is contained in:
@@ -135,16 +135,25 @@ pub fn start_of_line<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn preceded_by_whitespace(
|
||||
allow_start_of_file: bool,
|
||||
) -> impl for<'s> Fn(OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
||||
move |input| _preceded_by_whitespace(allow_start_of_file, input)
|
||||
}
|
||||
|
||||
/// Check that we are at the start of a line
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn preceded_by_whitespace<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
||||
fn _preceded_by_whitespace<'s>(
|
||||
allow_start_of_file: bool,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, ()> {
|
||||
let preceding_character = input.get_preceding_character();
|
||||
if !preceding_character
|
||||
.map(|c| c.is_whitespace() || c == '\u{200B}') // 200B = Zero-width space
|
||||
.unwrap_or(false)
|
||||
.unwrap_or(allow_start_of_file)
|
||||
{
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not preceded by whitespace.".into(),
|
||||
"Must be preceded by a non-whitespace character.".into(),
|
||||
))));
|
||||
}
|
||||
Ok((input, ()))
|
||||
|
||||
Reference in New Issue
Block a user