strip_bom
Add a simple BOM striping feature for str and String.
Usage
use *;
// Or std::fs::read_to_string, surf::get, ...
let my_string: = vec!;
let my_string: String = Stringfrom_utf8.unwrap;
// In this time, my_string has the BOM => true 🍣
println!;
// Strip BOM
let my_string: &str = my_string.strip_bom;
// my_string (slice) has not the BOM => false 🍣
println!;
Motivation
- I author wanted a simple and lightweight BOM stripper for only
strandString, not for byte stream or the other of UTF-8 such as UTF-16 or UTF-32. - Because, for example,
serdeandserde_jsonhas no BOM supporting then it will be fail if I put a UTF-8 BOM source. - The rust standard,
strandStrings will not support a BOM stripping features.; See also https://github.com/rust-lang/rfcs/issues/2428.
Reference
- https://tools.ietf.org/html/rfc3629; RFC3269 "UTF-8, a transformation format of ISO 10646" §6. Byte order mark (BOM)
License
Author
- USAGI.NETWORK / Usagi Ito https://usagi.network