]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathStream.cpp
Only set buffer if it is not null.
[lyx.git] / src / mathed / MathStream.cpp
index 78838ccd0ab25bb151e9441c4dbb42b87efb9faf..588e219157efaa03093f2f60cb18a6c77c0a4e01 100644 (file)
 
 #include "MathStream.h"
 
+#include "MathFactory.h"
 #include "MathData.h"
 #include "MathExtern.h"
 
+#include "TexRow.h"
+
 #include "support/docstring.h"
-#include "support/RefChanger.h"
 #include "support/textutils.h"
 
 #include <algorithm>
@@ -124,10 +126,8 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
 
 WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
                                                 OutputType output, Encoding const * encoding)
-       : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
-         output_(output), pendingspace_(false), pendingbrace_(false),
-         textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
-         line_(0), encoding_(encoding), row_entry_(TexRow::row_none)
+       : os_(os), fragile_(fragile), latex_(latex),
+         output_(output), encoding_(encoding)
 {}
 
 
@@ -178,7 +178,7 @@ void WriteStream::asciiOnly(bool ascii)
 
 Changer WriteStream::changeRowEntry(TexRow::RowEntry entry)
 {
-       return make_change(row_entry_, entry);
+       return changeVar(row_entry_, entry);
 }
 
 
@@ -265,8 +265,8 @@ WriteStream & operator<<(WriteStream & ws, unsigned int i)
 //////////////////////////////////////////////////////////////////////
 
 
-MathStream::MathStream(odocstream & os)
-       : os_(os), tab_(0), line_(0), in_text_(false)
+MathStream::MathStream(odocstream & os, std::string const & xmlns, bool xmlMode)
+       : os_(os), tab_(0), line_(0), in_text_(false), xmlns_(xmlns), xml_mode_(xmlMode)
 {}
 
 
@@ -291,7 +291,7 @@ void MathStream::defer(string const & s)
 
 
 docstring MathStream::deferred() const
-{ 
+{
        return deferred_.str();
 }
 
@@ -335,10 +335,10 @@ MathStream & operator<<(MathStream & ms, MTag const & t)
 {
        ++ms.tab();
        ms.cr();
-       ms.os() << '<' << from_ascii(t.tag_);
+       ms.os() << '<' << from_ascii(ms.namespacedTag(t.tag_));
        if (!t.attr_.empty())
                ms.os() << " " << from_ascii(t.attr_);
-       ms << '>';
+       ms << ">";
        return ms;
 }
 
@@ -348,7 +348,18 @@ MathStream & operator<<(MathStream & ms, ETag const & t)
        ms.cr();
        if (ms.tab() > 0)
                --ms.tab();
-       ms.os() << "</" << from_ascii(t.tag_) << '>';
+       ms.os() << "</" << from_ascii(ms.namespacedTag(t.tag_)) << ">";
+       return ms;
+}
+
+
+MathStream & operator<<(MathStream & ms, CTag const & t)
+{
+       ms.cr();
+       ms.os() << "<" << from_ascii(ms.namespacedTag(t.tag_));
+    if (!t.attr_.empty())
+        ms.os() << " " << from_utf8(t.attr_);
+    ms.os() << "/>";
        return ms;
 }
 
@@ -381,7 +392,7 @@ void HtmlStream::defer(string const & s)
 
 
 docstring HtmlStream::deferred() const
-{ 
+{
        return deferred_.str();
 }
 
@@ -448,17 +459,17 @@ HtmlStream & operator<<(HtmlStream & ms, docstring const & s)
 //////////////////////////////////////////////////////////////////////
 
 
-SetMode::SetMode(MathStream & os, bool text)
-       : os_(os)
+SetMode::SetMode(MathStream & ms, bool text)
+       : ms_(ms)
 {
-       was_text_ = os_.inText();
-       os_.setTextMode(text);
+       was_text_ = ms_.inText();
+       ms_.setTextMode(text);
 }
 
 
 SetMode::~SetMode()
 {
-       os_.setTextMode(was_text_);
+       ms_.setTextMode(was_text_);
 }
 
 
@@ -694,4 +705,33 @@ OctaveStream & operator<<(OctaveStream & os, string const & s)
 }
 
 
+docstring convertDelimToXMLEscape(docstring const & name, bool xmlmode)
+{
+       // For the basic symbols, no difference between XML and HTML.
+       if (name.size() == 1) {
+               char_type const c = name[0];
+               if (c == '<')
+                       return from_ascii("&lt;");
+               else if (c == '>')
+                       return from_ascii("&gt;");
+               else
+                       return name;
+       } else if (name.size() == 2 && name[0] == '\\') {
+               char_type const c = name[1];
+               if (c == '{')
+                       return from_ascii("&#123;");
+               else if (c == '}')
+                       return from_ascii("&#125;");
+       }
+       MathWordList const & words = mathedWordList();
+       MathWordList::const_iterator it = words.find(name);
+       if (it != words.end()) {
+               // Only difference between XML and HTML, based on the contents read by MathFactory.
+               docstring const escape = xmlmode ? it->second.xmlname : it->second.htmlname;
+               return escape;
+       }
+       LYXERR0("Unable to find `" << name <<"' in the mathWordList.");
+       return name;
+}
+
 } // namespace lyx