-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ extract trim-related functions to its own module
- Loading branch information
1 parent
cbf8d09
commit ba6f213
Showing
5 changed files
with
45 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod comparer; | ||
mod utils; | ||
|
||
pub use comparer::{default_comparer::DefaultComparer, CompareResult, Comparer}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod trim; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod slice; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#![allow(dead_code)] | ||
|
||
#[inline] | ||
pub(crate) const fn trim_ascii_start(input: &[u8]) -> &[u8] { | ||
let mut bytes = input; | ||
// Note: A pattern matching based approach (instead of indexing) allows | ||
// making the function const. | ||
while let [first, rest @ ..] = bytes { | ||
if first.is_ascii_whitespace() { | ||
bytes = rest; | ||
} else { | ||
break; | ||
} | ||
} | ||
bytes | ||
} | ||
|
||
#[inline] | ||
pub(crate) const fn trim_ascii_end(input: &[u8]) -> &[u8] { | ||
let mut bytes = input; | ||
// Note: A pattern matching based approach (instead of indexing) allows | ||
// making the function const. | ||
while let [rest @ .., last] = bytes { | ||
if last.is_ascii_whitespace() { | ||
bytes = rest; | ||
} else { | ||
break; | ||
} | ||
} | ||
bytes | ||
} | ||
|
||
#[inline] | ||
pub(crate) const fn trim_ascii(input: &[u8]) -> &[u8] { | ||
trim_ascii_end(trim_ascii_start(input)) | ||
} |