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
65
66
67
use crate::{
    deser::{
        data_map::CfgFiles,
        locale::{get_locale_list, iter_over_locale_list},
    },
    generator::Generator,
    prelude::MapWriter,
};
use std::{
    collections::{BTreeMap, HashSet},
    io::{self, Write},
    path::PathBuf,
};

impl<'p, 'res, 'ver> Generator<'ver, 'p, 'res> {
    pub fn run<W: Write>(&self, mut writer: MapWriter<W>) -> io::Result<()> {
        self.defind_rs_file_header(writer.get_rs_file_mut())?;

        let sub_locale_map = phf_codegen::Map::new();
        // Create a new, empty map for localisation data
        let data_map = phf_codegen::Map::new();

        let org_dir = self.get_l10n_path();

        let mut locale_treemap = BTreeMap::new();
        let fpath = PathBuf::with_capacity(org_dir.capacity() + 2);

        // Sub-map name for detecting the same name
        let sub_sets = HashSet::with_capacity(20);

        let cfg_file = fpath.clone();
        let cfg_text = String::with_capacity(120);

        let files = CfgFiles::new(
            fpath,
            cfg_file,
            cfg_text,
            data_map,
            sub_locale_map,
            sub_sets,
            #[cfg(feature = "highlight")]
            self.get_highlight().as_ref(),
            #[cfg(not(feature = "highlight"))]
            None,
        );

        // Create a new, empty map for locale data
        let mut locale_map = phf_codegen::Map::new();

        let locale_list = get_locale_list(org_dir)?;

        iter_over_locale_list(
            locale_list.capacity(),
            &locale_list,
            files,
            org_dir,
            &mut locale_map,
            &mut locale_treemap,
            &mut writer,
        )?;

        writer.build_locale_phf_map(locale_map)?;
        writer.build_lc_treemap(locale_treemap)?;

        Ok(())
    }
}