pub struct Charset { /* private fields */ }Expand description
Identifies the charset associated with a codec or error.
A charset is represented by a stable normalized identifier, a display name, and accepted aliases. Equality and hashing use only the identifier, so display names and alias lists can evolve without changing identity.
§Examples
use qubit_text_codec::Charset;
const GBK: Charset = Charset::new("gbk", "GBK", &["cp936"]);
assert!(GBK.matches_label("CP936"));
assert_eq!(GBK, Charset::new("gbk", "Chinese GBK", &[]));
assert_eq!("GBK", GBK.to_string());Implementations§
Source§impl Charset
impl Charset
Sourcepub const ISO_8859_1: Self
pub const ISO_8859_1: Self
ISO-8859-1 / Latin-1 text.
Sourcepub const fn new(
id: &'static str,
name: &'static str,
aliases: &'static [&'static str],
) -> Self
pub const fn new( id: &'static str, name: &'static str, aliases: &'static [&'static str], ) -> Self
Sourcepub const fn id(self) -> &'static str
pub const fn id(self) -> &'static str
Returns the stable normalized charset identifier.
§Returns
Returns the identifier used for equality and hashing.
Sourcepub const fn name(self) -> &'static str
pub const fn name(self) -> &'static str
Returns a human-readable charset label.
§Returns
Returns the display name stored in this descriptor.
Sourcepub const fn aliases(self) -> &'static [&'static str]
pub const fn aliases(self) -> &'static [&'static str]
Returns accepted aliases for this charset.
§Returns
Returns the static alias list stored in this descriptor.
Sourcepub const fn from_utf16_byte_order(byte_order: ByteOrder) -> Self
pub const fn from_utf16_byte_order(byte_order: ByteOrder) -> Self
Returns the UTF-16 charset with a fixed byte order.
§Parameters
byte_order: The byte order used by the byte stream.
§Returns
Returns Self::UTF_16LE for little-endian byte order and
Self::UTF_16BE for big-endian byte order.
Sourcepub const fn from_utf32_byte_order(byte_order: ByteOrder) -> Self
pub const fn from_utf32_byte_order(byte_order: ByteOrder) -> Self
Returns the UTF-32 charset with a fixed byte order.
§Parameters
byte_order: The byte order used by the byte stream.
§Returns
Returns Self::UTF_32LE for little-endian byte order and
Self::UTF_32BE for big-endian byte order.
Sourcepub fn byte_order(self) -> Option<ByteOrder>
pub fn byte_order(self) -> Option<ByteOrder>
Returns the fixed byte order represented by this charset.
§Returns
Returns Some(ByteOrder) for fixed-endian UTF-16 and UTF-32 charsets.
Returns None for UTF-8 and generic UTF-16/UTF-32 charsets.