diff --git a/src/error.rs b/src/error.rs index 7218493..78cdfc1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use ::core::fmt; -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq)] pub enum AtoiSimdError<'a> { Empty, Size(usize, &'a [u8]), diff --git a/src/linker/mod.rs b/src/linker/mod.rs index f29f9f6..e96e26d 100644 --- a/src/linker/mod.rs +++ b/src/linker/mod.rs @@ -73,7 +73,7 @@ pub trait Parser>: Sized { if *s.first().ok_or(AtoiSimdError::Empty)? == b'+' { i = 1; } - while s.len() > i { + while i + 1 < s.len() { if *s.get_safe_unchecked(i) != b'0' { break; } @@ -120,7 +120,7 @@ fn atoi_simd_parse_skipped_signed + ParserNeg>( } _ => {} }; - while s.len() > i { + while i + 1 < s.len() { if *s.get_safe_unchecked(i) != b'0' { break; } diff --git a/src/test.rs b/src/test.rs index e387bb3..1a470ba 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1102,4 +1102,82 @@ fn test_parse_skipped() { let tmp = parse_skipped::(b"-000000000000000000000000012345678901234567890").unwrap(); assert_eq!(tmp, -12345678901234567890_i128); + + // Zeroes. + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"-0"), Ok(0)); + assert_eq!(parse_skipped::(b"-0000000000000000000000000000"), Ok(0)); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!(parse_skipped::(b"+0000000000000000000000000000"), Ok(0)); + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!(parse_skipped::(b"+0000000000000000000000000000"), Ok(0)); + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"-0"), Ok(0)); + assert_eq!( + parse_skipped::(b"-0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!( + parse_skipped::(b"+0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!( + parse_skipped::(b"+0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"-0"), Ok(0)); + assert_eq!( + parse_skipped::(b"-0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!( + parse_skipped::(b"+0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!( + parse_skipped::(b"+0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"-0"), Ok(0)); + assert_eq!( + parse_skipped::(b"-0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!( + parse_skipped::(b"+0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!( + parse_skipped::(b"+0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"-0"), Ok(0)); + assert_eq!( + parse_skipped::(b"-0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!( + parse_skipped::(b"+0000000000000000000000000000"), + Ok(0) + ); + assert_eq!(parse_skipped::(b"0"), Ok(0)); + assert_eq!(parse_skipped::(b"+0"), Ok(0)); + assert_eq!( + parse_skipped::(b"+0000000000000000000000000000"), + Ok(0) + ); }