pub struct Engine { /* private fields */ }Expand description
The main stateful processor of the Vietnamese Input Method Engine.
It maintains an internal buffer of transformations and produces the correctly marked Vietnamese text.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(input_method: InputMethod) -> Self
pub fn new(input_method: InputMethod) -> Self
Creates a new engine with the specified input method and default configuration.
Sourcepub fn with_config(input_method: InputMethod, config: Config) -> Self
pub fn with_config(input_method: InputMethod, config: Config) -> Self
Creates a new engine with a specific input method and configuration.
Sourcepub fn set_config(&mut self, config: Config)
pub fn set_config(&mut self, config: Config)
Updates the engine configuration.
Sourcepub fn input_method(&self) -> InputMethod
pub fn input_method(&self) -> InputMethod
Returns a copy of the current input method.
Sourcepub fn process(&mut self, s: &str, mode: Mode) -> String
pub fn process(&mut self, s: &str, mode: Mode) -> String
Processes a string of characters and returns the current active word.
Sourcepub fn process_str(&mut self, s: &str, mode: Mode) -> &Self
pub fn process_str(&mut self, s: &str, mode: Mode) -> &Self
Processes a string of characters and returns a reference to the engine.
Sourcepub fn process_key_delta(
&mut self,
key: char,
mode: Mode,
) -> (usize, usize, &str)
pub fn process_key_delta( &mut self, key: char, mode: Mode, ) -> (usize, usize, &str)
Processes a single key and returns the “delta” change required for a text editor.
This is useful for IMEs to update the preedit text efficiently without rewriting the entire word.
§Returns
A tuple containing:
backspaces_chars: Number of characters to delete from the end of the previous preedit.backspaces_bytes: Number of UTF-8 bytes to delete.inserted: The new string to append after deletion.
Sourcepub fn process_key_delta_into(
&mut self,
key: char,
mode: Mode,
inserted: &mut String,
) -> usize
pub fn process_key_delta_into( &mut self, key: char, mode: Mode, inserted: &mut String, ) -> usize
Similar to Self::process_key_delta, but writes the inserted string into a provided buffer.
§Returns
The number of backspaces (characters) to perform.
Sourcepub fn process_key(&mut self, key: char, mode: Mode)
pub fn process_key(&mut self, key: char, mode: Mode)
Processes a single character.
The mode determines whether to apply Vietnamese transformation rules.
Sourcepub fn commit(&mut self)
pub fn commit(&mut self)
Clears the active syllable buffer and appends it to the committed text.
Sourcepub fn get_processed_str(&self, options: OutputOptions) -> String
pub fn get_processed_str(&self, options: OutputOptions) -> String
Returns the processed string according to the specified options.
This can be used to get the full text (committed + active) or variations like toneless text.
Sourcepub fn is_valid(&self, input_is_full_complete: bool) -> bool
pub fn is_valid(&self, input_is_full_complete: bool) -> bool
Checks if the current composition forms a valid Vietnamese syllable.
Sourcepub fn restore_last_word(&mut self, to_vietnamese: bool)
pub fn restore_last_word(&mut self, to_vietnamese: bool)
Restores the last word in the composition to its un-transformed state.
If to_vietnamese is true, it attempts to re-apply Vietnamese transformations.
Sourcepub fn remove_last_char(&mut self, refresh_last_tone_target: bool)
pub fn remove_last_char(&mut self, refresh_last_tone_target: bool)
Removes the last character from the active composition.