1pub mod checker;
17pub mod config;
18pub mod corrections;
19pub mod dictionary;
20pub mod issue;
21pub mod japanese;
22pub mod registry_lock;
23mod syntax;
24pub mod tokenizer;
25
26pub use checker::Checker;
27pub use config::{Config, LoadedConfig, Mode};
28pub use issue::{Issue, IssueKind};
29
30use std::path::PathBuf;
31
32fn configured_dir(variable: &str) -> Option<PathBuf> {
33 std::env::var_os(variable)
34 .filter(|value| !value.is_empty())
35 .map(PathBuf::from)
36}
37
38pub fn cache_dir() -> Option<PathBuf> {
40 configured_dir("AYAME_SPELL_CACHE_DIR")
41 .or_else(|| dirs::cache_dir().map(|directory| directory.join("ayame-spell")))
42}
43
44pub fn registry_cache_dir() -> Option<PathBuf> {
47 cache_dir().map(|directory| directory.join("dicts"))
48}
49
50pub fn registry_cache_path(name: &str) -> Option<PathBuf> {
53 registry_cache_dir().map(|d| d.join(format!("{name}.txt")))
54}
55
56pub fn registry_index_cache_path() -> Option<PathBuf> {
58 cache_dir().map(|directory| directory.join("index.json"))
59}
60
61pub fn scan_cache_dir() -> Option<PathBuf> {
63 cache_dir().map(|directory| directory.join("scan"))
64}
65
66pub fn completion_words_cache_path() -> Option<PathBuf> {
68 cache_dir().map(|directory| directory.join("completion-words.json"))
69}
70
71pub fn global_config_dir() -> Option<PathBuf> {
74 configured_dir("AYAME_SPELL_CONFIG_DIR")
75 .or_else(|| dirs::config_dir().map(|d| d.join("ayame-spell")))
76}
77
78pub fn global_words_path() -> Option<PathBuf> {
80 global_config_dir().map(|d| d.join("words.txt"))
81}