mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 06:51:44 +00:00
Fix up the range of a misspelled word when the checked string contains
non-ASCII characters. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29643 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
976f23a3b3
commit
4f02b08fb2
1 changed files with 25 additions and 3 deletions
|
@ -30,8 +30,9 @@
|
|||
|
||||
// get the configuration.
|
||||
#include "config.h"
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <GNUstepBase/Unicode.h>
|
||||
|
||||
#ifdef HAVE_ASPELL_H
|
||||
#include <aspell.h>
|
||||
|
@ -63,6 +64,26 @@
|
|||
@end
|
||||
|
||||
@implementation GNUSpellChecker
|
||||
|
||||
static inline unsigned int
|
||||
uniLength(unsigned char *buf, unsigned int len)
|
||||
{
|
||||
unsigned int i, size;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (buf[i] >= 0x80)
|
||||
{
|
||||
if (GSToUnicode(0, &size, buf, len, NSUTF8StringEncoding, 0, 0))
|
||||
{
|
||||
len = size;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
- (NSRange)spellServer:(NSSpellServer *)sender
|
||||
findMisspelledWordInString:(NSString *)stringToCheck
|
||||
language:(NSString *)language
|
||||
|
@ -91,7 +112,8 @@ findMisspelledWordInString:(NSString *)stringToCheck
|
|||
|
||||
aspell_document_checker_process(checker, p, length);
|
||||
token = aspell_document_checker_next_misspelling(checker);
|
||||
r = NSMakeRange(token.offset,token.len);
|
||||
r = NSMakeRange(uniLength((unsigned char *)p, token.offset),
|
||||
uniLength((unsigned char *)p + token.offset, token.len));
|
||||
}
|
||||
#else
|
||||
NSLog(@"spellServer:findMisspelledWordInString:... invoked, spell server not configured.");
|
||||
|
|
Loading…
Reference in a new issue