mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Better way of doing these checks, suggested by Enrico.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36356 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d764a97cf4
commit
0940cd77d4
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "support/debug.h"
|
||||
#include "support/lassert.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/textutils.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user