Anfang der weitergeleiteten E-Mail: > Von: Enrico Forestieri <for...@lyx.org> > Datum: 5. Dezember 2010 01:49:25 MEZ > An: lyx-devel@lists.lyx.org > Betreff: Re: PATCH for ticket 7026 > > On Sat, Dec 04, 2010 at 09:37:09PM +0100, Stephan Witt wrote: > >> I made another patch for the topic. >> Enrico, Georg, do you have any plans yourself? > > I think you should also perform the substitution > isDigit() -> isDigitASCII() as they are duplicates, > and ditch the isDigit() implementation in lstrings.cpp
I don't know how to proceed - if I should do anything. 1) no action - leave the ticket open. 2) minimal solution - fix the crash and postpone the code cleanup. 3) do as Enrico proposed - that would imply touching - Text.cpp - Format.cpp - InsetListingsParams.cpp - InsetBibtex.cpp Stephan Possible patch for 2)
Index: src/support/lstrings.cpp =================================================================== --- src/support/lstrings.cpp (Revision 36744) +++ src/support/lstrings.cpp (Arbeitskopie) @@ -266,7 +266,7 @@ string::const_iterator end = tmpstr.end(); for (; cit != end; ++cit) - if (!isdigit((*cit))) + if (!isDigitASCII((*cit))) return false; return true; @@ -286,7 +286,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; @@ -310,7 +310,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) @@ -330,9 +330,7 @@ docstring::const_iterator cit = str.begin(); docstring::const_iterator const end = str.end(); for (; cit != end; ++cit) { - if (*cit == ' ') - continue; - if (isdigit((*cit))) + if (isDigitASCII((*cit))) return true; } return false;
Possible patch for 3)
Index: src/support/lstrings.h =================================================================== --- src/support/lstrings.h (Revision 36720) +++ src/support/lstrings.h (Arbeitskopie) @@ -45,7 +45,7 @@ bool isStrDbl(std::string const & str); /// does the string contain a digit? -bool hasDigit(docstring const & str); +bool hasDigitASCII(docstring const & str); bool isHex(docstring const & str); Index: src/support/textutils.h =================================================================== --- src/support/textutils.h (Revision 36720) +++ src/support/textutils.h (Arbeitskopie) @@ -41,8 +41,8 @@ /// return true if a unicode char is a space. bool isSpace(char_type c); -/// return true if a unicode char is a digit. -bool isDigit(char_type c); +/// return true if a unicode char is a numeral. +bool isNumber(char_type c); /// return whether \p c is a digit in the ASCII range bool isDigitASCII(char_type c); Index: src/support/lstrings.cpp =================================================================== --- src/support/lstrings.cpp (Revision 36720) +++ src/support/lstrings.cpp (Arbeitskopie) @@ -147,13 +147,13 @@ } -bool isDigit(char_type c) +bool isNumber(char_type c) { if (!is_utf16(c)) - // assume that no non-utf16 character is a digit + // assume that no non-utf16 character is a numeral // c outside the UCS4 range is catched as well return false; - return ucs4_to_qchar(c).isDigit(); + return ucs4_to_qchar(c).isNumber(); } @@ -165,8 +165,7 @@ bool isAlnumASCII(char_type c) { - return ('0' <= c && c <= '9') - || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); + return isAlphaASCII(c) || isDigitASCII(c); } @@ -266,7 +265,7 @@ string::const_iterator end = tmpstr.end(); for (; cit != end; ++cit) - if (!isdigit((*cit))) + if (!isDigitASCII(*cit)) return false; return true; @@ -286,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; @@ -310,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) @@ -322,19 +321,13 @@ } -bool hasDigit(docstring const & str) +bool hasDigitASCII(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 (isDigitASCII(*cit)) return true; - } return false; } Index: src/support/docstring.cpp =================================================================== --- src/support/docstring.cpp (Revision 36720) +++ src/support/docstring.cpp (Arbeitskopie) @@ -753,9 +753,9 @@ bool isNumpunct(lyx::char_type const c) const { /// Only account for the standard numpunct "C" locale facet. - return c < 0x80 && (c == '-' || c == '+' || isdigit(c) - || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F') - || c == 'x' || c == 'X'); + return c == '-' || c == '+' + || c == 'x' || c == 'X' + || isHexChar(c); } template <typename ValueType> Index: src/insets/InsetListingsParams.cpp =================================================================== --- src/insets/InsetListingsParams.cpp (Revision 36720) +++ src/insets/InsetListingsParams.cpp (Arbeitskopie) @@ -768,7 +768,7 @@ else { bool has_special_char = false; for (size_t i = 0; i < value.size(); ++i) - if (!isAlphaASCII(value[i]) && !isDigit(value[i])) { + if (!isAlnumASCII(value[i])) { has_special_char = true; break; } Index: src/insets/InsetBibtex.cpp =================================================================== --- src/insets/InsetBibtex.cpp (Revision 36720) +++ src/insets/InsetBibtex.cpp (Arbeitskopie) @@ -555,13 +555,13 @@ return false; // check for field type - if (isDigit(ch)) { + if (isDigitASCII(ch)) { // read integer value do { val += ch; ifs.get(ch); - } while (ifs && isDigit(ch)); + } while (ifs && isDigitASCII(ch)); if (!ifs) return false; Index: src/Format.cpp =================================================================== --- src/Format.cpp (Revision 36720) +++ src/Format.cpp (Arbeitskopie) @@ -24,6 +24,7 @@ #include "support/lstrings.h" #include "support/os.h" #include "support/Systemcall.h" +#include "support/textutils.h" #include <algorithm> @@ -102,7 +103,7 @@ { if (name_.empty()) return false; - return isdigit(name_[name_.length() - 1]); + return isDigitASCII(name_[name_.length() - 1]); } Index: src/Text.cpp =================================================================== --- src/Text.cpp (Revision 36720) +++ src/Text.cpp (Arbeitskopie) @@ -850,7 +850,7 @@ static docstring const number_seperators = from_ascii(".,:"); if (cur.current_font.fontInfo().number() == FONT_ON) { - if (!isDigit(c) && !contains(number_operators, c) && + if (!isDigitASCII(c) && !contains(number_operators, c) && !(contains(number_seperators, c) && cur.pos() != 0 && cur.pos() != cur.lastpos() && @@ -858,7 +858,7 @@ tm.displayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON) ) number(cur); // Set current_font.number to OFF - } else if (isDigit(c) && + } else if (isDigitASCII(c) && cur.real_current_font.isVisibleRightToLeft()) { number(cur); // Set current_font.number to ON Index: src/Paragraph.cpp =================================================================== --- src/Paragraph.cpp (Revision 36720) +++ 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(); @@ -2818,7 +2820,7 @@ char_type const c = d->text_[pos]; // We want to pass the ' and escape chars to the spellchecker static docstring const quote = from_utf8(lyxrc.spellchecker_esc_chars + '\''); - return (!isLetterChar(c) && !isDigit(c) && !contains(quote, c)) + return (!isLetterChar(c) && !isDigitASCII(c) && !contains(quote, c)) || pos == size(); } @@ -2828,7 +2830,7 @@ if (Inset const * inset = getInset(pos)) return inset->isChar(); char_type const c = d->text_[pos]; - return !isLetterChar(c) && !isDigit(c) && !lyx::isSpace(c); + return !isLetterChar(c) && !isDigitASCII(c) && !lyx::isSpace(c); } @@ -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 (isNumber((*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) {