]> 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 16f96e8625891972966f573de975a912814dbcc2..a1f73f0e3f15e37480b45b9bf5e5192b799a128b 100644 (file)
 #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)
 {}
 
 
-MathMLStream & operator<<(MathMLStream & ms, MathInset const * p)
+MathMLStream & operator<<(MathMLStream & ms, MathAtom const & at)
 {
-       if (p)
-               p->mathmlize(ms);
-       else
-               lyxerr << "operator<<(MathMLStream, NULL) called\n";
+       at->mathmlize(ms);
        return ms;
 }
 
@@ -78,12 +171,9 @@ void MathMLStream::cr()
 //////////////////////////////////////////////////////////////////////
 
 
-MapleStream & operator<<(MapleStream & ms, MathInset const * p)
+MapleStream & operator<<(MapleStream & ms, MathAtom const & at)
 {
-       if (p)
-               p->maplize(ms);
-       else
-               lyxerr << "operator<<(MapleStream, NULL) called\n";
+       at->maplize(ms);
        return ms;
 }
 
@@ -119,12 +209,9 @@ MapleStream & operator<<(MapleStream & ms, int i)
 //////////////////////////////////////////////////////////////////////
 
 
-MathematicaStream & operator<<(MathematicaStream & ms, MathInset const * p)
+MathematicaStream & operator<<(MathematicaStream & ms, MathAtom const & at)
 {
-       if (p)
-               p->mathematicize(ms);
-       else
-               lyxerr << "operator<<(MathematicaStream, NULL) called\n";
+       at->mathematicize(ms);
        return ms;
 }
 
@@ -161,12 +248,9 @@ MathematicaStream & operator<<(MathematicaStream & ms, int i)
 //////////////////////////////////////////////////////////////////////
 
 
-OctaveStream & operator<<(OctaveStream & ns, MathInset const * p)
+OctaveStream & operator<<(OctaveStream & ns, MathAtom const & at)
 {
-       if (p)
-               p->octavize(ns);
-       else
-               lyxerr << "operator<<(OctaveStream, NULL) called\n";
+       at->octavize(ns);
        return ns;
 }
 
@@ -202,12 +286,9 @@ OctaveStream & operator<<(OctaveStream & ns, int i)
 //////////////////////////////////////////////////////////////////////
 
 
-NormalStream & operator<<(NormalStream & ns, MathInset const * p)
+NormalStream & operator<<(NormalStream & ns, MathAtom const & at)
 {
-       if (p)
-               p->normalize(ns);
-       else
-               lyxerr << "operator<<(NormalStream, NULL) called\n";
+       at->normalize(ns);
        return ns;
 }
 
@@ -243,68 +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, MathInset const * p)
-{
-       if (p)
-               p->write(ws);
-       else
-               lyxerr << "operator<<(WriteStream, NULL) called\n";
-       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') {
-               lyxerr << "writing a newline\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;
-}