kradfile utf8
This commit is contained in:
parent
6efeb0498c
commit
a08636b3ee
4 changed files with 6503 additions and 1 deletions
6455
src-tauri/data/kradfile.utf8
Normal file
6455
src-tauri/data/kradfile.utf8
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1 +0,0 @@
|
|||
CREATE DATABASE
|
43
src-tauri/database-maker/src/kradfile.rs
Normal file
43
src-tauri/database-maker/src/kradfile.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
use sqlx::SqlitePool;
|
||||
use tokio::{
|
||||
fs::File,
|
||||
io::{AsyncBufReadExt, BufReader},
|
||||
};
|
||||
|
||||
const SEPARATOR: char = ':';
|
||||
|
||||
pub async fn process_kradfile(pool: &SqlitePool, path: impl AsRef<Path>) -> Result<()> {
|
||||
let file = File::open(path.as_ref()).await?;
|
||||
|
||||
let file_reader = BufReader::new(file);
|
||||
let mut lines = file_reader.lines();
|
||||
|
||||
loop {
|
||||
let line = match lines.next_line().await? {
|
||||
Some(v) => v,
|
||||
None => break,
|
||||
};
|
||||
|
||||
// Skip comments
|
||||
if line.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let parts = line.split(SEPARATOR).collect::<Vec<_>>();
|
||||
let (kanji, radicals) = match &parts[..] {
|
||||
&[kanji, radicals] => {
|
||||
let kanji = kanji.trim();
|
||||
let radicals = radicals.trim().split_whitespace().collect::<Vec<_>>();
|
||||
(kanji, radicals)
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
println!("kanji: {}, radicals: {:?}", kanji, radicals);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
pub mod kradfile;
|
||||
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
|
||||
use anyhow::Result;
|
||||
|
@ -26,6 +28,9 @@ async fn main() -> Result<()> {
|
|||
// Migrate that shit
|
||||
sqlx::migrate!().run(&pool).await?;
|
||||
|
||||
// Kradfile
|
||||
kradfile::process_kradfile(&pool, opt.in_dir.join("kradfile.utf8")).await?;
|
||||
|
||||
println!("Hello, world!");
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue