[EMAIL PROTECTED] wrote:
> --- lyx-devel/trunk/src/mathed/InsetMathSymbol.C (original)
> +++ lyx-devel/trunk/src/mathed/InsetMathSymbol.C Sun Apr 1 15:06:41 2007
> @@ -20,6 +20,7 @@
> #include "LaTeXFeatures.h"
> #include "debug.h"
>
> +#include <cctype>
>
> namespace lyx {
>
> @@ -215,8 +216,13 @@
> void InsetMathSymbol::write(WriteStream & os) const
> {
> os << '\\' << name();
> - if (name().size() == 1 && name()[0] < '0') // $,#, etc
> +
> + // $,#, 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]))
> return;
> +
> os.pendingSpace(true);
> }
This is wrong: std::isalpha takes a char, and name()[0] is a char_type, so
it gets truncated, and isalpha may return true for nonalpha characters.
Apart from that std::isalpha depends on the locale which is not good
either.
Surprisingly the same error is in some other places, too.
The attached patch fixed this and goes in later today.
Georg
Index: src/sgml.C
===================================================================
--- src/sgml.C (Revision 17697)
+++ src/sgml.C (Arbeitskopie)
@@ -24,6 +24,7 @@
#include "support/lstrings.h"
#include "support/std_ostream.h"
#include "support/convert.h"
+#include "support/textutils.h"
#include <map>
#include <sstream>
@@ -144,13 +145,13 @@ docstring sgml::cleanID(Buffer const & b
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 & b
if (mangle) {
content += "-" + convert<docstring>(mangleID++);
}
- else if (isdigit(content[content.size() - 1])) {
+ else if (isDigitASCII(content[content.size() - 1])) {
content += ".";
}
Index: src/mathed/InsetMath.C
===================================================================
--- src/mathed/InsetMath.C (Revision 17697)
+++ src/mathed/InsetMath.C (Arbeitskopie)
@@ -18,6 +18,7 @@
#include "debug.h"
#include "support/lstrings.h"
+#include "support/textutils.h"
#include <boost/current_function.hpp>
@@ -77,7 +78,7 @@ void InsetMath::write(WriteStream & os)
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);
}
Index: src/mathed/InsetMathSymbol.C
===================================================================
--- src/mathed/InsetMathSymbol.C (Revision 17697)
+++ src/mathed/InsetMathSymbol.C (Arbeitskopie)
@@ -20,7 +20,7 @@
#include "LaTeXFeatures.h"
#include "debug.h"
-#include <cctype>
+#include "support/textutils.h"
namespace lyx {
@@ -220,7 +220,7 @@ void InsetMathSymbol::write(WriteStream
// $,#, 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);
Index: src/mathed/InsetMathNest.C
===================================================================
--- src/mathed/InsetMathNest.C (Revision 17697)
+++ src/mathed/InsetMathNest.C (Arbeitskopie)
@@ -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(LCurso
return true;
}
- if (isalpha(c)) {
+ if (isAlphaASCII(c)) {
cur.activeMacro()->setName(name + docstring(1, c));
return true;
}
Index: src/mathed/MathStream.C
===================================================================
--- src/mathed/MathStream.C (Revision 17697)
+++ src/mathed/MathStream.C (Arbeitskopie)
@@ -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<char>(c));
-}
-
-}
+#include "support/textutils.h"
namespace lyx {
@@ -100,7 +85,7 @@ NormalStream & operator<<(NormalStream &
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 & w
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 & w
WriteStream & operator<<(WriteStream & ws, char c)
{
if (ws.pendingSpace()) {
- if (isAlpha(c))
+ if (isAlphaASCII(c))
ws.os() << ' ';
ws.pendingSpace(false);
}
Index: src/support/textutils.C
===================================================================
--- src/support/textutils.C (Revision 17697)
+++ src/support/textutils.C (Arbeitskopie)
@@ -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
Index: src/support/textutils.h
===================================================================
--- src/support/textutils.h (Revision 17697)
+++ src/support/textutils.h (Arbeitskopie)
@@ -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