Beispiel #1
0
        /// <summary>
        /// Hyphenates the specified word.
        /// </summary>
        /// <param name="word">
        /// The word.
        /// </param>
        /// <returns>
        /// A <see cref="HyphenResult"/> object with data for simple and complex hyphenation
        /// </returns>
        public HyphenResult Hyphenate(string word)
        {
            if (this.unmanagedHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Dictionary is not loaded");
            }

            if (string.IsNullOrEmpty(word))
            {
                return(null);
            }

            IntPtr buffer = MarshalHunspellDll.HyphenHyphenate(this.unmanagedHandle, word);

            IntPtr hyphenatedWord = Marshal.ReadIntPtr(buffer);
            int    bufferOffset   = IntPtr.Size;

            IntPtr hyphenationPoints = Marshal.ReadIntPtr(buffer, bufferOffset);

            bufferOffset += IntPtr.Size;

            IntPtr hyphenationRep = Marshal.ReadIntPtr(buffer, bufferOffset);

            bufferOffset += IntPtr.Size;

            IntPtr hyphenationPos = Marshal.ReadIntPtr(buffer, bufferOffset);

            bufferOffset += IntPtr.Size;

            IntPtr hyphenationCut = Marshal.ReadIntPtr(buffer, bufferOffset);

            bufferOffset += IntPtr.Size;

            var hyphenationPointsArray = new byte[Math.Max(word.Length - 1, 1)];
            var hyphenationRepArray    = new string[Math.Max(word.Length - 1, 1)];
            var hyphenationPosArray    = new int[Math.Max(word.Length - 1, 1)];
            var hyphenationCutArray    = new int[Math.Max(word.Length - 1, 1)];

            for (int i = 0; i < word.Length - 1; ++i)
            {
                hyphenationPointsArray[i] = Marshal.ReadByte(hyphenationPoints, i);
                if (hyphenationRep != IntPtr.Zero)
                {
                    IntPtr repString = Marshal.ReadIntPtr(hyphenationRep, i * IntPtr.Size);
                    if (repString != IntPtr.Zero)
                    {
                        hyphenationRepArray[i] = Marshal.PtrToStringUni(repString);
                    }

                    hyphenationPosArray[i] = Marshal.ReadInt32(hyphenationPos, i * sizeof(int));
                    hyphenationCutArray[i] = Marshal.ReadInt32(hyphenationCut, i * sizeof(int));
                }
            }

            var result = new HyphenResult(Marshal.PtrToStringUni(hyphenatedWord), hyphenationPointsArray, hyphenationRepArray, hyphenationPosArray, hyphenationCutArray);

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Hyphenates the specified word.
        /// </summary>
        /// <param name="word">
        /// The word. 
        /// </param>
        /// <returns>
        /// A <see cref="HyphenResult"/> object with data for simple and complex hyphenation 
        /// </returns>
        public HyphenResult Hyphenate(string word)
        {
            if (this.unmanagedHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Dictionary is not loaded");
            }

            if (string.IsNullOrEmpty(word))
            {
                return null;
            }

            IntPtr buffer = MarshalHunspellDll.HyphenHyphenate(this.unmanagedHandle, word);

            IntPtr hyphenatedWord = Marshal.ReadIntPtr(buffer);
            int bufferOffset = IntPtr.Size;

            IntPtr hyphenationPoints = Marshal.ReadIntPtr(buffer, bufferOffset);
            bufferOffset += IntPtr.Size;

            IntPtr hyphenationRep = Marshal.ReadIntPtr(buffer, bufferOffset);
            bufferOffset += IntPtr.Size;

            IntPtr hyphenationPos = Marshal.ReadIntPtr(buffer, bufferOffset);
            bufferOffset += IntPtr.Size;

            IntPtr hyphenationCut = Marshal.ReadIntPtr(buffer, bufferOffset);
            bufferOffset += IntPtr.Size;

            var hyphenationPointsArray = new byte[Math.Max(word.Length - 1, 1)];
            var hyphenationRepArray = new string[Math.Max(word.Length - 1, 1)];
            var hyphenationPosArray = new int[Math.Max(word.Length - 1, 1)];
            var hyphenationCutArray = new int[Math.Max(word.Length - 1, 1)];

            for (int i = 0; i < word.Length - 1; ++i)
            {
                hyphenationPointsArray[i] = Marshal.ReadByte(hyphenationPoints, i);
                if (hyphenationRep != IntPtr.Zero)
                {
                    IntPtr repString = Marshal.ReadIntPtr(hyphenationRep, i * IntPtr.Size);
                    if (repString != IntPtr.Zero)
                    {
                        hyphenationRepArray[i] = Marshal.PtrToStringUni(repString);
                    }

                    hyphenationPosArray[i] = Marshal.ReadInt32(hyphenationPos, i * sizeof(int));
                    hyphenationCutArray[i] = Marshal.ReadInt32(hyphenationCut, i * sizeof(int));
                }
            }

            var result = new HyphenResult(Marshal.PtrToStringUni(hyphenatedWord), hyphenationPointsArray, hyphenationRepArray, hyphenationPosArray, hyphenationCutArray);
            return result;
        }