]> git.lyx.org Git - lyx.git/blobdiff - src/texstream.cpp
Cmake tests: macro setmarkedtestlabel() worked only by chance
[lyx.git] / src / texstream.cpp
index e1c0fe77e0b6e3d332989fe472ca7a74d3dfaaa4..3268dca7b23f954501ef4cfd2c99eefd87d25cd7 100644 (file)
@@ -29,17 +29,31 @@ using lyx::support::split;
 
 namespace lyx {
 
+
+void otexrowstream::append(docstring const & str, TexRow const & texrow)
+{
+       os_ << str;
+       texrow_.append(texrow);
+}
+
+
+void otexrowstream::put(char_type const & c)
+{
+       os_.put(c);
+       if (c == '\n')
+               texrow_.newline();
+}
+
+
 void otexstream::put(char_type const & c)
 {
        if (protectspace_) {
                if (!canbreakline_ && c == ' ')
-                       os_ << "{}";
+                       os() << "{}";
                protectspace_ = false;
        }
-       os_.put(c);
+       otexrowstream::put(c);
        lastChar(c);
-       if (c == '\n')
-               texrow_.newline();
 }
 
 
@@ -50,9 +64,8 @@ SafeBreakLine safebreakln;
 otexstream & operator<<(otexstream & ots, BreakLine)
 {
        if (ots.canBreakLine()) {
-               ots.os().put('\n');
+               ots.otexrowstream::put('\n');
                ots.lastChar('\n');
-               ots.texrow().newline();
        }
        ots.protectSpace(false);
        return ots;
@@ -61,26 +74,43 @@ otexstream & operator<<(otexstream & ots, BreakLine)
 
 otexstream & operator<<(otexstream & ots, SafeBreakLine)
 {
+       otexrowstream & otrs = ots;
        if (ots.canBreakLine()) {
-               ots.os() << "%\n";
+               otrs << "%\n";
                ots.lastChar('\n');
-               ots.texrow().newline();
        }
        ots.protectSpace(false);
        return ots;
 }
 
 
-otexstream & operator<<(otexstream & ots, odocstream_manip pf)
+otexrowstream & operator<<(otexrowstream & ots, odocstream_manip pf)
 {
        ots.os() << pf;
        if (pf == static_cast<odocstream_manip>(endl)) {
-               ots.lastChar('\n');
                ots.texrow().newline();
        }
        return ots;
 }
 
+otexstream & operator<<(otexstream & ots, odocstream_manip pf)
+{
+       otexrowstream & otrs = ots;
+       otrs << pf;
+       if (pf == static_cast<odocstream_manip>(endl)) {
+               ots.lastChar('\n');
+       }
+       return ots;
+}
+
+
+otexrowstream & operator<<(otexrowstream & ots, docstring const & s)
+{
+       ots.os() << s;
+       ots.texrow().newlines(count(s.begin(), s.end(), '\n'));
+       return ots;
+}
+
 
 otexstream & operator<<(otexstream & ots, docstring const & s)
 {
@@ -89,10 +119,10 @@ otexstream & operator<<(otexstream & ots, docstring const & s)
        // Check whether there's something to output
        if (len == 0)
                return ots;
-
+       otexrowstream & otrs = ots;
        if (ots.protectSpace()) {
                if (!ots.canBreakLine() && s[0] == ' ')
-                       ots.os() << "{}";
+                       otrs << "{}";
                ots.protectSpace(false);
        }
 
@@ -106,7 +136,7 @@ otexstream & operator<<(otexstream & ots, docstring const & s)
                docstring s2 = split(s, s1, 0xF0000);
                while (true) {
                        if (!s1.empty())
-                               ots.os() << s1;
+                               otrs << s1;
                        if (s2.empty())
                                break;
                        docstring enc;
@@ -114,17 +144,23 @@ otexstream & operator<<(otexstream & ots, docstring const & s)
                        if (!contains(s2, 0xF0001))
                                s2 = split(enc, s1, 0xF0000);
                        else {
-                               ots.os() << setEncoding(to_ascii(enc));
+                               otrs << setEncoding(to_ascii(enc));
                                s2 = split(s3, s1, 0xF0000);
                        }
                }
        } else
-               ots.os() << s;
+               otrs << s;
 
        if (len > 1)
                ots.canBreakLine(s[len - 2] != '\n');
        ots.lastChar(s[len - 1]);
-       ots.texrow().newlines(count(s.begin(), s.end(), '\n'));
+       return ots;
+}
+
+
+otexrowstream & operator<<(otexrowstream & ots, string const & s)
+{
+       ots << from_utf8(s);
        return ots;
 }
 
@@ -136,6 +172,13 @@ otexstream & operator<<(otexstream & ots, string const & s)
 }
 
 
+otexrowstream & operator<<(otexrowstream & ots, char const * s)
+{
+       ots << from_utf8(s);
+       return ots;
+}
+
+
 otexstream & operator<<(otexstream & ots, char const * s)
 {
        ots << from_utf8(s);
@@ -143,21 +186,36 @@ otexstream & operator<<(otexstream & ots, char const * s)
 }
 
 
+otexrowstream & operator<<(otexrowstream & ots, char c)
+{
+       ots.put(c);
+       return ots;
+}
+
+
 otexstream & operator<<(otexstream & ots, char c)
 {
-       if (ots.protectSpace()) {
-               if (!ots.canBreakLine() && c == ' ')
-                       ots.os() << "{}";
-               ots.protectSpace(false);
-       }
-       ots.os() << c;
-       ots.lastChar(c);
-       if (c == '\n')
-               ots.texrow().newline();
+       ots.put(c);
        return ots;
 }
 
 
+template <typename Type>
+otexrowstream & operator<<(otexrowstream & ots, Type value)
+{
+       ots.os() << value;
+       return ots;
+}
+
+template otexrowstream & operator<< <SetEnc>(otexrowstream & os, SetEnc);
+template otexrowstream & operator<< <double>(otexrowstream &, double);
+template otexrowstream & operator<< <int>(otexrowstream &, int);
+template otexrowstream & operator<< <unsigned int>(otexrowstream &,
+                                                                                                  unsigned int);
+template otexrowstream & operator<< <unsigned long>(otexrowstream &,
+                                                                                                       unsigned long);
+
+
 template <typename Type>
 otexstream & operator<<(otexstream & ots, Type value)
 {