Skip to content

Commit

Permalink
feat(capi): load embedded mini dictionary if system dictionaries were…
Browse files Browse the repository at this point in the history
… not found
  • Loading branch information
kanru committed Jul 14, 2024
1 parent e3caee6 commit f7c8369
Show file tree
Hide file tree
Showing 4 changed files with 7,030 additions and 7 deletions.
26 changes: 20 additions & 6 deletions capi/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ use std::{

use chewing::{
conversion::{ChewingEngine, Interval, SimpleEngine, Symbol},
dictionary::{Layered, SystemDictionaryLoader, UserDictionaryLoader},
dictionary::{
Dictionary, Layered, LoadDictionaryError, SystemDictionaryLoader, Trie,
UserDictionaryLoader,
},
editor::{
keyboard::{AnyKeyboardLayout, KeyCode, KeyboardLayout, Modifiers, Qwerty},
zhuyin_layout::{
DaiChien26, Et, Et26, GinYieh, Hsu, Ibm, KeyboardLayoutCompat, Pinyin, Standard,
SyllableEditor,
},
BasicEditor, CharacterForm, ConversionEngineKind, Editor, EditorKeyBehavior, LanguageMode,
LaxUserFreqEstimate, UserPhraseAddDirection,
AbbrevTable, BasicEditor, CharacterForm, ConversionEngineKind, Editor, EditorKeyBehavior,
LanguageMode, LaxUserFreqEstimate, SymbolSelector, UserPhraseAddDirection,
},
zhuyin::Syllable,
};
Expand Down Expand Up @@ -130,24 +133,35 @@ pub unsafe extern "C" fn chewing_new2(
let dictionaries = match dictionaries {
Ok(d) => d,
Err(e) => {
let builtin = Trie::new(&include_bytes!("../../data/mini.dat")[..]);
error!("Failed to load system dict: {e}");
return null_mut();
error!("Loading builtin minimum dictionary...");
if builtin.is_err() {
error!(
"Unable to load builtin dictionary: {}",
builtin.unwrap_err()
);
return null_mut();
}
vec![Box::new(builtin.unwrap()) as Box<dyn Dictionary>]
}
};
let abbrev = sys_loader.load_abbrev();
let abbrev = match abbrev {
Ok(abbr) => abbr,
Err(e) => {
error!("Failed to load abbrev table: {e}");
return null_mut();
error!("Loading empty table...");
AbbrevTable::new()
}
};
let sym_sel = sys_loader.load_symbol_selector();
let sym_sel = match sym_sel {
Ok(sym_sel) => sym_sel,
Err(e) => {
error!("Failed to load symbol table: {e}");
return null_mut();
error!("Loading empty table...");
SymbolSelector::new(b"".as_slice()).unwrap()
}
};
let user_dictionary = if userpath.is_null() {
Expand Down
Binary file added data/mini.dat
Binary file not shown.
Loading

0 comments on commit f7c8369

Please sign in to comment.