Am 01.09.2010 um 20:11 schrieb Stephan Witt:

> Am 01.09.2010 um 17:38 schrieb Jean-Marc LASGOUTTES:
> 
>> Stephan Witt <st.w...@gmx.net> writes:
>>> I've made some changes again... shorten lines as Jürgen suggested and
>>> formatting of if/while. And I added code to handle the soft-hyphens
>>> and friends.
>> 
>>> +int AppleSpellChecker::numMisspelledWords() const
>>> +{
>>> +   return numMisspelledWordsAppleSpeller(d->speller);
>>> +}
>> 
>> It might be nice, short of having proper objc++ files, to rename the
>> objc helper functions to something more obvious like
>> AppleSpeller_numMisspelledWords (or even AS_numMisspelledWords).
> 
> Yes, you're right. I'll change the names.

I'd like to commit the attached patch - changing the names only and adding the 
paragraph check feature for apple speller.

The Paragraph and Font changes I've left out because they seem controversial.

Any objections?

> What about replacing each character coming from the inset output by a
> discretionary hyphen (0x00ad)? Will the spellchecker correctly ignore
> it? In this case, this is a nice way of having strings of the same size.

This change would affect all callers of asString().
Would that be ok?

Stephan

Index: src/AppleSpellChecker.cpp
===================================================================
--- src/AppleSpellChecker.cpp   (Revision 35269)
+++ src/AppleSpellChecker.cpp   (Arbeitskopie)
@@ -78,8 +78,12 @@
 SpellChecker::Result AppleSpellChecker::check(WordLangTuple const & word)
 {
        string const word_str = to_utf8(word.word());
-       SpellCheckResult result = checkAppleSpeller(d->speller, 
word_str.c_str(), word.lang()->code().c_str());
-       LYXERR(Debug::GUI, "spellCheck: \"" << word.word() << "\" = " << 
d->toString(result)) ;
+       SpellCheckResult result =
+               AppleSpeller_check(d->speller,
+                       word_str.c_str(), word.lang()->code().c_str());
+       LYXERR(Debug::GUI, "spellCheck: \"" <<
+                  word.word() << "\" = " << d->toString(result) <<
+                  ", lang = " << word.lang()->code()) ;
        return d->toResult(result);
 }
 
@@ -88,7 +92,7 @@
 void AppleSpellChecker::insert(WordLangTuple const & word)
 {
        string const word_str = to_utf8(word.word());
-       learnAppleSpeller(d->speller, word_str.c_str());
+       AppleSpeller_learn(d->speller, word_str.c_str());
        LYXERR(Debug::GUI, "learn word: \"" << word.word() << "\"") ;
 }
 
@@ -97,7 +101,7 @@
 void AppleSpellChecker::remove(WordLangTuple const & word)
 {
        string const word_str = to_utf8(word.word());
-       unlearnAppleSpeller(d->speller, word_str.c_str());
+       AppleSpeller_unlearn(d->speller, word_str.c_str());
        LYXERR(Debug::GUI, "unlearn word: \"" << word.word() << "\"") ;
 }
 
@@ -106,7 +110,7 @@
 void AppleSpellChecker::accept(WordLangTuple const & word)
 {
        string const word_str = to_utf8(word.word());
-       ignoreAppleSpeller(d->speller, word_str.c_str());
+       AppleSpeller_ignore(d->speller, word_str.c_str());
 }
 
 
@@ -115,9 +119,9 @@
 {
        suggestions.clear();
        string const word_str = to_utf8(wl.word());
-       size_t num = makeSuggestionAppleSpeller(d->speller, word_str.c_str(), 
wl.lang()->code().c_str());
+       size_t num = AppleSpeller_makeSuggestion(d->speller, word_str.c_str(), 
wl.lang()->code().c_str());
        for (size_t i = 0; i < num; i++) {
-               char const * next = getSuggestionAppleSpeller(d->speller, i);
+               char const * next = AppleSpeller_getSuggestion(d->speller, i);
                if (!next) break;
                suggestions.push_back(from_utf8(next));
        }
@@ -126,10 +130,22 @@
 
 bool AppleSpellChecker::hasDictionary(Language const * lang) const
 {
-       return hasLanguageAppleSpeller(d->speller,lang->code().c_str());
+       return AppleSpeller_hasLanguage(d->speller,lang->code().c_str());
 }
 
 
+int AppleSpellChecker::numMisspelledWords() const
+{
+       return AppleSpeller_numMisspelledWords(d->speller);
+}
+
+
+void AppleSpellChecker::misspelledWord(int index, int & start, int & length) 
const
+{
+       AppleSpeller_misspelledWord(d->speller, index, &start, &length);
+}
+
+
 docstring const AppleSpellChecker::error()
 {
        return docstring();
Index: src/AppleSpellChecker.h
===================================================================
--- src/AppleSpellChecker.h     (Revision 35269)
+++ src/AppleSpellChecker.h     (Arbeitskopie)
@@ -30,6 +30,9 @@
        void remove(WordLangTuple const &);
        void accept(WordLangTuple const &);
        bool hasDictionary(Language const * lang) const;
+       bool canCheckParagraph() const { return true; }
+       int numMisspelledWords() const;
+       void misspelledWord(int index, int & start, int & length) const;
        docstring const error();
        //@}
 
Index: src/support/AppleSpeller.m
===================================================================
--- src/support/AppleSpeller.m  (Revision 35269)
+++ src/support/AppleSpeller.m  (Arbeitskopie)
@@ -84,7 +84,7 @@
 }
 
 
-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;
@@ -132,7 +132,7 @@
 }
 
 
