]> git.lyx.org Git - lyx.git/blobdiff - src/texstream.cpp
Introduce the notion of math class
[lyx.git] / src / texstream.cpp
index e312d2cdbc8354a4f01f2530ef174ba72791c9af..5b0e92759173f211ec2afeebc2d17d5f72b4ea37 100644 (file)
@@ -49,13 +49,6 @@ unique_ptr<TexRow> otexrowstream::releaseTexRow()
 }
 
 
-void otexrowstream::append(docstring const & str, TexRow texrow)
-{
-       os_ << str;
-       texrow_->append(move(texrow));
-}
-
-
 void otexrowstream::put(char_type const & c)
 {
        os_.put(c);
@@ -76,6 +69,24 @@ void otexstream::put(char_type const & c)
 }
 
 
+size_t otexstringstream::length()
+{
+       auto pos = ods_.tellp();
+       return (pos >= 0) ? size_t(pos) : 0;
+}
+
+
+TexString otexstringstream::release()
+{
+       TexString ts(ods_.str(), move(texrow()));
+       // reset this
+       texrow() = TexRow();
+       ods_.clear();
+       ods_.str(docstring());
+       return ts;
+}
+
+
 BreakLine breakln;
 SafeBreakLine safebreakln;
 
@@ -112,6 +123,7 @@ otexrowstream & operator<<(otexrowstream & ots, odocstream_manip pf)
        return ots;
 }
 
+
 otexstream & operator<<(otexstream & ots, odocstream_manip pf)
 {
        otexrowstream & otrs = ots;
@@ -123,6 +135,38 @@ otexstream & operator<<(otexstream & ots, odocstream_manip pf)
 }
 
 
+otexrowstream & operator<<(otexrowstream & ots, TexString ts)
+{
+       ts.validate();
+       ots.os() << move(ts.str);
+       ots.texrow().append(move(ts.texrow));
+       return ots;
+}
+
+
+otexstream & operator<<(otexstream & ots, TexString ts)
+{
+       size_t const len = ts.str.length();
+       // Check whether there is something to output
+       if (len == 0)
+               return ots;
+
+       otexrowstream & otrs = ots;
+       if (ots.protectSpace()) {
+               if (!ots.canBreakLine() && ts.str[0] == ' ')
+                       otrs << "{}";
+               ots.protectSpace(false);
+       }
+
+       if (len > 1)
+               ots.canBreakLine(ts.str[len - 2] != '\n');
+       ots.lastChar(ts.str[len - 1]);
+
+       otrs << move(ts);
+       return ots;
+}
+
+
 otexrowstream & operator<<(otexrowstream & ots, docstring const & s)
 {
        ots.os() << s;