Crate ispell [] [src]

This library provides an interface for easily calling the ispell or aspell command from Rust programs.

Example

use ispell::SpellLauncher;
let mut checker = SpellLauncher::new()
                 .aspell()
                 .launch()
                 .unwrap();
let errors = checker.check("Testing iff if it works").unwrap();
assert_eq!(&errors[0].mispelled, "iff");Run

The SpellLauncher

You can set the command that will be called manually:

let result = SpellLauncher::new()
             .command("foo")
             .launch();Run

but the easiest way to set which alternative must be used is with the aspell and hunspell methods:

let result = SpellLauncher::new()
             .hunspell()
             .launch();Run

The SpellChecker

If the command has been launched successfully, it will return a SpellChecker. The main usage of this struct is to get the errors (IspellError) the spell checker detects with SpellChecker::check. The ispell API returns the position (in characters) from the beginning of the line. This means that, if you want to be able do to anything with these numbers, you'll have to call check line by line.

This method returns a list of IspellErrors, containing:

  • the mispelled word;
  • the position (number of characters since the beginning of the line);
  • a (possibly empty) list of suggestions.
let mut checker = SpellLauncher::new()
                  .launch()
                  .unwrap();
let errors = checker.check("Does thit message contain any erors?").unwrap();
for e in errors {
    println!("{} was mispelled at pos {}.", e.mispelled, e.position);
    println!("There are {} suggestions for alternatives", e.suggestions.len());
}Run

SpellChecker also provides the check_raw method, whose behaviour mimics more closely ispell's output.

Languages and encodings

ispell, aspell and hunspell all allow you to specify which dictionary must be used, but they don't necessarily use the same naming scheme. ispell uses full names:

let result = SpellLauncher::new()
             .dictionary("american")
             .launch();Run

hunspell uses unicode language codes:

let result = SpellLauncher::new()
             .hunspell()
             .dictionary("en_US")
             .launch();Run

whereas aspell accepts both versions.

Currently, no encoding is specified when runnig i/a/hun/spell, so, depending on the system you are using and the command you use, it is possible you'll encounter problems if you use non-ASCII characters.

Warning

This library hasn't been tested a lot yet. It tries to avoid panic!s but, unfortunately, since Reads are blocking, there is a risk that it will simply hang up infinitely (particularly if you use SpellLauncher::command(...) to launch a process that doesn't comply with the ispell API).

Structs

Error

Error type returned by methods of this library

IspellError

An ispell error, corresponding to a word that isn't in the dictonary.

SpellChecker

Spell Checker

SpellLauncher

Spell Launcher wizard (ah, ah). A builder for SpellChecker.

Enums

IspellResult

A result from ispell, corresponding to a line that is sent back for each word.

Type Definitions

Result

Result type (returned by most methods of this library)