Skip to main content

strip_leading

Function strip_leading 

Source
pub fn strip_leading(source: &str) -> (&str, bool)
Expand description

Strip a strict-byte-0 leading BOM, returning (stripped, had_bom).

“Strict byte 0” means the BOM must be the very first bytes of the source. A BOM preceded by ANY content (whitespace, another character, anything) is by definition mid-file and is left in place for the lexer’s error path to surface — that’s not a “leading BOM” no matter how innocuous the preceding bytes look.

let with_bom = format!("{BOM}2024-01-01 open Assets:Bank\n");
let (stripped, had_bom) = strip_leading(&with_bom);
assert!(had_bom);
assert_eq!(stripped, "2024-01-01 open Assets:Bank\n");

let (stripped, had_bom) = strip_leading("2024-01-01 open Assets:Bank\n");
assert!(!had_bom);
assert_eq!(stripped, "2024-01-01 open Assets:Bank\n");