From 329d50d90d6c31750203835c4a4c09adcba8a7e6 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 2 Apr 2007 15:21:36 +0000 Subject: [PATCH] Use new isAlphaASCII and isDigitASCII functions instead of isalpha and isdigit from ctype.h, because the latter are locale dependant and do not work with char_type. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17698 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/InsetMath.C | 3 ++- src/mathed/InsetMathNest.C | 3 ++- src/mathed/InsetMathSymbol.C | 4 ++-- src/mathed/MathStream.C | 23 ++++------------------- src/sgml.C | 7 ++++--- src/support/textutils.C | 12 ++++++++++++ src/support/textutils.h | 6 ++++++ 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/mathed/InsetMath.C b/src/mathed/InsetMath.C index e44c384101..b1b46f2d47 100644 --- a/src/mathed/InsetMath.C +++ b/src/mathed/InsetMath.C @@ -18,6 +18,7 @@ #include "debug.h" #include "support/lstrings.h" +#include "support/textutils.h" #include @@ -77,7 +78,7 @@ void InsetMath::write(WriteStream & os) const os << "\\" << s; // We need an extra ' ' unless this is a single-char-non-ASCII name // or anything non-ASCII follows - if (s.size() != 1 || isalpha(s[0])) + if (s.size() != 1 || isAlphaASCII(s[0])) os.pendingSpace(true); } diff --git a/src/mathed/InsetMathNest.C b/src/mathed/InsetMathNest.C index 8488363616..335bf232b0 100644 --- a/src/mathed/InsetMathNest.C +++ b/src/mathed/InsetMathNest.C @@ -49,6 +49,7 @@ #include "undo.h" #include "support/lstrings.h" +#include "support/textutils.h" #include "frontends/Clipboard.h" #include "frontends/Painter.h" @@ -1228,7 +1229,7 @@ bool InsetMathNest::interpretChar(LCursor & cur, char_type c) return true; } - if (isalpha(c)) { + if (isAlphaASCII(c)) { cur.activeMacro()->setName(name + docstring(1, c)); return true; } diff --git a/src/mathed/InsetMathSymbol.C b/src/mathed/InsetMathSymbol.C index 4066dba4ef..e8a6dfb49b 100644 --- a/src/mathed/InsetMathSymbol.C +++ b/src/mathed/InsetMathSymbol.C @@ -20,7 +20,7 @@ #include "LaTeXFeatures.h" #include "debug.h" -#include +#include "support/textutils.h" namespace lyx { @@ -220,7 +220,7 @@ void InsetMathSymbol::write(WriteStream & os) const // $,#, etc. In theory the restriction based on catcodes, but then // we do not handle catcodes very well, let alone cat code changes, // so being outside the alpha range is good enough. - if (name().size() == 1 && !std::isalpha(name()[0])) + if (name().size() == 1 && !isAlphaASCII(name()[0])) return; os.pendingSpace(true); diff --git a/src/mathed/MathStream.C b/src/mathed/MathStream.C index e51819dc71..820aeeab54 100644 --- a/src/mathed/MathStream.C +++ b/src/mathed/MathStream.C @@ -16,22 +16,7 @@ #include "MathStream.h" #include "support/lyxalgo.h" - - -namespace { - -bool isAlpha(char c) -{ - return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); -} - - -bool isAlpha(lyx::char_type c) -{ - return c < 0x80 && isAlpha(static_cast(c)); -} - -} +#include "support/textutils.h" namespace lyx { @@ -100,7 +85,7 @@ NormalStream & operator<<(NormalStream & ns, int i) WriteStream & operator<<(WriteStream & ws, docstring const & s) { if (ws.pendingSpace() && s.length() > 0) { - if (isAlpha(s[0])) + if (isAlphaASCII(s[0])) ws.os() << ' '; ws.pendingSpace(false); } @@ -164,7 +149,7 @@ WriteStream & operator<<(WriteStream & ws, MathArray const & ar) WriteStream & operator<<(WriteStream & ws, char const * s) { if (ws.pendingSpace() && strlen(s) > 0) { - if (isAlpha(s[0])) + if (isAlphaASCII(s[0])) ws.os() << ' '; ws.pendingSpace(false); } @@ -177,7 +162,7 @@ WriteStream & operator<<(WriteStream & ws, char const * s) WriteStream & operator<<(WriteStream & ws, char c) { if (ws.pendingSpace()) { - if (isAlpha(c)) + if (isAlphaASCII(c)) ws.os() << ' '; ws.pendingSpace(false); } diff --git a/src/sgml.C b/src/sgml.C index a5aa601c8f..e5fb7fc2af 100644 --- a/src/sgml.C +++ b/src/sgml.C @@ -24,6 +24,7 @@ #include "support/lstrings.h" #include "support/std_ostream.h" #include "support/convert.h" +#include "support/textutils.h" #include #include @@ -144,13 +145,13 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams, return (*known).second; // make sure it starts with a letter - if (!isalpha(*it) && allowed.find(*it) >= allowed.size()) + if (!isAlphaASCII(*it) && allowed.find(*it) >= allowed.size()) content += "x"; bool mangle = false; for (; it != end; ++it) { char c = *it; - if (isalpha(c) || isdigit(c) || c == '-' || c == '.' + if (isAlphaASCII(c) || isDigitASCII(c) || c == '-' || c == '.' || allowed.find(c) < allowed.size()) content += c; else if (c == '_' || c == ' ') { @@ -168,7 +169,7 @@ docstring sgml::cleanID(Buffer const & buf, OutputParams const & runparams, if (mangle) { content += "-" + convert(mangleID++); } - else if (isdigit(content[content.size() - 1])) { + else if (isDigitASCII(content[content.size() - 1])) { content += "."; } diff --git a/src/support/textutils.C b/src/support/textutils.C index cfcc7dfa57..c5074cb45c 100644 --- a/src/support/textutils.C +++ b/src/support/textutils.C @@ -37,6 +37,12 @@ bool isLetterChar(char_type c) } +bool isAlphaASCII(char_type c) +{ + return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); +} + + bool isPrintable(char_type c) { if (!is_utf16(c)) { @@ -74,4 +80,10 @@ bool isDigit(char_type c) return ucs4_to_qchar(c).isDigit(); } + +bool isDigitASCII(char_type c) +{ + return '0' <= c && c <= '9'; +} + } // namespace lyx diff --git a/src/support/textutils.h b/src/support/textutils.h index 283db0316b..50d9acb7f7 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -30,6 +30,9 @@ bool isLineSeparatorChar(char_type c) /// return true if a char is alphabetical (including accented chars) bool isLetterChar(char_type c); +/// return whether \p c is an alphabetic character in the ASCII range +bool isAlphaASCII(char_type c); + /// return true if the char is printable bool isPrintable(char_type c); @@ -39,6 +42,9 @@ bool isPrintableNonspace(char_type c); /// return true if a unicode char is a digit. bool isDigit(char_type c); +/// return whether \p c is a digit in the ASCII range +bool isDigitASCII(char_type c); + } // namespace lyx #endif // TEXTUTILS_H -- 2.39.2