JFLib

plat/spell.rs#

Source: lib/plat/spell.rs

spell -- the system's spell checker

  sys_spell_find(lang) -> Some(tag)   the checker of the system knows the language: the tag
                                   as it names it ("de-DE"); `lang` exactly, else the same
                                   language in its main region, else any region of it
  sys_spell_languages() -> tags    every language it knows
  SysSpeller::open(tag) -> checker   language(), check(word), suggest(word, max)
  hunspell_dirs() -> folders       where Hunspell dictionaries live here (DICPATH, Linux:
                                   the XDG data folders); the spell crate reads them
  hyphen_dirs() -> folders         where hyphenation patterns live here (Linux: hyphen in
                                   the XDG data folders); spell::Hyphenator reads them
  (both always readable for the app's permissions, policy.rs)

Windows (win_spell.rs): ISpellCheckerFactory / ISpellChecker of the Spell Checking API
(Windows 8 and later; the languages are the installed language packs).  COM on the calling
thread (an apartment of its own on the UI thread): a SysSpeller stays on the thread that
opened it (it is not Send).  check() reports a word as misspelled when ISpellChecker::Check
returns any error for it (also "replace" / "delete" actions); the user's Windows word list
counts as known.  macOS (apple_spell.rs): NSSpellChecker (its languages; the words the user
taught it count as known); iOS: UITextChecker (its languages, the words the user taught the
keyboard).  Linux, Web, Android: no system checker (None, empty) -- their Hunspell
dictionaries are files the spell crate reads itself.
  • struct SysSpeller a checker of the system's spell checking service for one language

  • fn hunspell_dirs() -> Vec<String> the folders of Hunspell dictionaries on this system, in search order: DICPATH (';' separated on Windows, ':' elsewhere), then on Linux $XDG_DATA_HOME/hunspell (~/.local/share/hunspell) and hunspell, myspell, myspell/dicts below every XDG_DATA_DIRS folder (default /usr/local/share, /usr/share); Web / Android: none. Always readable for the app's permissions (policy.rs), like the font folders.

  • fn hyphen_dirs() -> Vec<String> the system's folders of hyphenation patterns (hyph_*.dic, LibreOffice's format: Linux $XDG_DATA_HOME/hyphen (~/.local/share/hyphen), then hyphen in each of $XDG_DATA_DIRS (/usr/local/share, /usr/share) -- where the distributions' hyphen-* packages put them); empty elsewhere (Windows: spell::Hyphenator looks in LibreOffice's extensions itself)

  • fn sys_spell_find(lang: &str) -> Option<String> the tag of a language the system's checker knows (see the module header)

  • fn sys_spell_languages() -> Vec<String> every language the system's checker knows

impl SysSpeller

  • fn open(tag: &str) -> Option<SysSpeller> the checker for tag (a tag sys_spell_find gave), None when the system has none
  • fn language(&self) -> &str the language tag
  • fn check(&self, word: &str) -> bool the word is correct (an error of the service: true)
  • fn suggest(&self, word: &str, max: usize) -> Vec<String> corrections for the word (at most max)

Source: docs/API.md in the JFLib repository.