1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/// Set the formatting of the output  
#[derive(Clone, Copy)]
pub struct Formatting<'format> {
    /// capitalize the start of the word.
    pub capitalize: bool,
    /// Set the seperator in between digits like "threehundred,twentytwo".
    pub digit_seperator: Option<&'format str>,
    /// Set the seperator in between words like "three/hundred".
    pub place_seperator: Option<&'format str>,
    /// Set the seperator between tens place digits like "twenty-two".
    pub tens_seperator: Option<&'format str>,
}

impl<'format> Formatting<'format> {
    /// Get the default formatting.
    pub fn default() -> Self {
        Self {
            capitalize: true,
            digit_seperator: Some(","),
            place_seperator: Some(" "),
            tens_seperator: Some("-"),
        }
    }
    /// No formatting at all
    pub fn none() -> Self {
        Self {
            capitalize: false,
            digit_seperator: None,
            place_seperator: None,
            tens_seperator: None,
        }
    }
    /// With same formatting for all seperators
    pub fn with_seperator(seperator: &'format str) -> Self {
        Self {
            capitalize: false,
            digit_seperator: Some(seperator),
            place_seperator: Some(seperator),
            tens_seperator: Some(seperator),
        }
    }
    /// Capitalize the formatting
    pub fn capitalize(&mut self) -> Self {
        self.capitalize = true;
        Self {
            capitalize: self.capitalize,
            digit_seperator: self.digit_seperator,
            place_seperator: self.place_seperator,
            tens_seperator: self.tens_seperator,
        }
    }
    /// Lower case the formatting struct
    pub fn decapitalize(&mut self) -> Self {
        self.capitalize = false;
        Self {
            capitalize: self.capitalize,
            digit_seperator: self.digit_seperator,
            place_seperator: self.place_seperator,
            tens_seperator: self.tens_seperator,
        }
    }
}