Source

Resharper Spell Checker / ReSpeller / SpellEngine / Dictionaries / HunspellEngine.cs

Full commit
using System.Collections.Generic;
using System.IO;
using NHunspell;

namespace ReSpeller.SpellEngine.Dictionaries
{
  public class HunspellEngine : IDictionaryEngine
  {
    private readonly Hunspell myHunspell;

    public static string NativeDllPath
    {
      get { return Hunspell.NativeDllPath; }
      set { Hunspell.NativeDllPath = value; }
    }

    public HunspellEngine(string affixFile, string dictFile)
    {
      myHunspell = new Hunspell(affixFile, dictFile);
    }

    public bool Check(string word)
    {
      return myHunspell.Spell(word);
    }

    public List<string> Suggest(string word)
    {
      return myHunspell.Suggest(word);
    }

    public void Add(string word)
    {
      myHunspell.Add(word);
    }

    public void AddRange(IEnumerable<string> words)
    {
      foreach (var word in words)
      {
        myHunspell.Add(word);
      }
    }

    public void Dispose()
    {
      if (myHunspell != null && !myHunspell.IsDisposed)
        myHunspell.Dispose();
    }

    public static HunspellEngine CreateForLanguage(string dictDir, string language)
    {
      string dictFile = Path.Combine(dictDir, language + "." + Constants.HunspellDictExt);
      string affixFile = Path.Combine(dictDir, language + "." + Constants.HunspellAffixExt);
      return new HunspellEngine(affixFile, dictFile);
    }
  }
}