Update get_consumed to use the new wrapped input type.
This commit is contained in:
@@ -49,26 +49,9 @@ pub fn immediate_in_section<'r, 's, 'x>(context: Context<'r, 's>, section_name:
|
||||
false
|
||||
}
|
||||
|
||||
/// Check if the child string slice is a slice of the parent string slice.
|
||||
fn is_slice_of(parent: &str, child: &str) -> bool {
|
||||
let parent_start = parent.as_ptr() as usize;
|
||||
let parent_end = parent_start + parent.len();
|
||||
let child_start = child.as_ptr() as usize;
|
||||
let child_end = child_start + child.len();
|
||||
child_start >= parent_start && child_end <= parent_end
|
||||
}
|
||||
|
||||
/// Get a slice of the string that was consumed in a parser using the original input to the parser and the remaining input after the parser.
|
||||
pub fn get_consumed<'s>(input: OrgSource<'s>, remaining: OrgSource<'s>) -> OrgSource<'s> {
|
||||
// TODO: This should be replaced with new logic now that we are wrapping the input type.
|
||||
let input = Into::<&str>::into(&input);
|
||||
let remaining = Into::<&str>::into(&remaining);
|
||||
assert!(is_slice_of(input, remaining));
|
||||
let source = {
|
||||
let offset = remaining.as_ptr() as usize - input.as_ptr() as usize;
|
||||
&input[..offset]
|
||||
};
|
||||
source.into()
|
||||
input.get_until(remaining)
|
||||
}
|
||||
|
||||
/// A line containing only whitespace and then a line break
|
||||
|
||||
Reference in New Issue
Block a user