Compare commits
No commits in common. "4ec6e32357ba93226f0ae0050c1d57d198f5db1a" and "770645cfdea5dcacd74f37aa084b3d69f7ff870b" have entirely different histories.
4ec6e32357
...
770645cfde
|
@ -1,19 +1,21 @@
|
|||
use std::fs;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::prelude::*;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub struct DictionaryEntry {
|
||||
struct Entry {
|
||||
hieroglyph: String,
|
||||
reading: String,
|
||||
translation: String,
|
||||
}
|
||||
|
||||
impl std::clone::Clone for DictionaryEntry {
|
||||
impl std::clone::Clone for Entry {
|
||||
fn clone(&self) -> Self {
|
||||
Self { hieroglyph: self.hieroglyph.clone(), reading: self.reading.clone(), translation: self.translation.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for DictionaryEntry {
|
||||
impl std::fmt::Display for Entry {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
|
@ -33,8 +35,8 @@ fn get_sym_pos_or_panic(path: &String, line: &str, sym: &str, line_number: usize
|
|||
}
|
||||
}
|
||||
|
||||
fn read_and_parse(path: &String) -> Vec<DictionaryEntry> {
|
||||
let mut result: Vec<DictionaryEntry> = Vec::new();
|
||||
fn read_and_parse(path: &String) -> Vec<Entry> {
|
||||
let mut result: Vec<Entry> = Vec::new();
|
||||
let content = fs::read_to_string(path).unwrap();
|
||||
|
||||
let content: Vec<&str> = content.split('\n').collect();
|
||||
|
@ -59,7 +61,7 @@ fn read_and_parse(path: &String) -> Vec<DictionaryEntry> {
|
|||
};
|
||||
let translation = line[translation_start..translation_end].to_string();
|
||||
|
||||
let entry = DictionaryEntry {
|
||||
let entry = Entry {
|
||||
hieroglyph,
|
||||
reading,
|
||||
translation,
|
||||
|
@ -70,9 +72,9 @@ fn read_and_parse(path: &String) -> Vec<DictionaryEntry> {
|
|||
result
|
||||
}
|
||||
|
||||
fn deduplicate (entries: &Vec<DictionaryEntry>) -> Vec<DictionaryEntry>{
|
||||
fn deduplicate (entries: &Vec<Entry>) -> Vec<Entry>{
|
||||
|
||||
let mut deduplicated:Vec<DictionaryEntry> = Vec::new();
|
||||
let mut deduplicated:Vec<Entry> = Vec::new();
|
||||
|
||||
for entry in entries.iter() {
|
||||
let mut is_dup = false;
|
||||
|
@ -95,26 +97,21 @@ fn deduplicate (entries: &Vec<DictionaryEntry>) -> Vec<DictionaryEntry>{
|
|||
deduplicated
|
||||
}
|
||||
|
||||
pub fn import(path: &String) -> Vec<DictionaryEntry>{
|
||||
pub fn import(path: &String) {
|
||||
let mut output = OpenOptions::new()
|
||||
.write(true)
|
||||
.append(true)
|
||||
.open("./reparsed-test.txt")
|
||||
.unwrap();
|
||||
let dictionary = read_and_parse(path);
|
||||
let dictionary = deduplicate(&dictionary);
|
||||
dictionary
|
||||
for entry in dictionary {
|
||||
if let Err(e) = writeln!(
|
||||
output,
|
||||
"({}) [{}] {{{}}}",
|
||||
entry.hieroglyph, entry.reading, entry.translation
|
||||
) {
|
||||
eprintln!("Couldn't write to file: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn write_to_file(path: &String, dict: &Vec<Entry>) {
|
||||
// let mut output = OpenOptions::new()
|
||||
// .write(true)
|
||||
// .append(true)
|
||||
// .open("./reparsed-test.txt")
|
||||
// .unwrap();
|
||||
|
||||
// for entry in dict {
|
||||
// if let Err(e) = writeln!(
|
||||
// output,
|
||||
// "({}) [{}] {{{}}}",
|
||||
// entry.hieroglyph, entry.reading, entry.translation
|
||||
// ) {
|
||||
// eprintln!("Couldn't write to file: {}", e);
|
||||
// }
|
||||
// }
|
||||
// }
|
|
@ -10,7 +10,7 @@ mod db;
|
|||
mod game;
|
||||
mod ui;
|
||||
mod widgets;
|
||||
mod dictionary;
|
||||
mod import;
|
||||
|
||||
use crate::ui::menu::MenuScene;
|
||||
|
||||
|
@ -39,9 +39,9 @@ const APP_ID: &str = "org.foxarmy.learn-hieroglyph";
|
|||
fn main() -> glib::ExitCode {
|
||||
gio::resources_register_include!("compiled.gresource").expect("Cannot include gresources");
|
||||
|
||||
db::init(); // Create database if not exists, create program's home if not exists, etc...
|
||||
db::init();
|
||||
|
||||
dictionary::import(&String::from("./reparsed.txt")); //
|
||||
import::import(&String::from("./reparsed.txt"));
|
||||
|
||||
let app: Application = Application::builder().application_id(APP_ID).build();
|
||||
|
||||
|
|
Loading…
Reference in New Issue