public bool good(string word) { bool result; using (AnsiMarshaller utf8Word = new AnsiMarshaller(word)) { result = (hunspell_spell(_hunspellSession, utf8Word.MarshalledValue) == 1); } return result; }
public Hunspell(string dirDll, string dirDic, string llengua) { if (_library == IntPtr.Zero) { string dll = Path.Combine(dirDll, "hunspell.dll"); if (!File.Exists(dll)) throw new Exception("No existeix el fitxer " + Path.GetFullPath(dll)); _library = LoadLibrary(dll); } using (AnsiMarshaller aff = new AnsiMarshaller(Path.Combine(dirDic, llengua + ".aff"))) using (AnsiMarshaller dic = new AnsiMarshaller(Path.Combine(dirDic, llengua + ".dic"))) { if (!File.Exists(aff.Value)) throw new Exception("No existeix el fitxer " + Path.GetFullPath(aff.Value)); if (!File.Exists(dic.Value)) throw new Exception("No existeix el fitxer " + Path.GetFullPath(dic.Value)); _hunspellSession = hunspell_initialize(aff.MarshalledValue, dic.MarshalledValue); if (_hunspellSession == IntPtr.Zero)//review: what would a failed session give us? throw new ApplicationException("Couldn't create hunspell session."); } }
public List<String> sugg(string word) { List<String> llista; using (AnsiMarshaller utf8word = new AnsiMarshaller(word)) { IntPtr slst = Marshal.AllocHGlobal(IntPtr.Size); int nSugg = hunspell_suggest(_hunspellSession, utf8word.MarshalledValue, slst); llista = AnsiMarshaller.MarshalFromAnsiArray(Marshal.ReadIntPtr(slst), nSugg); hunspell_suggest_free(_hunspellSession, nSugg, slst); Marshal.FreeHGlobal(slst); } return llista; }