Skip to content

Commit f785988

Browse files
committed
Remove options from lookup tables
1 parent cc2190a commit f785988

File tree

3 files changed

+1785
-1816
lines changed

3 files changed

+1785
-1816
lines changed

codegen/src/main.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn include_table<R: BufRead, W: Write>(writer: &mut W, reader: &mut R, tablename
3232
}
3333

3434
// Output table declaration.
35-
write!(writer, "pub const {}: &[(char, Option<char>, Option<&str>)] = &[\n", tablename.replace(".", "_")).unwrap();
35+
write!(writer, "pub const {}: &[(char, char, &str)] = &[\n", tablename.replace(".", "_")).unwrap();
3636

3737
// For each line:
3838
let target_re = Regex::new(r"([0-9A-F]+)(-([0-9A-F]+))?(; ([0-9A-F]+)( ([0-9A-F]+))?( ([0-9A-F]+))?( ([0-9A-F]+))?;)?").unwrap();
@@ -52,23 +52,11 @@ fn include_table<R: BufRead, W: Write>(writer: &mut W, reader: &mut R, tablename
5252

5353
// Generate an entry for each data line.
5454
if let Some(captures) = target_re.captures(&line) {
55-
let start = captures.get(1).unwrap();
55+
// start char
56+
let start = captures.get(1).unwrap().as_str();
5657

57-
// '\u{start}',
58-
let mut entry = String::from("'\\u{");
59-
entry.push_str(start.as_str());
60-
entry.push_str("}', ");
61-
62-
// '\u{start}', None,
63-
// '\u{start}', Some('\u{end}'),
64-
match captures.get(3) {
65-
None => entry.push_str("None, "),
66-
Some(end) => {
67-
entry.push_str("Some('\\u{");
68-
entry.push_str(end.as_str());
69-
entry.push_str("}'), ");
70-
}
71-
}
58+
// end char (inclusive)
59+
let end = captures.get(3).map_or(start, |m| m.as_str());
7260

7361
// 0-4 character replacement string
7462
let mut replace = String::new();
@@ -83,18 +71,7 @@ fn include_table<R: BufRead, W: Write>(writer: &mut W, reader: &mut R, tablename
8371
}
8472
}
8573

86-
// '\u{start}', None, None
87-
// '\u{start}', None, Some("replace")
88-
if replace.is_empty() {
89-
entry.push_str("None");
90-
} else {
91-
entry.push_str("Some(\"");
92-
entry.push_str(&replace);
93-
entry.push_str("\")");
94-
}
95-
96-
// Output entry for this line.
97-
write!(writer, " ({}),\n", entry).unwrap();
74+
write!(writer, " ('\\u{{{}}}', '\\u{{{}}}', \"{}\"),\n", start, end, replace).unwrap()
9875
}
9976
}
10077

0 commit comments

Comments
 (0)