Applied patch from Hawke for hunxpell suggestions (linux/mac) - thx Hawke

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@414 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2011-04-28 07:15:38 +00:00
parent 0beaf3ca7d
commit 54338f3e50
2 changed files with 16 additions and 34 deletions

View File

@ -36,29 +36,20 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
public override List<string> Suggest(string word)
{
IntPtr pointerToAddressStringArray = Marshal.AllocHGlobal(IntPtr.Size);
int resultCount = Hunspell_suggest(_hunspellHandle, pointerToAddressStringArray, word);
IntPtr addressStringArray = Marshal.ReadIntPtr(pointerToAddressStringArray);
List<string> results = new List<string>();
for (int i = 0; i < resultCount; i++)
{
IntPtr addressCharArray = Marshal.ReadIntPtr(addressStringArray, i * 4);
int offset = 0;
List<byte> bytesList = new List<byte>();
byte newByte = Marshal.ReadByte(addressCharArray, offset++);
while (newByte != 0)
{
bytesList.Add(newByte);
newByte = Marshal.ReadByte(addressCharArray, offset++);
}
byte[] bytesArray = new byte[offset];
bytesList.CopyTo(bytesArray);
string suggestion = System.Text.Encoding.UTF8.GetString(bytesArray);
results.Add(suggestion);
}
Hunspell_free_list(_hunspellHandle, pointerToAddressStringArray, resultCount);
Marshal.FreeHGlobal(pointerToAddressStringArray);
return results;
IntPtr pointerToAddressStringArray = Marshal.AllocHGlobal(IntPtr.Size);
int resultCount = Hunspell_suggest(_hunspellHandle, pointerToAddressStringArray, word);
IntPtr addressStringArray = Marshal.ReadIntPtr(pointerToAddressStringArray);
List<string> results = new List<string>();
for (int i = 0; i < resultCount; i++)
{
IntPtr addressCharArray = Marshal.ReadIntPtr(addressStringArray, i * 4);
string suggestion = Marshal.PtrToStringAuto(addressCharArray);
results.Add(suggestion);
}
Hunspell_free_list(_hunspellHandle, pointerToAddressStringArray, resultCount);
Marshal.FreeHGlobal(pointerToAddressStringArray);
return results;
}
~ LinuxHunspell()

View File

@ -43,21 +43,12 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
for (int i = 0; i < resultCount; i++)
{
IntPtr addressCharArray = Marshal.ReadIntPtr(addressStringArray, i * 4);
int offset = 0;
List<byte> bytesList = new List<byte>();
byte newByte = Marshal.ReadByte(addressCharArray, offset++);
while (newByte != 0)
{
bytesList.Add(newByte);
newByte = Marshal.ReadByte(addressCharArray, offset++);
}
byte[] bytesArray = new byte[offset];
bytesList.CopyTo(bytesArray);
string suggestion = System.Text.Encoding.UTF8.GetString(bytesArray);
string suggestion = Marshal.PtrToStringAuto(addressCharArray);
results.Add(suggestion);
}
Hunspell_free_list(_hunspellHandle, pointerToAddressStringArray, resultCount);
Marshal.FreeHGlobal(pointerToAddressStringArray);
return results;
}