-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 +144,7 @@
 }
 
 
-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 +184,7 @@
 }
 
 
-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 +194,7 @@
 }
 
 
-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 +209,7 @@
 }
 
 
-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 +224,21 @@
 }
 
 
-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];
+       NSRange range = [[speller->misspelled objectAtIndex:index] rangeValue];
        *start = range.location;
        *length = range.length;
 }
 
 
-int hasLanguageAppleSpeller(AppleSpeller speller, const char * lang)
+int AppleSpeller_hasLanguage(AppleSpeller speller, const char * lang)
 {
        return toLanguage(speller, lang) != nil;
 }
Index: src/support/AppleSpeller.h
===================================================================
--- src/support/AppleSpeller.h  (Revision 35269)
+++ src/support/AppleSpeller.h  (Arbeitskopie)
@@ -28,15 +28,15 @@
 AppleSpeller newAppleSpeller(void);
 void freeAppleSpeller(AppleSpeller speller);
 
-SpellCheckResult checkAppleSpeller(AppleSpeller speller, const char * word, 
const char * lang);
-void ignoreAppleSpeller(AppleSpeller speller, const char * word);
-size_t makeSuggestionAppleSpeller(AppleSpeller speller, const char * word, 
const char * lang);
-const char * getSuggestionAppleSpeller(AppleSpeller speller, size_t pos);
-void learnAppleSpeller(AppleSpeller speller, const char * word);
-void unlearnAppleSpeller(AppleSpeller speller, const char * word);
-int hasLanguageAppleSpeller(AppleSpeller speller, const char * lang);
-int numMisspelledWordsAppleSpeller(AppleSpeller speller);
-void misspelledWordAppleSpeller(AppleSpeller speller, int const position, int 
* start, int * length);
+SpellCheckResult AppleSpeller_check(AppleSpeller speller, const char * word, 
const char * lang);
+void AppleSpeller_ignore(AppleSpeller speller, const char * word);
+size_t AppleSpeller_makeSuggestion(AppleSpeller speller, const char * word, 
const char * lang);
+const char * AppleSpeller_getSuggestion(AppleSpeller speller, size_t pos);
+void AppleSpeller_learn(AppleSpeller speller, const char * word);
+void AppleSpeller_unlearn(AppleSpeller speller, const char * word);
+int AppleSpeller_hasLanguage(AppleSpeller speller, const char * lang);
+int AppleSpeller_numMisspelledWords(AppleSpeller speller);
+void AppleSpeller_misspelledWord(AppleSpeller speller, int index, int * start, 
int * length);
 
 #ifdef __cplusplus
 } // extern "C"
Index: src/SpellChecker.h
===================================================================
--- src/SpellChecker.h  (Revision 35269)
+++ src/SpellChecker.h  (Arbeitskopie)
@@ -55,7 +55,7 @@
 
        /// check the given word of the given lang code and return the result
        virtual enum Result check(WordLangTuple const &) = 0;
-       
+
        /// Gives suggestions.
        virtual void suggest(WordLangTuple const &, docstring_list & 
suggestions) = 0;
 
@@ -71,6 +71,22 @@
        /// check if dictionary exists
        virtual bool hasDictionary(Language const *) const = 0;
 
+       /// if speller can spell check whole paragraph return true
+       virtual bool canCheckParagraph() const { return false; }
+
+       /// count of misspelled words
+       virtual int numMisspelledWords() const { return 0; }
+
+       /// start position and length of misspelled word at index
+       virtual void misspelledWord(
+               int /* index */,
+               int & start, int & length) const
+       {
+               /// index is used here to make the compiler happy
+               start = 0;
+               length = 0;
+       }
+
        /// give an error message on messy exit
        virtual docstring const error() = 0;
 };

Reply via email to