Skip to main content

TextTable

Struct TextTable 

Source
pub struct TextTable { /* private fields */ }
Expand description

A per-language table that replaces bodies.

Keys are module.label#id (the same form as passed stop points). Values are bodies in the same form as the original. Pass it to the VM with Vm::set_texts.

Implementations§

Source§

impl TextTable

Source

pub fn new(language: impl Into<String>) -> Self

Makes an empty table. language is the name of the language (such as en; the core gives it no meaning).

Source

pub fn language(&self) -> &str

The name of the language.

Source

pub fn insert( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> Result<(), TextError>

Puts a translation. If the same key exists, replaces it.

A translation is a body in the same form as the original. Body escapes (\「 \」 \$ \\ \= \#) can be used. ${n} (n is an integer of 1 or more) becomes the value of the n-th ${expr} of the original. Any other \ combinations and ${…} are errors (the table is unchanged). Whether n exceeds the count in the original is not checked here, because the scripts are unknown (Vm::set_texts and TextTable::check check it).

Source

pub fn get(&self, key: &str) -> Option<&str>

The translation of a key (as written).

Source

pub fn len(&self) -> usize

The number of translations.

Source

pub fn is_empty(&self) -> bool

Whether it is empty.

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>

Returns (key, translation) in insertion order.

Source

pub fn check(&self, program: &Program) -> Vec<TextIssue>

Checks against the scripts. Results are in script order (missing translations, number errors), followed by table order (extra translations).

  • Missing translation (warning): a key of a body with a stable ID in the scripts that is not in the table.
  • Extra translation (warning): a key in the table that is not in the scripts.
  • Number error (error): the n of ${n} exceeds the number of ${expr} in the original.
Source

pub fn template(program: &Program, language: impl Into<String>) -> Self

Makes a table (a template) whose translations are the originals, for all bodies with stable IDs in the scripts. ${expr} becomes a numbered ${n} (in the order written). Translators rewrite it into translations.

Source

pub fn from_file(source: &str) -> Result<Self, TextError>

Reads a table from the text of a file (a line-oriented format for tools; section 5.7 of spec/host/05-texts.md).

  • Empty lines are skipped. Lines starting with # are comments.
  • A line @lang language sets the language name (empty if absent).
  • Other lines are key TAB translation. In translations, \n is a newline, \t a TAB and \r a carriage return. Other \ sequences are translation escapes (such as \\).
  • A key appearing twice, or a translation that is an error in TextTable::insert, gives an error with the line.
Source

pub fn to_file(&self) -> String

Turns the table into the text of a file (it can be read back with TextTable::from_file).

Trait Implementations§

Source§

impl Clone for TextTable

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TextTable

Source§

impl PartialEq for TextTable

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TextTable

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.