mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 14:32:35 +01:00
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:
parent
0beaf3ca7d
commit
54338f3e50
@ -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()
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user