aboutsummaryrefslogtreecommitdiff
path: root/src/format.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-03-15 17:36:55 +0100
committerAlex Auvolat <alex@adnab.me>2024-03-15 17:36:55 +0100
commit4cd9081dc3a41594174480c1565fd2427550c50a (patch)
tree8a09db13b11477eaba40fa1a12347015738a5f8d /src/format.rs
parentf6a778698b8f0b709a7afa693ab42f8a0c314fe7 (diff)
downloaddatagengo-4cd9081dc3a41594174480c1565fd2427550c50a.tar.gz
datagengo-4cd9081dc3a41594174480c1565fd2427550c50a.zip
reduce memory usage & fix scroll to top
Diffstat (limited to 'src/format.rs')
-rw-r--r--src/format.rs28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/format.rs b/src/format.rs
index b9da487..3f10f8f 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -11,16 +11,16 @@ use crate::*;
// FORMATTING TO HTML
// =====================================================================
-pub fn format_batch<'a>(dict_idx: &DictIndex<'a>, count: usize, (i, batch): (usize, &Batch)) {
+pub fn format_batch(dict_idx: &DictIndex, count: usize, (i, batch): (usize, &Batch)) {
let mut f = io::BufWriter::new(
fs::File::create(format!("public/{:03}.html", i)).expect("create batch file"),
);
format_batch_to(&mut f, dict_idx, count, i, batch).expect("format batch");
}
-pub fn format_batch_to<'a>(
+pub fn format_batch_to(
buf: &mut impl Write,
- dict_idx: &DictIndex<'a>,
+ dict_idx: &DictIndex,
count: usize,
i: usize,
batch: &Batch,
@@ -200,32 +200,22 @@ fn format_vocab(buf: &mut impl Write, vocab: &[&JlptVocab], t: &str) -> Result<(
Ok(())
}
-fn dict_str_short<'a>(
- qkeb: &str,
- qreb: Option<&str>,
- ent: &roxmltree::Node<'a, 'a>,
-) -> Option<String> {
- let r_ele = ent.children().find(|x| x.has_tag_name("r_ele")).unwrap();
- let reb = r_ele.children().find(|x| x.has_tag_name("reb")).unwrap();
- let reb = reb.text().unwrap().trim();
-
- if qreb.map(|x| x != reb).unwrap_or(false) {
+fn dict_str_short<'a>(qkeb: &str, qreb: Option<&str>, ent: &DictEntry) -> Option<String> {
+ if qreb.map(|x| x != ent.reb).unwrap_or(false) {
return None;
}
Some(format!(
r#"<span class="font_ja">{} 【{}】</span>"#,
- qkeb, reb
+ qkeb, ent.reb
))
}
-fn dict_str<'a>(qkeb: &str, qreb: Option<&str>, ent: &roxmltree::Node<'a, 'a>) -> Option<String> {
+fn dict_str<'a>(qkeb: &str, qreb: Option<&str>, ent: &DictEntry) -> Option<String> {
let mut ret = dict_str_short(qkeb, qreb, ent)?;
- for sense in ent.children().filter(|x| x.has_tag_name("sense")) {
- if let Some(s) = sense.children().find(|x| x.has_tag_name("gloss")) {
- ret.extend(format!(" {};", s.text().unwrap().trim()).chars());
- }
+ for sense in ent.sense.iter() {
+ ret += &format!(" {};", sense);
}
if ret.chars().rev().next() == Some(';') {