Skip to content

Instantly share code, notes, and snippets.

@cbc02009
Last active May 16, 2022 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbc02009/2db21c1810912218ee0de136be979645 to your computer and use it in GitHub Desktop.
Save cbc02009/2db21c1810912218ee0de136be979645 to your computer and use it in GitHub Desktop.
code example for adding guesses to list of titles and authors
pub struct BookInfo {
pub titles: Vec<String>,
pub authors: Vec<String>,
}
fn populate_book_info(file_name: &str) -> BookInfo {
//binfo may have entries in titles or authors
//depending on regex results
let mut binfo = BookInfo::from(file_name);
let title = binfo.titles.get(0).cloned();
let auth1 = binfo.authors.get(0).cloned();
let auth2 = binfo.authors.get(1).cloned();
if let Some(t) = title {
if let Some(k) = translate_kana(&*t) {
binfo.authors.push(k);
}
if let Some(k) = translate_kanji(&*t) {
binfo.authors.push(k);
}
}
if let Some(a1) = auth1 {
if let Some(k) = translate_kana(&*a1) {
binfo.authors.push(k);
}
if let Some(k) = translate_kanji(&*a1) {
binfo.authors.push(k);
}
}
if let Some(a2) = auth2 {
if let Some(k) = translate_kanji(&*a2) {
binfo.authors.push(k);
}
if let Some(k) = translate_kanji(&*a2) {
binfo.authors.push(k);
}
}
binfo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment