]> git.lyx.org Git - lyx.git/blobdiff - src/texstream.cpp
Introduce the notion of math class
[lyx.git] / src / texstream.cpp
index f748f8a4d27687c232b9e9ff4b8bcaf2767112f9..5b0e92759173f211ec2afeebc2d17d5f72b4ea37 100644 (file)
@@ -33,26 +33,19 @@ using lyx::support::split;
 namespace lyx {
 
 
-otexrowstream::otexrowstream(odocstream & os, bool enable)
-       : os_(os), texrow_(make_unique<TexRow>(enable))
+otexrowstream::otexrowstream(odocstream & os)
+       : os_(os), texrow_(make_unique<TexRow>())
 {}
 
 
 otexrowstream::~otexrowstream() = default;
 
 
-unique_ptr<TexRow> && otexrowstream::releaseTexRow()
+unique_ptr<TexRow> otexrowstream::releaseTexRow()
 {
        auto p = make_unique<TexRow>();
        swap(texrow_, p);
-       return move(p);
-}
-
-
-void otexrowstream::append(docstring const & str, TexRow texrow)
-{
-       os_ << str;
-       texrow_->append(move(texrow));
+       return p;
 }
 
 
@@ -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;