Struct contractions::Contractions [−][src]
pub struct Contractions { /* fields omitted */ }
Expand description
Main actor in the contractions
crate
Stores Contractions
in a Vec
Example
let contractions = contractions::Contractions::default(); assert_eq!("I am sure you would have been fine.", contractions.apply("I’m sure you’d’ve been fine.")); assert_eq!("Are you sure?", contractions.apply("R u sure?"));
Implementations
impl Contractions
[src]
impl Contractions
[src]#[must_use]pub const fn new() -> Self
[src]
#[must_use]pub const fn new() -> Self
[src]Creates empty Contractions
Example
use contractions::{self, Contractions}; let contractions = Contractions::new();
pub fn from_json(contractions_as_str: &[&str]) -> Result<Self, Box<dyn Error>>
[src]
pub fn from_json(contractions_as_str: &[&str]) -> Result<Self, Box<dyn Error>>
[src]Deserialize Contraction
from json
Convenience method that chains Contractions::new()
and Contractions::add_from_json()
Example
use contractions::{self, Contractions}; let contractions = Contractions::from_json(&[contractions::SINGLE_CONTRACTIONS_JSON, contractions::SINGLE_NO_APOSTROPHE_CONTRACTIONS_JSON]);
Errors
Returns an Error if deserialization fails
pub fn add_from_json(
&mut self,
contractions_as_str: &str
) -> Result<(), Box<dyn Error>>
[src]
pub fn add_from_json(
&mut self,
contractions_as_str: &str
) -> Result<(), Box<dyn Error>>
[src]Add Contraction
s from a json string to an existing
Contractions
struct
Example
use contractions::{self, Contractions}; let mut contractions = Contractions::new(); contractions.add_from_json(contractions::SINGLE_CONTRACTIONS_JSON);
Errors
Returns an Error if deserialization fails
pub fn remove(&mut self, key: &str)
[src]
pub fn remove(&mut self, key: &str)
[src]Remove a Contraction
from Contractions
Provide the exact find
key to delete the corresponding Contraction
Example
use contractions::{self, Contractions}; let mut contractions = Contractions::new(); assert_eq!("I’m happy", contractions.apply("I’m happy")); contractions.add_from_json(contractions::SINGLE_CONTRACTIONS_JSON); assert_eq!("I am happy", contractions.apply("I’m happy")); contractions.remove("\\b(?i)i['’`]m(?-i)\\b"); assert_eq!("I’m happy", contractions.apply("I’m happy"));
pub fn add(
&mut self,
find: &str,
replace: LinkedHashMap<&str, &str>
) -> Result<(), Box<dyn Error>>
[src]
pub fn add(
&mut self,
find: &str,
replace: LinkedHashMap<&str, &str>
) -> Result<(), Box<dyn Error>>
[src]Add a contraction to Contractions
Example
use contractions::{self, Contractions}; let mut contractions = Contractions::new(); assert_eq!("I’m happy", contractions.apply("I’m happy")); let find = r#"\b(?i)i['’`]m(?-i)\b"#; let mut replace = linked_hash_map::LinkedHashMap::new(); replace.insert(r#"\bi['’`]m\b"#, "i am"); replace.insert(r#"\bI['’`]m\b"#, "I am"); replace.insert(r#"\bI['’`]M\b"#, "I AM"); contractions.add(find, replace); assert_eq!("I am happy", contractions.apply("I’m happy"));
Errors
Returns an Error if find
or the key in the replace
cannot be successfully turned into a Regex
Trait Implementations
impl Debug for Contractions
[src]
impl Debug for Contractions
[src]impl Default for Contractions
[src]
impl Default for Contractions
[src]fn default() -> Self
[src]
fn default() -> Self
[src]Returns the built in configuration for Contractions
Example
use contractions::Contractions; let contractions = Contractions::new();
Panics
Only panics when the library internal configuration is faulty this ought to only happen during development