diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-07-05 23:07:26 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-07-05 23:07:26 +0200 |
| commit | 4d577650f737daaeb477bbbd5ae2bad4f1121c38 (patch) | |
| tree | ac973541e0a2d7751af4ece5f7f639e739f81fcc /src/text/mod.rs | |
first sketch of indexer
Diffstat (limited to 'src/text/mod.rs')
| -rw-r--r-- | src/text/mod.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/text/mod.rs b/src/text/mod.rs new file mode 100644 index 0000000..4e1b9a4 --- /dev/null +++ b/src/text/mod.rs @@ -0,0 +1,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) +} |