diff --git a/src/Layout.cpp b/src/Layout.cpp index 7f4925a8c3..b2d4d2e273 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -23,8 +23,9 @@ #include "support/lassert.h" #include "support/lstrings.h" #include "support/Messages.h" - #include "support/regex.h" +#include "support/textutils.h" + using namespace std; using namespace lyx::support; @@ -997,7 +998,7 @@ string Layout::defaultCSSClass() const docstring::const_iterator en = name().end(); for (; it != en; ++it) { char_type const c = *it; - if (c >= 0x80 || !isalnum(c)) { + if (!isAlphaASCII(c)) { if (d.empty()) // make sure we don't start with an underscore, // as that sometimes causes problems. diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index aa0bcb573e..8324104eed 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -28,6 +28,7 @@ #include "support/docstream.h" #include "support/gettext.h" #include "support/lstrings.h" +#include "support/textutils.h" using namespace lyx::support; using namespace std; @@ -114,8 +115,8 @@ docstring InsetRef::getFormattedCmd(docstring const & ref, // make sure the prefix is legal for a latex command int const len = prefix.size(); for (int i = 0; i < len; i++) { - char_type c = prefix[i]; - if (c >= 0x80 || !isalpha(prefix[i])) { + char_type const c = prefix[i]; + if (!isAlphaASCII(c)) { LYXERR0("Prefix `" << prefix << "' is invalid for LaTeX."); // restore the label label = ref; diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp index 40759cea40..d8299ce5c4 100644 --- a/src/output_xhtml.cpp +++ b/src/output_xhtml.cpp @@ -32,6 +32,7 @@ #include "support/debug.h" #include "support/lassert.h" #include "support/lstrings.h" +#include "support/textutils.h" #include @@ -130,8 +131,7 @@ docstring cleanAttr(docstring const & str) docstring::const_iterator en = str.end(); for (; it != en; ++it) { char_type const c = *it; - bool const is_alnum = c < 0x80 && isalnum(c); - newname += is_alnum ? c : char_type('_'); + newname += isAlnumASCII(c) ? c : char_type('_'); } return newname; } diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index daa862747c..74950b397f 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -161,6 +161,14 @@ bool isDigitASCII(char_type c) return '0' <= c && c <= '9'; } + +bool isAlnumASCII(char_type c) +{ + return ('0' <= c && c <= '9') + || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); +} + + namespace support { int compare_no_case(docstring const & s, docstring const & s2) diff --git a/src/support/textutils.h b/src/support/textutils.h index e1a3063d82..99594f32c3 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -47,6 +47,9 @@ bool isDigit(char_type c); /// return whether \p c is a digit in the ASCII range bool isDigitASCII(char_type c); +/// return whether \p c is alpha or a digit in the ASCII range +bool isAlnumASCII(char_type c); + } // namespace lyx #endif // TEXTUTILS_H