mirror of
https://github.com/eiskasten/wc-beacon.git
synced 2026-09-08 12:25:08 -05:00
Handle newlines
This commit is contained in:
2
build.rs
2
build.rs
@@ -16,7 +16,7 @@ fn main() {
|
||||
let reader = BufReader::new(File::open(MAP_PATH).expect("Character map for generation iv"));
|
||||
let mapping: HashMap<u16, Utf16Grapheme> = reader.lines().filter_map(|r| {
|
||||
if let Ok(s) = r { if s.starts_with("0x") && s.len() >= 8 { Some(s) } else { None } } else { None }
|
||||
}).map(|s| (u16::from_str_radix(&s[2..6], 16).expect(&format!("Invalid number: 0x{}", &s[2..6])), str_to_utf16_graphemes(&s[7..]).remove(0))).collect();
|
||||
}).map(|s| (u16::from_str_radix(&s[2..6], 16).expect(&format!("Invalid number: 0x{}", &s[2..6])), if "\\n".eq(&s[7..]) { Utf16Grapheme::Bmp(0x000au16) } else { str_to_utf16_graphemes(&s[7..]).remove(0) })).collect();
|
||||
|
||||
let mut writer = LineWriter::new(File::create(path).unwrap());
|
||||
write!(writer, "use utf16::Utf16Grapheme; pub const CHARACTER_MAP_BY_GENIV: [Utf16Grapheme; {}] = [\n", CHARACTERS).unwrap();
|
||||
|
||||
@@ -46,14 +46,26 @@ impl TryFrom<&Gen4Str> for String {
|
||||
}
|
||||
}
|
||||
|
||||
const HARD_CODED_MAPPINGS: [(u16, Utf16Grapheme); 1] = [(0xe000, Utf16Grapheme::Bmp(0x0a))];
|
||||
|
||||
/// Look up the corresponding UTF16 grapheme to a pokémon gen iv character.
|
||||
/// Returns [None] when the character map does not contain such a character.
|
||||
fn to_utf16(geniv_char: u16) -> Option<&'static Utf16Grapheme> {
|
||||
for m in &HARD_CODED_MAPPINGS {
|
||||
if m.0 == geniv_char {
|
||||
return Some(&m.1);
|
||||
}
|
||||
}
|
||||
CHARACTER_MAP_BY_GENIV.get(usize::from(geniv_char))
|
||||
}
|
||||
|
||||
/// Look up the corresponding pokémon gen iv character to a UTF16 grapheme.
|
||||
/// Returns [None] when the character map does not contain such a character.
|
||||
fn to_geniv_char(grapheme: &Utf16Grapheme) -> Option<u16> {
|
||||
for m in &HARD_CODED_MAPPINGS {
|
||||
if m.1 == *grapheme {
|
||||
return Some(m.0);
|
||||
}
|
||||
}
|
||||
CHARACTER_MAP_BY_UTF16.binary_search_by(|(u, _)| u.cmp(grapheme)).map(|i| CHARACTER_MAP_BY_UTF16[i].1).ok()
|
||||
}
|
||||
Reference in New Issue
Block a user