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
/// Configuration options for the Bamboo engine.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Config {
/// If true, allows typing tone marks at any position in the word (Free Tone Marking).
/// Default: true.
pub free_tone_marking: bool,
/// If true, uses the standard (new) tone placement (e.g., "hòa", "khỏe").
/// If false, uses the old style (e.g., "hoà", "khoẻ").
/// Default: true.
pub std_tone_style: bool,
/// If true, enables automatic spelling correction to ensure valid Vietnamese syllables.
/// Default: true.
pub auto_correct: bool,
}
impl Default for Config {
fn default() -> Self {
Self {
free_tone_marking: true,
std_tone_style: true,
auto_correct: true,
}
}
}
impl Config {
/// Creates a new configuration with default values.
pub fn new() -> Self {
Self::default()
}
pub(crate) fn to_flags(self) -> u32 {
let mut flags = 0;
if self.free_tone_marking {
flags |= 1 << 0;
}
if self.std_tone_style {
flags |= 1 << 1;
}
if self.auto_correct {
flags |= 1 << 2;
}
flags
}
/// Creates a configuration from a bitmask of flags.
pub fn from_flags(flags: u32) -> Self {
Self {
free_tone_marking: (flags & (1 << 0)) != 0,
std_tone_style: (flags & (1 << 1)) != 0,
auto_correct: (flags & (1 << 2)) != 0,
}
}
}