On Mon, Oct 30, 2006 at 08:22:31PM +0100, Georg Baum wrote:

> Am Montag, 30. Oktober 2006 20:03 schrieb Enrico Forestieri:
> 
> > An hack? What do you mean?
> 
> This one:
> 
> if (s[0] < 0x80 && isAlpha(static_cast<char>(s[0])))
> 
> We should have an isAlpha that takes a lyx::char_type and use
> 
> if (isAlpha(s[0]))
> 
> instead, even if that isAlpha looks like this:
> 
> bool isAlpha(lyx::char_type c)
> {
>       return c < 0x80 && isAlpha(static_cast<char>(c));
> }
> 
> The places where a lyx::char_type is treated as a char should be limited to 
> some support functions. If we hardcode this stuff all over the place it 
> will be more difficult to take non-ascii alphanumeric characters into 
> acoount if that is needed some day.

Agreed, even if that doesn't qualify as an hack for me. I doubt that you
can use something different than ascii in a TeX equation (unless you
catcode it, of course). I thought about adding an assert, but then
nobody can stop an user from writing \sinü, so let's have an error from
latex if that happens...

> > > Then I would also like to know why this problem was introduced. 
> Probably 
> > > not by removing the code you just added (or was it done by accident?).
> > 
> > Probably by adding the overloaded << operator and not taking the 
> appropriate
> > actions.
> 
> Ah, you just copied existing stuff. If I had known that I would not have 
> asked.

Yep, I stand on the shoulders of giants ;-)

Here is where the wicked deed occurred:
http://www.lyx.org/trac/changeset/15462#file162

Updated patch attached.

-- 
Enrico
Index: src/mathed/MathStream.C
===================================================================
--- src/mathed/MathStream.C     (revision 15623)
+++ src/mathed/MathStream.C     (working copy)
@@ -25,6 +25,12 @@ 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));
+}
+
 }
 
 
@@ -93,7 +99,19 @@ NormalStream & operator<<(NormalStream &
 
 WriteStream & operator<<(WriteStream & ws, docstring const & s)
 {
+       if (ws.pendingSpace() && s.length() > 0) {
+               if (isAlpha(s[0]))
+                       ws.os() << ' ';
+               ws.pendingSpace(false);
+       }
        ws.os() << s;
+       int lf = 0;
+       docstring::const_iterator dit = s.begin();
+       docstring::const_iterator end = s.end();
+       for (; dit != end; ++dit)
+               if ((*dit) == '\n')
+                       ++lf;
+       ws.addlines(lf);
        return ws;
 }
 

Reply via email to