Am 17.11.2010 um 23:02 schrieb Enrico Forestieri:

> On Wed, Nov 17, 2010 at 04:19:34PM -0500, Richard Heck wrote:
>> On 11/17/2010 03:48 PM, Enrico Forestieri wrote:
>>> 
>>> As regards the other isxxx() tests, I suggest to audit them on an as
>>> needed basis, according to what the posix standard says:
>>> http://www.opengroup.org/onlinepubs/9699919799/mindex.html
>>> (click on the "Alphabetic index" link at the bottom for accessing the
>>> relevant man page).
>>> 
>> Both those were ones I introduced, ignorant as I am about these
>> sorts of issues. So I've fixed them both, I think, but I'd appreciate
>> if you'd have a look at r36351.
> 
> Looks OK to me. However, in lstrings.cpp we also have isAlphaASCII()
> and isDigitASCII() tests that could be used. I think they convey the
> real intention more clearly and could be combined for getting a
> isAlnumASCII() test, too.

There is a patch pending from Georg.
I present it here again and propose to apply it.

The second part of the patch is mine.
It encapsulates the crucial hasDigit into an ignoreWord() method to
prepare to solve the FIXME and to propose an alternate implementation.

The latter is not that important...

Stephan

Index: src/support/lstrings.cpp
===================================================================
--- src/support/lstrings.cpp    (Revision 36657)
+++ src/support/lstrings.cpp    (Arbeitskopie)
@@ -265,7 +265,7 @@
 
        string::const_iterator end = tmpstr.end();
        for (; cit != end; ++cit)
-               if (!isdigit((*cit)))
+               if (!isDigitASCII(*cit))
                        return false;
 
        return true;
@@ -285,7 +285,7 @@
        string::const_iterator cit = tmpstr.begin();
        string::const_iterator end = tmpstr.end();
        for (; cit != end; ++cit)
-               if (!isdigit((*cit)))
+               if (!isDigitASCII(*cit))
                        return false;
 
        return true;
@@ -309,7 +309,7 @@
                ++cit;
        string::const_iterator end = tmpstr.end();
        for (; cit != end; ++cit) {
-               if (!isdigit(*cit) && *cit != '.')
+               if (!isDigitASCII(*cit) && *cit != '.')
                        return false;
                if ('.' == (*cit)) {
                        if (found_dot)
@@ -323,17 +323,11 @@
 
 bool hasDigit(docstring const & str)
 {
-       if (str.empty())
-               return false;
-
        docstring::const_iterator cit = str.begin();
        docstring::const_iterator const end = str.end();
-       for (; cit != end; ++cit) {
-               if (*cit == ' ')
-                       continue;
-               if (isdigit((*cit)))
+       for (; cit != end; ++cit)
+               if (isDigit(*cit))
                        return true;
-       }
        return false;
 }
 
Index: src/Paragraph.cpp
===================================================================
--- src/Paragraph.cpp   (Revision 36657)
+++ src/Paragraph.cpp   (Arbeitskopie)
@@ -358,6 +358,8 @@
                return speller_change_number > 
speller_state_.currentChangeNumber();
        }
 
+       bool ignoreWord(docstring const & word) const ;
+       
        void setMisspelled(pos_type from, pos_type to, SpellChecker::Result 
state)
        {
                pos_type textsize = owner_->size();
@@ -3545,6 +3547,21 @@
 }
 
 
+bool Paragraph::Private::ignoreWord(docstring const & word) const
+{
+       // Ignore words with digits
+       // FIXME: make this customizable
+       // (note that some checkers ignore words with digits by default)
+       docstring::const_iterator cit = word.begin();
+       docstring::const_iterator const end = word.end();
+       for (; cit != end; ++cit) {
+               if (iswdigit((*cit)))
+                       return true;
+       }
+       return false;
+}
+
+
 SpellChecker::Result Paragraph::spellCheck(pos_type & from, pos_type & to,
        WordLangTuple & wl, docstring_list & suggestions,
        bool do_suggestion, bool check_learned) const
@@ -3570,10 +3587,7 @@
                return result;
 
        if (needsSpellCheck() || check_learned) {
-               // Ignore words with digits
-               // FIXME: make this customizable
-               // (note that some checkers ignore words with digits by default)
-               if (!hasDigit(word)) {
+               if (!d->ignoreWord(word)) {
                        bool const trailing_dot = to < size() && d->text_[to] 
== '.';
                        result = speller->check(wl);
                        if (SpellChecker::misspelled(result) && trailing_dot) {
 

Reply via email to