Skip to content

Commit

Permalink
added: lot's of small fixes;
Browse files Browse the repository at this point in the history
  • Loading branch information
codybloemhard committed Aug 10, 2022
1 parent 8cd78eb commit 9049a17
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 56 deletions.
16 changes: 0 additions & 16 deletions example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,3 @@ characters = ["nano"]
["", "せい"],
]
transl = ["Shinonome Nano", "Robot highschool girl"]

# - picture 2
# - text 1
# - すいません <br/> はかせ
# - suimasen <br/> hakase
# - Sorry, hakasei
# - text 2
# - 朝食は自分で <br/> 作って下さい!!
# - ちょう・しょく・は・じ・ぶんで!! <br/> つく・って・くだ・さい!!
# - kyou shoku wa ji bunde!! <br/> tsukutte kudasai!!
# - Breakfast is on you. <br/> Please make it yourself!!
# - text 3
# - 東雲なの <br/> ロボ女子高生
# - しの・のめ・なの <br/> ロボ・じょ・し・こう・せい
# - shinonome nano <br/> robo joshi kousei
# - shinonome nano <br/> robot highschool girl
82 changes: 42 additions & 40 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ struct Chapter{
volume: usize,
chapter: usize,
title: String,
pic: Vec<Picture>,
pic: Vec<Pic>,
}

#[derive(Deserialize, Debug)]
struct Picture{
struct Pic{
nr: usize,
page: usize,
characters: Vec<String>,
characters: Option<Vec<String>>,
location: Option<String>,
text: Vec<Text>,
text: Option<Vec<Text>>,
}

#[derive(Deserialize, Debug)]
Expand All @@ -31,13 +31,13 @@ struct Text{
to: Option<String>,
lines: Vec<String>,
kmap: Option<Vec<[String; 2]>>,
transl: Vec<String>,
transl: Option<Vec<String>>,
}

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args{
#[clap(short, long, default_value = "file")]
#[clap(short, long, default_value = "stdout")]
outputmode: String,
#[clap(short, long)]
files: Vec<String>,
Expand Down Expand Up @@ -96,12 +96,12 @@ fn write_transcription(chapter: Chapter) -> String{
let _ = writeln!(md, "{}Page: {}", header(5), picture.page);
last_page = picture.page;
}
let _ = writeln!(md, "{}picture {}", bullet(1), picture.nr);
let _ = writeln!(md, "{}picture {}", bullet(0), picture.nr);

fn write_text(md: &mut String, ident: usize, text: &Text){
fn write_lines(md: &mut String, lines: &[String], rep: &str) {
for line in lines{
let _ = write!(md, "{} <br/> ", line.replace(" ", rep));
let _ = write!(md, "{} <br/> ", line.replace(' ', rep));
}
for _ in 0..7 { md.pop(); }
}
Expand All @@ -111,27 +111,29 @@ fn write_transcription(chapter: Chapter) -> String{
let _ = writeln!(md);
// kanji replacement
let mut replacements = Vec::new();
let mut map = HashMap::new();
if let Some(kmap) = &text.kmap{
let mut map = HashMap::new();
for [x, y] in kmap{
map.insert(x, y);
}
}
for line in &text.lines{
let mut replaced = String::new();
for c in line.chars(){
let s = c.to_string();
if let Some(replacement) = map.get(&s){
replaced.push_str(replacement);
} else {
replaced.push_str(&s);
for line in &text.lines{
let mut replaced = String::new();
for c in line.chars(){
let s = c.to_string();
if let Some(replacement) = map.get(&s){
replaced.push_str(replacement);
} else {
replaced.push_str(&s);
}
}
replacements.push(replaced);
}
replacements.push(replaced);
let _ = write!(md, "{}", bullet(ident + 1));
write_lines(md, &replacements, "");
let _ = writeln!(md);
} else {
replacements = text.lines.clone();
}
let _ = write!(md, "{}", bullet(ident + 1));
write_lines(md, &replacements, "");
let _ = writeln!(md);
// romanize
let mut romanizeds = Vec::new();
for rep in &replacements{
Expand All @@ -141,31 +143,34 @@ fn write_transcription(chapter: Chapter) -> String{
write_lines(md, &romanizeds, " ");
let _ = writeln!(md);
// translation
let _ = write!(md, "{}", bullet(ident + 1));
write_lines(md, &text.transl, " ");
let _ = writeln!(md);
if let Some(transl) = &text.transl{
let _ = write!(md, "{}", bullet(ident + 1));
write_lines(md, transl, " ");
let _ = writeln!(md);
}
}

if picture.text.len() == 1{
write_text(&mut md, 2, &picture.text[0]);
let text = if let Some(text) = picture.text{ text } else { continue; };
if text.len() == 1{
write_text(&mut md, 1, &text[0]);
} else {
for (n, text) in picture.text.iter().enumerate(){
let _ = writeln!(md, "{}text {}", bullet(2), n);
write_text(&mut md, 3, text);
for (n, text) in text.iter().enumerate(){
let _ = writeln!(md, "{}text {}", bullet(2), n + 1);
write_text(&mut md, 2, text);
}
}
}
md
}

fn header(rank: usize) -> String{
let mut temp = "#".repeat(rank).to_string();
temp.push_str(" ");
let mut temp = "#".repeat(rank);
temp.push(' ');
temp
}

fn bullet(ident: usize) -> String{
let mut temp = " ".repeat(ident).to_string();
let mut temp = " ".repeat(ident);
temp.push_str("- ");
temp
}
Expand Down Expand Up @@ -195,13 +200,10 @@ fn romanize(string: &str) -> String{
let a = chars[i];
let b = chars[i + 1];
let comb = format!("{}{}", a, b);
match Hepburn::from(&comb){
Hepburn::Roman(roman) => {
push(&mut res, &roman, &mut tsu, &mut prev);
i += 2;
continue;
},
_ => {},
if let Hepburn::Roman(roman) = Hepburn::from(&comb){
push(&mut res, &roman, &mut tsu, &mut prev);
i += 2;
continue;
}
let a = a.to_string();
match Hepburn::from(&a){
Expand Down

0 comments on commit 9049a17

Please sign in to comment.