Struct finl_charsub::charsub::CharSubMachine [−][src]
pub struct CharSubMachine { /* fields omitted */ }
Expand description
The implementation of a char substitution machine. This is a non-thread-safe implementation with mutable state.
Implementations
Create a new blank char substitution machine.
Create a new blank char substitution machine instantiated from the specified file (given
as a std::io::buffered::BufReader
. Since errors might occur during the read process, the result
is wrapped in anyhow::Result
. Errors can be of type CharSubError
, UnescapeError
or io::Error
depending on the origin of the error.
Add a new substitution rule to an existing char sub machine. This will not fail.
Process an input string and return the substitution in alloc::borrow::Cow<str>
. This will
not fail, but may leave unprocessed output behind if the end of the string might be part
pf a longer substitution, e.g..
let mut char_sub_machine = CharSubMachine::new();
char_sub_machine.add_substitution("A", "a");
char_sub_machine.add_substitution("ABC", "b");
assert_eq!("", char_sub_machine.process("AB"));
assert_eq!("b", char_sub_machine.process("C"));
Returns a possibly empty string with the contents of any unprocessed input still waiting in the unprocessed buffer.
let mut char_sub_machine = CharSubMachine::new();
char_sub_machine.add_substitution("A", "a");
char_sub_machine.add_substitution("ABC", "b");
assert_eq!("", char_sub_machine.process("AB"));
assert_eq!("aB".to_string(), char_sub_machine.flush());
assert_eq!("b", char_sub_machine.process("ABC"));
assert_eq!("".to_string(), char_sub_machine.flush());