Skip to content

Commit

Permalink
properly extract token
Browse files Browse the repository at this point in the history
  • Loading branch information
bnavetta committed Dec 20, 2014
1 parent f706696 commit 02e133b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions MacVoikko/CocoaVoikko.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ - (void)enumerateTokens:(NSString *)text withBlock:(TokenCallback)callback
while(tokenType != TOKEN_NONE)
{
tokenType = voikkoNextTokenCstr(handle, cText + offset, textLen, &tokenLen);
NSRange tokenRange = NSMakeRange(offset, tokenLen);
NSString* token = [text substringWithRange:tokenRange];

NSString* token = [[NSString alloc] initWithBytes:cText + offset length:tokenLen - offset encoding:NSUTF8StringEncoding];
BOOL keepGoing = callback(tokenType, token, NSMakeRange(offset, tokenLen));
// NSString* token = [[NSString alloc] initWithBytes:cText + offset length:tokenLen - offset encoding:NSUTF8StringEncoding];
BOOL keepGoing = callback(tokenType, token, tokenRange);

offset += tokenLen;

Expand All @@ -71,7 +73,7 @@ - (int)checkSpelling:(NSString *)word

- (NSRange)nextMisspelledWord:(NSString *)text wordCount:(NSInteger *)wordCount
{
__block NSRange range;
__block NSRange range = NSMakeRange(NSNotFound, 0);
__block int wc = 0;
[self enumerateTokens:text withBlock:^BOOL(enum voikko_token_type tokenType, NSString* token, NSRange tokenLoc) {
NSLog(@"Token '%@' of type %d at %@", token, tokenType, NSStringFromRange(tokenLoc));
Expand All @@ -81,6 +83,7 @@ - (NSRange)nextMisspelledWord:(NSString *)text wordCount:(NSInteger *)wordCount
int spelling = [self checkSpelling:token];
if(spelling == VOIKKO_SPELL_FAILED)
{
NSLog(@"Misspelled word '%@' at %@", token, NSStringFromRange(tokenLoc));
range = tokenLoc;
return NO;
}
Expand Down

0 comments on commit 02e133b

Please sign in to comment.