Skip to content

Commit

Permalink
Fixes lint issues and CRLF support (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-ha458 authored Oct 13, 2023
1 parent 7a3b9f4 commit feaf9cd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
15 changes: 6 additions & 9 deletions generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand Down Expand Up @@ -98,17 +98,14 @@ pub struct Alias {

pub fn get_aliases(name_aliases: &'static str) -> Vec<Alias> {
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,
Expand Down
6 changes: 4 additions & 2 deletions generator/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
24 changes: 12 additions & 12 deletions src/jamo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>, &[u8]) {
if !a.is_empty() {
(Some(a[0]), &a[1..])
} else {
if a.is_empty() {
(None, a)
} else {
(Some(a[0]), &a[1..])
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@ pub fn character(search_name: &str) -> Option<char> {
} // 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,
}
}
Expand Down

0 comments on commit feaf9cd

Please sign in to comment.