]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_mathmlstream.C
temporary reversal of the 'don't write spaces' stuff as this was buggy...
[lyx.git] / src / mathed / math_mathmlstream.C
index d7cf3ab39ffa72551e0daacd84350321d412ef94..a1f73f0e3f15e37480b45b9bf5e5192b799a128b 100644 (file)
 #include "math_mathmlstream.h"
 #include "math_inset.h"
 #include "math_extern.h"
+#include "debug.h"
 #include "support/lyxalgo.h"
+#include "support/LOstream.h"
 
 
 using std::ostream;
 using std::strlen;
 
 
+WriteStream::WriteStream(ostream & os, bool fragile, bool latex)
+       : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
+         pendingspace_(false), line_(0)
+{}
+
+
+WriteStream::WriteStream(ostream & os)
+       : os_(os), fragile_(false), firstitem_(false), latex_(false),
+         pendingspace_(false), line_(0)
+{}
+
+
+WriteStream::~WriteStream()
+{
+       if (pendingspace_)
+               os_ << ' ';
+}
+
+
+void WriteStream::addlines(unsigned int n)
+{
+       line_ += n;
+}
+
+
+void WriteStream::pendingSpace(bool how)
+{
+       if (how)
+               os_ << ' ';
+       pendingspace_ = how;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
+{
+       at->write(ws);
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
+{
+       write(ar, ws);
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, char const * s)
+{
+       if (ws.pendingSpace()) {
+               lyxerr << "writing a space in a string\n";
+               ws.os() << ' ';
+               ws.pendingSpace(false);
+       }
+       ws.os() << s;
+       ws.addlines(int(lyx::count(s, s + strlen(s), '\n')));
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, char c)
+{
+       if (ws.pendingSpace()) {
+               //if (isalpha(c))
+               //      ws.os() << ' ';
+               if (!isalpha(c)) {
+                       lyxerr << "I'd like to suppress writing a space\n";
+               }
+               ws.os() << ' ';
+               ws.pendingSpace(false);
+       }
+       ws.os() << c;
+       if (c == '\n')
+               ws.addlines(1);
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, int i)
+{
+       ws.os() << i;
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, unsigned int i)
+{
+       ws.os() << i;
+       return ws;
+}
+
+
+//////////////////////////////////////////////////////////////////////
+
+
 MathMLStream::MathMLStream(ostream & os)
        : os_(os), tab_(0), line_(0), lastchar_(0)
 {}
@@ -227,63 +324,3 @@ NormalStream & operator<<(NormalStream & ns, int i)
 
 //////////////////////////////////////////////////////////////////////
 
-
-WriteStream::WriteStream(ostream & os, bool fragile, bool latex)
-       : os_(os), fragile_(fragile), latex_(latex), firstitem_(false), line_(0)
-{}
-
-
-WriteStream::WriteStream(ostream & os)
-       : os_(os), fragile_(false), latex_(false), firstitem_(false), line_(0)
-{}
-
-
-void WriteStream::addlines(unsigned int n)
-{
-       line_ += n;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
-{
-       at->write(ws);
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
-{
-       write(ar, ws);
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, char const * s)
-{
-       ws.os() << s;
-       ws.addlines(int(lyx::count(s, s + strlen(s), '\n')));
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, char c)
-{
-       ws.os() << c;
-       if (c == '\n')
-               ws.addlines(1);
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, int i)
-{
-       ws.os() << i;
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, unsigned int i)
-{
-       ws.os() << i;
-       return ws;
-}