Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate dictionary lookup logic #7

Closed
eagleflo opened this issue Nov 19, 2020 · 0 comments
Closed

Deduplicate dictionary lookup logic #7

eagleflo opened this issue Nov 19, 2020 · 0 comments

Comments

@eagleflo
Copy link
Owner

There's a fair bit of duplicated logic depending on which dictionary is being consulted in

jisho/src/lib.rs

Lines 52 to 76 in 425b409

if is_japanese(&first) {
if j2e.contains_key(input) {
let (reb, gloss) = j2e.get(input).unwrap();
println!("{}【{}】- {}", input, reb, gloss);
} else {
for key in j2e.keys() {
if key.starts_with(input) {
let (reb, gloss) = j2e.get(key).unwrap();
println!("{}【{}】- {}", input, reb, gloss);
}
}
}
} else {
if e2j.contains_key(input) {
let (keb, reb) = e2j.get(input).unwrap();
println!("{}【{}】- {}", keb, reb, input);
} else {
for key in e2j.keys() {
if key.starts_with(input) {
let (keb, reb) = e2j.get(key).unwrap();
println!("{}【{}】- {}", keb, reb, key);
}
}
}
}

By clearly setting up keb, reb and gloss it should be possible to cut that down in half.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant