summaryrefslogtreecommitdiffstats
path: root/vendor/gix-object/src/commit/message/decode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix-object/src/commit/message/decode.rs')
-rw-r--r--vendor/gix-object/src/commit/message/decode.rs70
1 files changed, 31 insertions, 39 deletions
diff --git a/vendor/gix-object/src/commit/message/decode.rs b/vendor/gix-object/src/commit/message/decode.rs
index 6224909bd..8038009b4 100644
--- a/vendor/gix-object/src/commit/message/decode.rs
+++ b/vendor/gix-object/src/commit/message/decode.rs
@@ -1,57 +1,49 @@
-use nom::{
- branch::alt,
- bytes::complete::{tag, take_till1},
- combinator::all_consuming,
- error::ParseError,
- sequence::pair,
- IResult,
+use winnow::{
+ combinator::{alt, eof, preceded, rest, terminated},
+ error::ParserError,
+ prelude::*,
+ stream::{Offset, Stream},
+ token::take_till1,
};
use crate::bstr::{BStr, ByteSlice};
-pub(crate) fn newline<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a [u8], E> {
- alt((tag(b"\r\n"), tag(b"\n")))(i)
+pub(crate) fn newline<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> PResult<&'a [u8], E> {
+ alt((b"\n", b"\r\n")).parse_next(i)
}
-fn subject_and_body<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], (&'a BStr, Option<&'a BStr>), E> {
- let mut c = i;
- let mut consumed_bytes = 0;
- while !c.is_empty() {
- c = match take_till1::<_, _, E>(|c| c == b'\n' || c == b'\r')(c) {
- Ok((i1, segment)) => {
- consumed_bytes += segment.len();
- match pair::<_, _, _, E, _, _>(newline, newline)(i1) {
- Ok((body, _)) => {
- return Ok((
- &[],
- (
- i[0usize..consumed_bytes].as_bstr(),
- (!body.is_empty()).then(|| body.as_bstr()),
- ),
- ));
+fn subject_and_body<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> PResult<(&'a BStr, Option<&'a BStr>), E> {
+ let start_i = *i;
+ let start = i.checkpoint();
+ while !i.is_empty() {
+ match take_till1::<_, _, E>(|c| c == b'\n' || c == b'\r').parse_next(i) {
+ Ok(_) => {
+ let consumed_bytes = i.offset_from(&start);
+ match preceded((newline::<E>, newline::<E>), rest).parse_next(i) {
+ Ok(body) => {
+ let body = (!body.is_empty()).then(|| body.as_bstr());
+ return Ok((start_i[0usize..consumed_bytes].as_bstr(), body));
}
- Err(_) => match i1.get(1..) {
- Some(next) => {
- consumed_bytes += 1;
- next
- }
+ Err(_) => match i.next_token() {
+ Some(_) => {}
None => break,
},
}
}
- Err(_) => match c.get(1..) {
- Some(next) => {
- consumed_bytes += 1;
- next
- }
+ Err(_) => match i.next_token() {
+ Some(_) => {}
None => break,
},
- };
+ }
}
- Ok((&[], (i.as_bstr(), None)))
+
+ i.reset(start);
+ rest.map(|r: &[u8]| (r.as_bstr(), None)).parse_next(i)
}
/// Returns title and body, without separator
-pub fn message(input: &[u8]) -> (&BStr, Option<&BStr>) {
- all_consuming(subject_and_body::<()>)(input).expect("cannot fail").1
+pub fn message(mut input: &[u8]) -> (&BStr, Option<&BStr>) {
+ terminated(subject_and_body::<()>, eof)
+ .parse_next(&mut input)
+ .expect("cannot fail")
}