-
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.
`Arc<String>` to `Arc<str>` (double heap pointer -> single heap pointer) Also enforces that BOM handling is a `deno_graph` concern. See denoland/deno_graph#152
- Loading branch information
1 parent
88aa744
commit 30b1a2d
Showing
2 changed files
with
19 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1 @@ | ||
pub const BOM_CHAR: char = '\u{FEFF}'; | ||
|
||
/// Strips the byte order mark if it exists from the provided text in place. | ||
pub fn strip_bom_mut(text: &mut String) { | ||
if text.starts_with(BOM_CHAR) { | ||
text.drain(..BOM_CHAR.len_utf8()); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn strip_bom_mut_with_bom() { | ||
let mut text = format!("{}text", BOM_CHAR); | ||
strip_bom_mut(&mut text); | ||
assert_eq!(text, "text"); | ||
} | ||
|
||
#[test] | ||
fn strip_bom_mut_without_bom() { | ||
let mut text = "text".to_string(); | ||
strip_bom_mut(&mut text); | ||
assert_eq!(text, "text"); | ||
} | ||
} |
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