mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +00:00
#7026 substitute isDigit() by isDigitASCII() and ditch isDigit(); introduce isNumber() and use it in spell checker; change isdigit() to isDigitASCII() otherwise
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36748 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
256b236675
commit
430d03811e
@ -24,6 +24,7 @@
|
|||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
#include "support/os.h"
|
#include "support/os.h"
|
||||||
#include "support/Systemcall.h"
|
#include "support/Systemcall.h"
|
||||||
|
#include "support/textutils.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ bool Format::isChildFormat() const
|
|||||||
{
|
{
|
||||||
if (name_.empty())
|
if (name_.empty())
|
||||||
return false;
|
return false;
|
||||||
return isdigit(name_[name_.length() - 1]);
|
return isDigitASCII(name_[name_.length() - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -358,6 +358,8 @@ public:
|
|||||||
return speller_change_number > speller_state_.currentChangeNumber();
|
return speller_change_number > speller_state_.currentChangeNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ignoreWord(docstring const & word) const ;
|
||||||
|
|
||||||
void setMisspelled(pos_type from, pos_type to, SpellChecker::Result state)
|
void setMisspelled(pos_type from, pos_type to, SpellChecker::Result state)
|
||||||
{
|
{
|
||||||
pos_type textsize = owner_->size();
|
pos_type textsize = owner_->size();
|
||||||
@ -2818,7 +2820,7 @@ bool Paragraph::isWordSeparator(pos_type pos) const
|
|||||||
char_type const c = d->text_[pos];
|
char_type const c = d->text_[pos];
|
||||||
// We want to pass the ' and escape chars to the spellchecker
|
// We want to pass the ' and escape chars to the spellchecker
|
||||||
static docstring const quote = from_utf8(lyxrc.spellchecker_esc_chars + '\'');
|
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();
|
|| pos == size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2828,7 +2830,7 @@ bool Paragraph::isChar(pos_type pos) const
|
|||||||
if (Inset const * inset = getInset(pos))
|
if (Inset const * inset = getInset(pos))
|
||||||
return inset->isChar();
|
return inset->isChar();
|
||||||
char_type const c = d->text_[pos];
|
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::needsSpellCheck() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
SpellChecker::Result Paragraph::spellCheck(pos_type & from, pos_type & to,
|
||||||
WordLangTuple & wl, docstring_list & suggestions,
|
WordLangTuple & wl, docstring_list & suggestions,
|
||||||
bool do_suggestion, bool check_learned) const
|
bool do_suggestion, bool check_learned) const
|
||||||
@ -3570,10 +3587,7 @@ SpellChecker::Result Paragraph::spellCheck(pos_type & from, pos_type & to,
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
if (needsSpellCheck() || check_learned) {
|
if (needsSpellCheck() || check_learned) {
|
||||||
// Ignore words with digits
|
if (!d->ignoreWord(word)) {
|
||||||
// FIXME: make this customizable
|
|
||||||
// (note that some checkers ignore words with digits by default)
|
|
||||||
if (!hasDigit(word)) {
|
|
||||||
bool const trailing_dot = to < size() && d->text_[to] == '.';
|
bool const trailing_dot = to < size() && d->text_[to] == '.';
|
||||||
result = speller->check(wl);
|
result = speller->check(wl);
|
||||||
if (SpellChecker::misspelled(result) && trailing_dot) {
|
if (SpellChecker::misspelled(result) && trailing_dot) {
|
||||||
|
@ -850,7 +850,7 @@ void Text::insertChar(Cursor & cur, char_type c)
|
|||||||
static docstring const number_seperators = from_ascii(".,:");
|
static docstring const number_seperators = from_ascii(".,:");
|
||||||
|
|
||||||
if (cur.current_font.fontInfo().number() == FONT_ON) {
|
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) &&
|
!(contains(number_seperators, c) &&
|
||||||
cur.pos() != 0 &&
|
cur.pos() != 0 &&
|
||||||
cur.pos() != cur.lastpos() &&
|
cur.pos() != cur.lastpos() &&
|
||||||
@ -858,7 +858,7 @@ void Text::insertChar(Cursor & cur, char_type c)
|
|||||||
tm.displayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON)
|
tm.displayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON)
|
||||||
)
|
)
|
||||||
number(cur); // Set current_font.number to OFF
|
number(cur); // Set current_font.number to OFF
|
||||||
} else if (isDigit(c) &&
|
} else if (isDigitASCII(c) &&
|
||||||
cur.real_current_font.isVisibleRightToLeft()) {
|
cur.real_current_font.isVisibleRightToLeft()) {
|
||||||
number(cur); // Set current_font.number to ON
|
number(cur); // Set current_font.number to ON
|
||||||
|
|
||||||
|
@ -555,13 +555,13 @@ namespace {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// check for field type
|
// check for field type
|
||||||
if (isDigit(ch)) {
|
if (isDigitASCII(ch)) {
|
||||||
|
|
||||||
// read integer value
|
// read integer value
|
||||||
do {
|
do {
|
||||||
val += ch;
|
val += ch;
|
||||||
ifs.get(ch);
|
ifs.get(ch);
|
||||||
} while (ifs && isDigit(ch));
|
} while (ifs && isDigitASCII(ch));
|
||||||
|
|
||||||
if (!ifs)
|
if (!ifs)
|
||||||
return false;
|
return false;
|
||||||
|
@ -768,7 +768,7 @@ void InsetListingsParams::addParam(string const & key,
|
|||||||
else {
|
else {
|
||||||
bool has_special_char = false;
|
bool has_special_char = false;
|
||||||
for (size_t i = 0; i < value.size(); ++i)
|
for (size_t i = 0; i < value.size(); ++i)
|
||||||
if (!isAlphaASCII(value[i]) && !isDigit(value[i])) {
|
if (!isAlnumASCII(value[i])) {
|
||||||
has_special_char = true;
|
has_special_char = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -753,9 +753,9 @@ private:
|
|||||||
bool isNumpunct(lyx::char_type const c) const
|
bool isNumpunct(lyx::char_type const c) const
|
||||||
{
|
{
|
||||||
/// Only account for the standard numpunct "C" locale facet.
|
/// Only account for the standard numpunct "C" locale facet.
|
||||||
return c < 0x80 && (c == '-' || c == '+' || isdigit(c)
|
return c == '-' || c == '+'
|
||||||
|| ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')
|
|| c == 'x' || c == 'X'
|
||||||
|| c == 'x' || c == 'X');
|
|| isHexChar(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ValueType>
|
template <typename ValueType>
|
||||||
|
@ -147,13 +147,13 @@ bool isSpace(char_type c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isDigit(char_type c)
|
bool isNumber(char_type c)
|
||||||
{
|
{
|
||||||
if (!is_utf16(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
|
// c outside the UCS4 range is catched as well
|
||||||
return false;
|
return false;
|
||||||
return ucs4_to_qchar(c).isDigit();
|
return ucs4_to_qchar(c).isNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -165,8 +165,7 @@ bool isDigitASCII(char_type c)
|
|||||||
|
|
||||||
bool isAlnumASCII(char_type c)
|
bool isAlnumASCII(char_type c)
|
||||||
{
|
{
|
||||||
return ('0' <= c && c <= '9')
|
return isAlphaASCII(c) || isDigitASCII(c);
|
||||||
|| ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -266,7 +265,7 @@ bool isStrInt(string const & str)
|
|||||||
|
|
||||||
string::const_iterator end = tmpstr.end();
|
string::const_iterator end = tmpstr.end();
|
||||||
for (; cit != end; ++cit)
|
for (; cit != end; ++cit)
|
||||||
if (!isdigit((*cit)))
|
if (!isDigitASCII(*cit))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -286,7 +285,7 @@ bool isStrUnsignedInt(string const & str)
|
|||||||
string::const_iterator cit = tmpstr.begin();
|
string::const_iterator cit = tmpstr.begin();
|
||||||
string::const_iterator end = tmpstr.end();
|
string::const_iterator end = tmpstr.end();
|
||||||
for (; cit != end; ++cit)
|
for (; cit != end; ++cit)
|
||||||
if (!isdigit((*cit)))
|
if (!isDigitASCII(*cit))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -310,7 +309,7 @@ bool isStrDbl(string const & str)
|
|||||||
++cit;
|
++cit;
|
||||||
string::const_iterator end = tmpstr.end();
|
string::const_iterator end = tmpstr.end();
|
||||||
for (; cit != end; ++cit) {
|
for (; cit != end; ++cit) {
|
||||||
if (!isdigit(*cit) && *cit != '.')
|
if (!isDigitASCII(*cit) && *cit != '.')
|
||||||
return false;
|
return false;
|
||||||
if ('.' == (*cit)) {
|
if ('.' == (*cit)) {
|
||||||
if (found_dot)
|
if (found_dot)
|
||||||
@ -322,19 +321,13 @@ bool isStrDbl(string const & str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool hasDigit(docstring const & str)
|
bool hasDigitASCII(docstring const & str)
|
||||||
{
|
{
|
||||||
if (str.empty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
docstring::const_iterator cit = str.begin();
|
docstring::const_iterator cit = str.begin();
|
||||||
docstring::const_iterator const end = str.end();
|
docstring::const_iterator const end = str.end();
|
||||||
for (; cit != end; ++cit) {
|
for (; cit != end; ++cit)
|
||||||
if (*cit == ' ')
|
if (isDigitASCII(*cit))
|
||||||
continue;
|
|
||||||
if (isdigit((*cit)))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ bool isStrUnsignedInt(std::string const & str);
|
|||||||
bool isStrDbl(std::string const & str);
|
bool isStrDbl(std::string const & str);
|
||||||
|
|
||||||
/// does the string contain a digit?
|
/// does the string contain a digit?
|
||||||
bool hasDigit(docstring const & str);
|
bool hasDigitASCII(docstring const & str);
|
||||||
|
|
||||||
bool isHex(docstring const & str);
|
bool isHex(docstring const & str);
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ bool isPrintableNonspace(char_type c);
|
|||||||
/// return true if a unicode char is a space.
|
/// return true if a unicode char is a space.
|
||||||
bool isSpace(char_type c);
|
bool isSpace(char_type c);
|
||||||
|
|
||||||
/// return true if a unicode char is a digit.
|
/// return true if a unicode char is a numeral.
|
||||||
bool isDigit(char_type c);
|
bool isNumber(char_type c);
|
||||||
|
|
||||||
/// return whether \p c is a digit in the ASCII range
|
/// return whether \p c is a digit in the ASCII range
|
||||||
bool isDigitASCII(char_type c);
|
bool isDigitASCII(char_type c);
|
||||||
|
Loading…
Reference in New Issue
Block a user