diff options
| author | jan <jan@ruken.pw> | 2016-10-09 06:40:07 (UTC) |
|---|---|---|
| committer | jan <jan@ruken.pw> | 2016-10-09 06:40:07 (UTC) |
| commit | 54c2cb1e484e09b4fcfe236aff70c01bf3bbaae0 (patch) | |
| tree | 3483753fb061d32f32bbe0c1a609d4b760192e47 /src | |
| parent | b8b1da0a95635fe9ed4ba28851906556ccc351a8 (diff) | |
serien hinzugefuegt, aber ich muss auf die naechste rust nightly warten
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 6 | ||||
| -rw-r--r-- | src/series.rs | 63 |
2 files changed, 67 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 2b96024..7481376 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #![feature(rustc_macro)] | 1 | #![feature(proc_macro)] |
| 2 | #[macro_use] extern crate serde_derive; | 2 | #[macro_use] extern crate serde_derive; |
| 3 | extern crate serde_json; | 3 | extern crate serde_json; |
| 4 | 4 | ||
| @@ -22,6 +22,8 @@ mod section; | |||
| 22 | 22 | ||
| 23 | mod character; | 23 | mod character; |
| 24 | use character::Character; | 24 | use character::Character; |
| 25 | mod series; | ||
| 26 | use series::Series; | ||
| 25 | 27 | ||
| 26 | mod tags; | 28 | mod tags; |
| 27 | mod dl_list; | 29 | mod dl_list; |
| @@ -66,7 +68,7 @@ fn main() { | |||
| 66 | 68 | ||
| 67 | let buf = pre_process::strip_irrelevant_content(&buf); | 69 | let buf = pre_process::strip_irrelevant_content(&buf); |
| 68 | 70 | ||
| 69 | let mut char = Character::new(); | 71 | let mut char = Series::new(); |
| 70 | char.parse(&buf); | 72 | char.parse(&buf); |
| 71 | 73 | ||
| 72 | let json = serde_json::to_string(&char).unwrap(); | 74 | let json = serde_json::to_string(&char).unwrap(); |
diff --git a/src/series.rs b/src/series.rs new file mode 100644 index 0000000..d111fb8 --- /dev/null +++ b/src/series.rs | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | use super::tags; | ||
| 2 | use super::tags::Tag; | ||
| 3 | use super::dl_list; | ||
| 4 | use super::dl_list::DLListItem; | ||
| 5 | use super::section; | ||
| 6 | use super::section::Section; | ||
| 7 | use super::regex::Regex; | ||
| 8 | use super::tiles; | ||
| 9 | |||
| 10 | use std::collections::HashMap; | ||
| 11 | |||
| 12 | #[derive(Debug, Serialize)] | ||
| 13 | pub struct Names { | ||
| 14 | pub english: String, | ||
| 15 | pub aliases: String, | ||
| 16 | pub romaji: String, | ||
| 17 | pub furigana: String, | ||
| 18 | pub japanese: String, | ||
| 19 | } | ||
| 20 | |||
| 21 | #[derive(Debug, Serialize)] | ||
| 22 | pub struct Series { | ||
| 23 | pub name: Names, | ||
| 24 | } | ||
| 25 | |||
| 26 | impl Names { | ||
| 27 | pub fn new() -> Self { | ||
| 28 | Names { | ||
| 29 | String::new(), String::new(), String::new(), String::new(), String::new() | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | impl Series { | ||
| 35 | pub fn new() -> Self { | ||
| 36 | Series { | ||
| 37 | name: Names::new() | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | pub fn parse(&mut self, buf: &str) { | ||
| 42 | let mut sections = get_sections(); | ||
| 43 | section::process(&buf, &mut sections); | ||
| 44 | |||
| 45 | { | ||
| 46 | let name: &Section = §ions["name".into()]; | ||
| 47 | |||
| 48 | self.name.english = name["english".into()]; | ||
| 49 | self.name.aliases = name["aliases".into()]; | ||
| 50 | self.name.romaji = name["romaji".into()]; | ||
| 51 | self.name.furigana = name["furigana".into()]; | ||
| 52 | self.name.japanese = name["japanese".into()]; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | fn get_sections() -> HashMap<String, Section> { | ||
| 58 | let mut s: HashMap<String, Section> = HashMap::new(); | ||
| 59 | |||
| 60 | s.insert("name".into(), Section::new("name", r#"(?is)English Title.*?<TD>(.*?)</TD>.*?Aliases.*?<TD>(.*?)?</TD>.*?Romaji Title.*?<TD.*?>(.*?)</TD>.*?Furigana Title.*?<TD.*?>(.*?)</TD>.*?Japanese Title.*?<TD.*?>(.*?)</TD>"#, vec!["english", "aliases", "romaji", "furigana", "japanese"])); | ||
| 61 | |||
| 62 | s | ||
| 63 | } | ||
