strip_bom

Add a simple BOM striping feature for str and String.

Usage

rust use str_strip_bom::*;

```rust // Or std::fs::readtostring, surf::get, ... let mystring: Vec = vec![ 0xefu8, 0xbb, 0xbf, 0xf0, 0x9f, 0x8d, 0xa3 ]; let mystring: String = String::fromutf8( mystring ).unwrap();

// In this time, mystring has the BOM => true 🍣 println!( "{} {}", mystring.startswith("\u{feff}"), &mystring );

// Strip BOM let mystring: &str = mystring.strip_bom();

// mystring (slice) has not the BOM => false 🍣 println!( "{} {}", mystring.startswith("\u{feff}"), &mystring ); ```

Motivation

  1. I author wanted a simple and lightweight BOM stripper for only str and String, not for byte stream or the other of UTF-8 such as UTF-16 or UTF-32.
  2. Because, for example, serde and serde_json has no BOM supporting then it will be fail if I put a UTF-8 BOM source.
  3. The rust standard, str and Strings will not support a BOM stripping features.; See also https://github.com/rust-lang/rfcs/issues/2428.

Reference

License

Author