) -> Result<(), IoError> {
let mut file = File::create(file_name)?;
- write!(file, "{}", "\
+ write!(
+ file,
+ "{}",
+ "\
use lazy_static::lazy_static;
use std::collections::HashMap;
lazy_static! {
static ref CODEPAGE_NUMBER_TO_NAME: HashMap<u32, &'static str> = {
let mut map = HashMap::new();
-")?;
+"
+ )?;
for (&cpnumber, value) in codepages.iter() {
let source = value.keys().max().unwrap();
let name = value[source][0];
writeln!(file, " map.insert({cpnumber}, \"{name}\");")?;
}
- write!(file, "{}", "\
- map
+ write!(
+ file,
+ "{}",
+ " map
};
-}
-")?;
- let mut names: BTreeMap<&str, BTreeMap<Source, Vec<CPNumber>>> = BTreeMap::new();
+ static ref CODEPAGE_NAME_TO_NUMBER: HashMap<&'static str, u32> = {
+ let mut map = HashMap::new();
+"
+ )?;
+
+ let mut names: BTreeMap<String, BTreeMap<Source, Vec<CPNumber>>> = BTreeMap::new();
for (&cpnumber, value) in codepages.iter() {
for (&source, value2) in value.iter() {
- for &name in value2.iter() {
+ for name in value2.iter().map(|name| name.to_ascii_lowercase()) {
names
.entry(name)
.or_insert_with(BTreeMap::new)
}
}
- for (&name, value) in names.iter() {
- for (_source, numbers) in value.iter().rev() {
- println!(" {{ {}, \"{name}\" }},", numbers[0]);
- break;
+ for (name, value) in names.iter() {
+ for (_source, numbers) in value.iter().rev().take(1) {
+ writeln!(file, " map.insert(\"{name}\", {});", numbers[0])?;
}
}
+ write!(
+ file,
+ "{}",
+ " map
+ };
+}
+"
+ )?;
Ok(())
}