LocaleSlug.Tables (LocaleSlug v0.2.0)

Copy Markdown View Source

Compiled lookup tables, and the accessors the engine matches through.

A table is %{max_key_len: n, rules: %{key_graphemes => branches}, classes: %{...}} where branches is an ordered list of {conditions, output} and the last entry has conditions == [] (the required default).

Keys are stored as grapheme lists, not binaries, so matching never has to re-segment. That is also how match_at/2 stays a plain prefix comparison instead of a byte-level match that would need to re-verify cluster boundaries afterwards.

The data comes from LocaleSlug.GeneratedTables, which is produced from the YAML in priv/ by mix locale_slug.gen and committed. Consumers of the package therefore need no YAML parser and no dependencies at all.

Summary

Types

t()

A compiled table: ordered rules keyed by grapheme list, plus named classes.

Functions

The L0 base table.

Members of a named character class in table, as a MapSet of graphemes.

Metadata (status, source, reviewers) for a locale or schema id.

An L2 locale table by tag, or nil.

Every locale tag that ships.

Every rule in table whose key matches at the head of graphemes.

Every schema id that ships.

An L1 script table by schema id, or nil.

Types

t()

@type t() :: %{
  max_key_len: non_neg_integer(),
  rules: %{optional([String.t()]) => [{list(), String.t()}]},
  classes: %{optional(String.t()) => MapSet.t(String.t())}
}

A compiled table: ordered rules keyed by grapheme list, plus named classes.

Functions

base()

@spec base() :: t()

The L0 base table.

class(table, name)

@spec class(t() | nil, String.t()) :: MapSet.t(String.t())

Members of a named character class in table, as a MapSet of graphemes.

info(id)

@spec info(String.t()) :: LocaleSlug.table_info() | nil

Metadata (status, source, reviewers) for a locale or schema id.

locale(tag)

@spec locale(String.t() | nil) :: t() | nil

An L2 locale table by tag, or nil.

locales()

@spec locales() :: [String.t()]

Every locale tag that ships.

match_at(table, graphemes)

@spec match_at(t() | nil, [String.t()]) :: [{pos_integer(), [{list(), String.t()}]}]

Every rule in table whose key matches at the head of graphemes.

Returns [{key_length, branches}], unordered — the engine ranks them.

schemas()

@spec schemas() :: [String.t()]

Every schema id that ships.

script(schema)

@spec script(String.t() | nil) :: t() | nil

An L1 script table by schema id, or nil.