https://github.com/usagi/strip_bom
Add a simple BOM striping feature for `str` and `String`.
https://github.com/usagi/strip_bom
Last synced: about 2 months ago
JSON representation
Add a simple BOM striping feature for `str` and `String`.
- Host: GitHub
- URL: https://github.com/usagi/strip_bom
- Owner: usagi
- License: mit
- Created: 2020-09-10T21:19:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-10T21:22:21.000Z (over 4 years ago)
- Last Synced: 2025-03-23T21:11:25.346Z (2 months ago)
- Language: Rust
- Size: 4.88 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# strip_bom
Add a simple BOM striping feature for `str` and `String`.
## Usage
```rust
use str_strip_bom::*;
``````rust
// Or std::fs::read_to_string, surf::get, ...
let my_string: Vec = vec![ 0xefu8, 0xbb, 0xbf, 0xf0, 0x9f, 0x8d, 0xa3 ];
let my_string: String = String::from_utf8( my_string ).unwrap();// In this time, my_string has the BOM => true ๐ฃ
println!( "{} {}", my_string.starts_with("\u{feff}"), &my_string );// Strip BOM
let my_string: &str = my_string.strip_bom();// my_string (slice) has not the BOM => false ๐ฃ
println!( "{} {}", my_string.starts_with("\u{feff}"), &my_string );
```## 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 `String`s will not support a BOM stripping features.; See also .## Reference
- ; RFC3269 "UTF-8, a transformation format of ISO 10646" ยง6. Byte order mark (BOM)
## License
- [MIT](LICENSE)
## Author
- USAGI.NETWORK / Usagi Ito