X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2FAppleSpeller.m;h=3e9a2f84529f286ab2174669fdd92e63567948e5;hb=faa87bf9f30b943397429a04254d96963bbf38bc;hp=810ee976024bf5208ae9cdf99788cba1667d368b;hpb=fa3c8d68945027151f41a3ea751a06ec88eeda14;p=lyx.git diff --git a/src/support/AppleSpeller.m b/src/support/AppleSpeller.m index 810ee97602..3e9a2f8452 100644 --- a/src/support/AppleSpeller.m +++ b/src/support/AppleSpeller.m @@ -8,7 +8,6 @@ * Full author contact details are available in file CREDITS. */ -#import #import #import @@ -69,7 +68,7 @@ static NSString * toLanguage(AppleSpeller speller, const char * lang) NSArray * languages = [speller->checker availableLanguages]; for (NSString *element in languages) { - if ([element isEqualToString:lang_]) { + if (0 == [element caseInsensitiveCompare:lang_]) { result = element; break; } else if ([lang_ hasPrefix:element]) { @@ -84,7 +83,7 @@ static NSString * toLanguage(AppleSpeller speller, const char * lang) } -SpellCheckResult checkAppleSpeller(AppleSpeller speller, const char * word, const char * lang) +SpellCheckResult AppleSpeller_check(AppleSpeller speller, const char * word, const char * lang) { if (!speller->checker || !lang || !word) return SPELL_CHECK_FAILED; @@ -94,16 +93,17 @@ SpellCheckResult checkAppleSpeller(AppleSpeller speller, const char * word, cons NSString * lang_ = toString(lang); SpellCheckResult result = SPELL_CHECK_FAILED; int start = 0; - + int length = [word_ length]; + [speller->misspelled release]; speller->misspelled = nil; - while (result == SPELL_CHECK_FAILED) { + while (result == SPELL_CHECK_FAILED && start < length) { NSRange match = [speller->checker checkSpellingOfString:word_ startingAt:start language:lang_ - wrap:NO + wrap:(BOOL)NO inSpellDocumentWithTag:speller->doctag wordCount:NULL]; @@ -114,7 +114,11 @@ SpellCheckResult checkAppleSpeller(AppleSpeller speller, const char * word, cons result = SPELL_CHECK_LEARNED; } } else { +#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050) + NSUInteger capacity = [speller->misspelled count] + 1; +#else int capacity = [speller->misspelled count] + 1; +#endif NSMutableArray * misspelled = [NSMutableArray arrayWithCapacity:capacity]; [misspelled addObjectsFromArray:speller->misspelled]; [misspelled addObject:[NSValue valueWithRange:match]]; @@ -132,7 +136,7 @@ SpellCheckResult checkAppleSpeller(AppleSpeller speller, const char * word, cons } -void ignoreAppleSpeller(AppleSpeller speller, const char * word) +void AppleSpeller_ignore(AppleSpeller speller, const char * word) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString * word_ = toString(word); @@ -144,7 +148,7 @@ void ignoreAppleSpeller(AppleSpeller speller, const char * word) } -size_t makeSuggestionAppleSpeller(AppleSpeller speller, const char * word, const char * lang) +size_t AppleSpeller_makeSuggestion(AppleSpeller speller, const char * word, const char * lang) { if (!speller->checker || !word || !lang) return 0; @@ -184,7 +188,7 @@ size_t makeSuggestionAppleSpeller(AppleSpeller speller, const char * word, const } -const char * getSuggestionAppleSpeller(AppleSpeller speller, size_t pos) +const char * AppleSpeller_getSuggestion(AppleSpeller speller, size_t pos) { const char * result = 0; if (pos < [speller->suggestions count]) { @@ -194,7 +198,7 @@ const char * getSuggestionAppleSpeller(AppleSpeller speller, size_t pos) } -void learnAppleSpeller(AppleSpeller speller, const char * word) +void AppleSpeller_learn(AppleSpeller speller, const char * word) { #if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050) NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; @@ -209,7 +213,7 @@ void learnAppleSpeller(AppleSpeller speller, const char * word) } -void unlearnAppleSpeller(AppleSpeller speller, const char * word) +void AppleSpeller_unlearn(AppleSpeller speller, const char * word) { #if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050) NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; @@ -224,21 +228,29 @@ void unlearnAppleSpeller(AppleSpeller speller, const char * word) } -int numMisspelledWordsAppleSpeller(AppleSpeller speller) +int AppleSpeller_numMisspelledWords(AppleSpeller speller) { return [speller->misspelled count]; } -void misspelledWordAppleSpeller(AppleSpeller speller, int const position, int * start, int * length) +void AppleSpeller_misspelledWord(AppleSpeller speller, int index, int * start, int * length) { - NSRange range = [[speller->misspelled objectAtIndex:position] rangeValue]; +#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050) + NSRange range = [[speller->misspelled objectAtIndex:(NSUInteger)index] rangeValue]; +#else + NSRange range = [[speller->misspelled objectAtIndex:index] rangeValue]; +#endif *start = range.location; *length = range.length; } -int hasLanguageAppleSpeller(AppleSpeller speller, const char * lang) +int AppleSpeller_hasLanguage(AppleSpeller speller, const char * lang) { +#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050) return toLanguage(speller, lang) != nil; +#else + return true; +#endif }