Struct crowbook_text_processing::french::FrenchFormatter
[−]
[src]
pub struct FrenchFormatter { /* fields omitted */ }French typographic formatter.
The purpose of this struct is to try to make a text more typographically correct, according to french typographic rules. This means:
- making spaces before
?,!,;narrow non-breaking space; - making spaces before
:non-breaking space; - making space after
—for dialog a demi em space; - making spaces after
«and before»non-breking space or narrow non-breking space, according to the circumstances (dialog or a few quoted words). - making spaces in numbers, e.g.
80 000or50 €narrow and non-breaking.
As this requires a bit of guessing sometimes, there are some paremeters that can be set if you want better results.
Methods
impl FrenchFormatter[src]
fn new() -> Self
Create a new FrenchFormatter with default settings
fn threshold_currency(&mut self, t: usize) -> &mut Self
Sets the threshold currency.
After that number of characters, assume it's not a currency
Default is 3.
fn threshold_unit(&mut self, t: usize) -> &mut Self
Sets the threshold for unit.
After that number of characters, assume it's not an unit.
Default is 2.
fn threshold_quote(&mut self, t: usize) -> &mut Self
Sets the threshold for quote.
After that number of characters, assume it's not a quote of a single word or a few words, but a dialog.
Default is 28 (just enough for « anticonstitutionnellement »).
fn threshold_real_word(&mut self, t: usize) -> &mut Self
Sets the threshold for real word.
After that number of characters, assume it's not an abbreviation
but a real word (used to determine if . marks the end of a sentence
or just a title such as M. Dupuis.
Default is 3
fn format<'a, S: Into<Cow<'a, str>>>(&self, input: S) -> Cow<'a, str>
(Try to) Format a string according to french typographic rules.
This method should be called for each paragraph, as it makes some suppositions that the beginning of the string also means the beginning of a line.
This method calls remove_whitespaces internally, as it relies on it.
Example
use crowbook_text_processing::french::FrenchFormatter; let f = FrenchFormatter::new(); let s = f.format("« Est-ce bien formaté ? » se demandait-elle — les espaces \ insécables étaient tellement compliquées à gérer, dans cette langue !"); println!("{}", s);Run
fn format_tex<'a, S: Into<Cow<'a, str>>>(&self, input: S) -> Cow<'a, str>
(Try to) Format a string according to french typographic rules, and use '~' so it works correctly with LaTeX output.
Example
use crowbook_text_processing::french::FrenchFormatter; let f = FrenchFormatter::new(); let s = f.format_tex("« Est-ce bien formaté ? »"); assert_eq!(&s, "«~Est-ce bien formaté~?~»");Run