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
63
64
/*!
A submodule containing the section data container of the doctree.
Copyright © 2020 Santtu Söderholm
*/
use super::*;
/// A container for section-related data of the doctree of ruSTLa.
pub struct SectionData {
/// A mapping of the different encountered section styles to section levels.
section_levels: HashMap<SectionLineStyle, usize>,
/// As the name implies, this counter is incremented as new types of sections
/// are encountered in the document. It is assigned to `self.levels` when a new
/// type is encountered and incremented.
highest_encountered_section_level: usize,
}
impl SectionData {
/// A `SectionData` constructor.
pub fn new() -> Self {
Self {
section_levels: HashMap::new(),
highest_encountered_section_level: 0,
}
}
/// Increments the number of encountered sections.
pub fn increment_encountered_section_number(&mut self) {
self.highest_encountered_section_level += 1;
}
/// Returns the highest encountered section level.
pub fn highest_encountered_section_level(&self) -> usize {
self.highest_encountered_section_level
}
/// Asks the SectionData container for the section level that a given section
/// line style corresponds to. If the line style has not been encountered before,
/// returns `self.highest_encountered_section_level + 1`.
pub fn line_style_section_level(&self, line_style: &SectionLineStyle) -> usize {
match self.section_levels.get(line_style) {
Some(section_level) => *section_level,
None => self.highest_encountered_section_level + 1,
}
}
/// Adds a new section line style to known section levels, if not present.
pub fn add_section_level(&mut self, section_style: SectionLineStyle) {
match self.section_levels.get(§ion_style) {
Some(section_level) => {}
None => match self
.section_levels
.insert(section_style, self.highest_encountered_section_level + 1)
{
Some(level) => {} //eprintln!("Updating level of section style {:#?}\n", section_style),
None => {} //eprintln!("Adding a new section level to known levels...\n")
},
}
}
}