From feaf9cd6d9e582c1db461eb4be959b67a7a2c744 Mon Sep 17 00:00:00 2001 From: Chris Ha Date: Fri, 13 Oct 2023 16:51:36 +0900 Subject: [PATCH] Fixes lint issues and CRLF support (#33) --- generator/src/lib.rs | 15 ++++++--------- generator/src/util.rs | 6 ++++-- src/jamo.rs | 24 ++++++++++++------------ src/lib.rs | 8 ++++---- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/generator/src/lib.rs b/generator/src/lib.rs index d92d356..f7f1abc 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -39,7 +39,7 @@ fn get_table_data(unicode_data: &'static str) -> TableData { Some((c, name)) } - let mut iter = unicode_data.split('\n'); + let mut iter = unicode_data.lines(); let mut codepoint_names = vec![]; let mut cjk_ideograph_ranges = vec![]; @@ -98,17 +98,14 @@ pub struct Alias { pub fn get_aliases(name_aliases: &'static str) -> Vec { let mut aliases = Vec::new(); - for line in name_aliases.split(['\n', '\r']) { - if line.is_empty() { - continue; - } - if line.starts_with('#') { + for line in name_aliases.lines() { + if line.is_empty() | line.starts_with('#') { continue; } let mut parts = line.splitn(3, ';'); - let code = parts.next().unwrap(); - let alias = parts.next().unwrap(); - let category = parts.next().unwrap(); + let code = parts.next().expect(line); + let alias = parts.next().expect(code); + let category = parts.next().expect(alias); aliases.push(Alias { code, alias, diff --git a/generator/src/util.rs b/generator/src/util.rs index 74a0714..8fee296 100644 --- a/generator/src/util.rs +++ b/generator/src/util.rs @@ -32,10 +32,12 @@ impl<'a, 'b> Iterator for Split<'a, 'b> { fn next(&mut self) -> Option<&'a str> { if self.done { return None; - } else if self.s.is_empty() { + } + if self.s.is_empty() { self.done = true; return Some(""); - } else if !self.pending.is_empty() { + } + if !self.pending.is_empty() { return Some(std::mem::take(&mut self.pending)); } diff --git a/src/jamo.rs b/src/jamo.rs index 9989811..ca6c32a 100644 --- a/src/jamo.rs +++ b/src/jamo.rs @@ -19,24 +19,24 @@ pub fn is_hangul_syllable(c: char) -> bool { } pub fn syllable_decomposition(c: char) -> Option<(u8, u8, u8)> { - if !is_hangul_syllable(c) { + if is_hangul_syllable(c) { + let n = c as u32 - 0xAC00; + // break this into the various parts. + let jongseong = n % 28; + let jungseong = (n / 28) % 21; + let choseong = n / (28 * 21); + Some((choseong as u8, jungseong as u8, jongseong as u8)) + } else { // outside the range - return None; + None } - let n = c as u32 - 0xAC00; - // break this into the various parts. - let jongseong = n % 28; - let jungseong = (n / 28) % 21; - let choseong = n / (28 * 21); - - Some((choseong as u8, jungseong as u8, jongseong as u8)) } fn slice_shift_byte(a: &[u8]) -> (Option, &[u8]) { - if !a.is_empty() { - (Some(a[0]), &a[1..]) - } else { + if a.is_empty() { (None, a) + } else { + (Some(a[0]), &a[1..]) } } diff --git a/src/lib.rs b/src/lib.rs index 3075240..81d5f31 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -371,10 +371,10 @@ pub fn character(search_name: &str) -> Option { } // avoid overflow let mut v = 0u32; - for &c in remaining.iter() { - match c { - b'0'..=b'9' => v = (v << 4) | (c - b'0') as u32, - b'A'..=b'F' => v = (v << 4) | (c - b'A' + 10) as u32, + for &c in remaining { + v = match c { + b'0'..=b'9' => (v << 4) | (c - b'0') as u32, + b'A'..=b'F' => (v << 4) | (c - b'A' + 10) as u32, _ => return None, } }