MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / skip_bom

Method skip_bom

atomic-core/src/change/encoding.rs:288–312  ·  view source on GitHub ↗

Skip BOM bytes in content if present. Returns the content without the BOM prefix for this encoding. # Arguments `content` - The content potentially starting with a BOM # Returns The content after any BOM bytes.

(&self, content: &'a [u8])

Source from the content-addressed store, hash-verified

286 ///
287 /// The content after any BOM bytes.
288 pub fn skip_bom<'a>(&self, content: &'a [u8]) -> &'a [u8] {
289 match self {
290 Encoding::Utf8 => {
291 if content.len() >= 3
292 && content[0] == 0xEF
293 && content[1] == 0xBB
294 && content[2] == 0xBF
295 {
296 &content[3..]
297 } else {
298 content
299 }
300 }
301 Encoding::Utf16Le | Encoding::Utf16Be => {
302 if content.len() >= 2 {
303 let bom = self.bom();
304 if content.starts_with(bom) {
305 return &content[bom.len()..];
306 }
307 }
308 content
309 }
310 Encoding::Latin1 | Encoding::Binary => content,
311 }
312 }
313}
314
315impl fmt::Display for Encoding {

Callers

nothing calls this directly

Calls 2

bomMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected