aboutsummaryrefslogtreecommitdiff
path: root/src/text/mod.rs
blob: 4e1b9a4cf7b7614a7d1b2aee9529e8254a57086e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use lazy_static::lazy_static;
use std::ffi::OsStr;
use std::path::Path;
use std::collections::HashMap;

mod txt;

fn empty_extractor(_ : &str) -> String {
    "".to_string()
}

macro_rules! ext {
    ($f:ident) => {(stringify!($f), $f::get_text as ExtFn)}
}

type ExtFn = fn(&str) -> String;

lazy_static! {
    static ref EXT: HashMap<&'static str, ExtFn> = {
        HashMap::from([
            ext!(txt),
        ])
    };
}


pub fn extract_text(path : &str) -> String {
    let p = Path::new(&path);
    let extenstion = p.extension().unwrap_or_else(|| OsStr::new("")).to_str().unwrap();
    EXT.get(extenstion).unwrap_or(&(empty_extractor as ExtFn))(path)
}