Beispiel #1
0
        /// <summary>Returns suggested spellings for a word.</summary>
        public string[] Suggest(string word)
        {
            var suggestions = new List <string>();

            int    ptrSize = Marshal.SizeOf(typeof(IntPtr));
            IntPtr slst    = Marshal.AllocHGlobal(ptrSize);
            int    count   = HunspellInterop.Hunspell_suggest(handle, slst, word);

            if (count > 0)
            {
                IntPtr sa = Marshal.ReadIntPtr(slst);
                for (int i = 0;
                     i < count;
                     ++i)
                {
                    IntPtr sp         = Marshal.ReadIntPtr(sa, i * ptrSize);
                    string suggestion = Marshal.PtrToStringAuto(sp);
                    suggestions.Add(suggestion);
                }
                HunspellInterop.Hunspell_free_list(handle, slst, count);
            }

            Marshal.FreeHGlobal(slst);

            return(suggestions.ToArray());
        }
        public HunspellHandle(
            string affpath,
            string dicpath)
            : base(IntPtr.Zero, true)
        {
            handle = HunspellInterop.Hunspell_create(affpath, dicpath);

            if (IsInvalid)
            {
                throw new InvalidOperationException("Couldn't load hunspell.");
            }
        }
Beispiel #3
0
        public bool CheckWord(string word)
        {
            // If the word is mixed case or has numbers call it good.
            for (int i = 1;
                 i < word.Length;
                 ++i)
            {
                if (char.IsUpper(word[i]) ||
                    char.IsNumber(word[i]))
                {
                    return(true);
                }
            }

            int result = HunspellInterop.Hunspell_spell(handle, word);

            GC.KeepAlive(this);
            return(result != 0);
        }
        protected override bool ReleaseHandle()
        {
            HunspellInterop.Hunspell_destroy(this);

            return(true);
        }