pub enum UnicodeBom {
Utf8,
Utf16BigEndian,
Utf16LittleEndian,
Utf32BigEndian,
Utf32LittleEndian,
}Expand description
Unicode byte order marks supported by this crate.
detect recognizes BOMs only from the bytes supplied to the call. Streaming
callers should buffer up to four bytes, or read until EOF, before deciding
that no longer BOM can be present.
§Examples
use qubit_text_codec::{
ByteOrder,
Charset,
UnicodeBom,
};
let bom = UnicodeBom::detect(&[0xff, 0xfe, 0x00, 0x00]);
assert_eq!(Some(UnicodeBom::Utf32LittleEndian), bom);
let bom = bom.expect("UTF-32LE BOM");
assert_eq!(Charset::UTF_32LE, bom.charset());
assert_eq!(Some(ByteOrder::LittleEndian), bom.byte_order());
assert_eq!(4, bom.byte_len());Variants§
Utf8
UTF-8 byte order mark.
Utf16BigEndian
UTF-16 big-endian byte order mark.
Utf16LittleEndian
UTF-16 little-endian byte order mark.
Utf32BigEndian
UTF-32 big-endian byte order mark.
Utf32LittleEndian
UTF-32 little-endian byte order mark.
Implementations§
Source§impl UnicodeBom
impl UnicodeBom
Sourcepub fn detect(bytes: &[u8]) -> Option<Self>
pub fn detect(bytes: &[u8]) -> Option<Self>
Detects a Unicode byte order mark at the beginning of bytes.
§Parameters
bytes: The byte buffer to inspect.
§Returns
Returns the detected BOM, or None if no supported BOM prefix is present.
UTF-32 BOMs are checked before UTF-16 BOMs so that overlapping prefixes
such as FF FE 00 00 are classified as UTF-32 little-endian when all
four bytes are available.
Sourcepub const fn bytes(self) -> &'static [u8] ⓘ
pub const fn bytes(self) -> &'static [u8] ⓘ
Returns the bytes that represent this BOM.
§Returns
Returns a static byte slice containing the BOM bytes.
Sourcepub const fn byte_order(self) -> Option<ByteOrder>
pub const fn byte_order(self) -> Option<ByteOrder>
Returns the byte order indicated by this BOM when applicable.
§Returns
Returns Some(ByteOrder) for UTF-16 and UTF-32 BOMs. Returns None for
UTF-8 because byte order does not apply.
Trait Implementations§
Source§impl Clone for UnicodeBom
impl Clone for UnicodeBom
Source§fn clone(&self) -> UnicodeBom
fn clone(&self) -> UnicodeBom
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UnicodeBom
impl Debug for UnicodeBom
Source§impl Hash for UnicodeBom
impl Hash for UnicodeBom
Source§impl PartialEq for UnicodeBom
impl PartialEq for UnicodeBom
Source§fn eq(&self, other: &UnicodeBom) -> bool
fn eq(&self, other: &UnicodeBom) -> bool
self and other values to be equal, and is used by ==.