-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from epage/norm
fix(snap)!: Centralize logic into normalization mod
- Loading branch information
Showing
6 changed files
with
47 additions
and
42 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
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,33 @@ | ||
mod substitutions; | ||
|
||
#[cfg(feature = "regex")] | ||
pub use regex::Regex; | ||
pub use substitutions::SubstitutionValue; | ||
pub use substitutions::Substitutions; | ||
|
||
/// Normalize line endings | ||
pub fn normalize_lines(data: &str) -> String { | ||
normalize_lines_chars(data.chars()).collect() | ||
} | ||
|
||
fn normalize_lines_chars(data: impl Iterator<Item = char>) -> impl Iterator<Item = char> { | ||
normalize_line_endings::normalized(data) | ||
} | ||
|
||
/// Normalize path separators | ||
pub fn normalize_paths(data: &str) -> String { | ||
normalize_paths_chars(data.chars()).collect() | ||
} | ||
|
||
fn normalize_paths_chars(data: impl Iterator<Item = char>) -> impl Iterator<Item = char> { | ||
data.map(|c| if c == '\\' { '/' } else { c }) | ||
} | ||
|
||
/// "Smart" text normalization | ||
/// | ||
/// This includes | ||
/// - Line endings | ||
/// - Path separators | ||
pub fn normalize_text(data: &str) -> String { | ||
normalize_paths_chars(normalize_lines_chars(data.chars())).collect() | ||
} |
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,30 +1,3 @@ | ||
mod lines; | ||
|
||
pub use lines::LinesWithTerminator; | ||
|
||
/// Normalize line endings | ||
pub fn normalize_lines(data: &str) -> String { | ||
normalize_lines_chars(data.chars()).collect() | ||
} | ||
|
||
fn normalize_lines_chars(data: impl Iterator<Item = char>) -> impl Iterator<Item = char> { | ||
normalize_line_endings::normalized(data) | ||
} | ||
|
||
/// Normalize path separators | ||
pub fn normalize_paths(data: &str) -> String { | ||
normalize_paths_chars(data.chars()).collect() | ||
} | ||
|
||
fn normalize_paths_chars(data: impl Iterator<Item = char>) -> impl Iterator<Item = char> { | ||
data.map(|c| if c == '\\' { '/' } else { c }) | ||
} | ||
|
||
/// "Smart" text normalization | ||
/// | ||
/// This includes | ||
/// - Line endings | ||
/// - Path separators | ||
pub fn normalize_text(data: &str) -> String { | ||
normalize_paths_chars(normalize_lines_chars(data.chars())).collect() | ||
} |
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