pub struct Catalog { /* private fields */ }Expand description
A validated .mf2b catalog (F2): the fetched buffer and the offsets
new found. Share it as Rc<Catalog> / Arc<Catalog>.
Implementations§
Source§impl Catalog
impl Catalog
Sourcepub fn new(
bytes: Vec<u8>,
expect_manifest: u64,
) -> Result<Catalog, CatalogError>
pub fn new( bytes: Vec<u8>, expect_manifest: u64, ) -> Result<Catalog, CatalogError>
Takes ownership of a fetched .mf2b buffer and validates its
structure once: magic, version (F9), manifest_hash (F6), the section
table, INDEX bounds and monotonicity, and the NAMES, FUNCS, FALLBACK,
LOCALE (with its plural entries) and IDS tables. Strings are checked
when read (F4). Linear in the buffer; allocates nothing; no copy (F2).
Sourcepub fn manifest_hash(&self) -> u64
pub fn manifest_hash(&self) -> u64
The manifest hash this catalog was compiled against (F6).
Sourcepub fn cldr_version(&self) -> Option<CldrVersion>
pub fn cldr_version(&self) -> Option<CldrVersion>
The CLDR version of the locale data, if any.
Sourcepub fn message_count(&self) -> u32
pub fn message_count(&self) -> u32
The number of ids in the manifest (INDEX entries).
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Gives the buffer back (a copy, for a catalog over static bytes).
Sourcepub fn nfc_map(&self) -> NfcMap<'_>
pub fn nfc_map(&self) -> NfcMap<'_>
The canonical-equivalence map this catalog carries (plan/01 §4.3):
how the runtime decides whether a value the program passed in is
canonically equivalent to one of this catalog’s variant keys or
argument names. An absent section is the empty map.
Sourcepub fn names_function(&self, pick: impl Fn(&str) -> bool) -> bool
pub fn names_function(&self, pick: impl Fn(&str) -> bool) -> bool
Whether FUNCS names a function pick chooses, given each identifier
as FUNCS has it (ns:name, NFC). A catalog that names none has no
message that calls one, so a caller asking Catalog::calls of many
messages asks this first (plan/08 §4.3: whether a catalog has date
messages at all).
Sourcepub fn calls(&self, id: MsgId, pick: impl Fn(&str) -> bool) -> bool
pub fn calls(&self, id: MsgId, pick: impl Fn(&str) -> bool) -> bool
Whether message id calls a function pick chooses — in a
declaration, a placeholder, or any variant’s pattern — read from its
expression and declaration tags and FUNCS, without formatting it
(plan/08 §4.3: whether it is a date message). A simple or absent
message calls none. A malformed record counts as a call: the caller
that acts on true then acts on it too, which is harmless where
acting means formatting it again.