[LyX/master] Cleanup MathMLStream

Jean-Marc Lasgouttes lasgouttes at lyx.org
Mon Jul 22 19:32:39 UTC 2024


commit fbd4b0a13fae4263cc88aa76bc4fbba5178b15fa
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Fri Jul 19 14:57:58 2024 +0200

    Cleanup MathMLStream
    
    This is preparatory work for fixing ticket #13069.
    
    Remove direct accesses to the underlying stream of MathMLStream in
    InsetMathChar, InsetMathSpecialChar, and in all << operators other
    than MathMLStream << docstring. This will allow to add a hook later in
    this operator.
    
    Move default values of MathMLStream private members to their definition.
    
    Get rid of line_ member, which is not used.
---
 src/mathed/InsetMathChar.cpp        |  2 +-
 src/mathed/InsetMathSpecialChar.cpp |  2 +-
 src/mathed/MathStream.cpp           | 22 +++++++++++-----------
 src/mathed/MathStream.h             | 16 +++++-----------
 4 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/src/mathed/InsetMathChar.cpp b/src/mathed/InsetMathChar.cpp
index 199982a5f7..82d0b63f1e 100644
--- a/src/mathed/InsetMathChar.cpp
+++ b/src/mathed/InsetMathChar.cpp
@@ -248,7 +248,7 @@ void InsetMathChar::mathmlize(MathMLStream & ms) const
 
 	if (ms.inText()) {
 		if (entity.empty())
-			ms.os().put(char_);
+			ms << char_;
 		else
 			ms << from_ascii(entity);
 		return;
diff --git a/src/mathed/InsetMathSpecialChar.cpp b/src/mathed/InsetMathSpecialChar.cpp
index 746cec5bda..12c9a4c111 100644
--- a/src/mathed/InsetMathSpecialChar.cpp
+++ b/src/mathed/InsetMathSpecialChar.cpp
@@ -139,7 +139,7 @@ void InsetMathSpecialChar::mathmlize(MathMLStream & ms) const
 		ms << "&";
 		break;
 	default:
-		ms.os().put(char_);
+		ms << char_;
 		break;
 	}
 }
diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp
index 4a006e4809..dc4aa05df9 100644
--- a/src/mathed/MathStream.cpp
+++ b/src/mathed/MathStream.cpp
@@ -289,7 +289,7 @@ TeXMathStream & operator<<(TeXMathStream & ws, unsigned int i)
 
 
 MathMLStream::MathMLStream(odocstream & os, std::string const & xmlns)
-	: os_(os), tab_(0), line_(0), in_text_(false), xmlns_(xmlns)
+	: os_(os), xmlns_(xmlns)
 {
 	if (in_text_)
 		font_math_style_ = TEXT_STYLE;
@@ -338,23 +338,30 @@ MathMLStream & operator<<(MathMLStream & ms, MathData const & ar)
 }
 
 
-MathMLStream & operator<<(MathMLStream & ms, char const * s)
+MathMLStream & operator<<(MathMLStream & ms, docstring const & s)
 {
 	ms.os() << s;
 	return ms;
 }
 
 
+MathMLStream & operator<<(MathMLStream & ms, char const * s)
+{
+	ms << from_utf8(s);
+	return ms;
+}
+
+
 MathMLStream & operator<<(MathMLStream & ms, char c)
 {
-	ms.os() << c;
+	ms << docstring(1,c);
 	return ms;
 }
 
 
 MathMLStream & operator<<(MathMLStream & ms, char_type c)
 {
-	ms.os().put(c);
+	ms << docstring(1,c);
 	return ms;
 }
 
@@ -410,13 +417,6 @@ MathMLStream & operator<<(MathMLStream & ms, CTag const & t)
 }
 
 
-MathMLStream & operator<<(MathMLStream & ms, docstring const & s)
-{
-	ms.os() << s;
-	return ms;
-}
-
-
 //////////////////////////////////////////////////////////////////////
 
 
diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
index 04c7cb507e..c8d684bc38 100644
--- a/src/mathed/MathStream.h
+++ b/src/mathed/MathStream.h
@@ -9,8 +9,8 @@
  * Full author contact details are available in file CREDITS.
  */
 
-#ifndef MATH_MATHMLSTREAM_H
-#define MATH_MATHMLSTREAM_H
+#ifndef MATH_MATHSTREAM_H
+#define MATH_MATHSTREAM_H
 
 #include "InsetMath.h"
 #include "FontInfo.h"
@@ -382,13 +382,9 @@ public:
 	void cr();
 	///
 	odocstream & os() { return os_; }
-	///
-	int line() const { return line_; }
-	///
+	/// Indentation when nesting tags
 	int & tab() { return tab_; }
 	///
-	friend MathMLStream & operator<<(MathMLStream &, char const *);
-	///
 	void defer(docstring const &);
 	///
 	void defer(std::string const &);
@@ -412,11 +408,9 @@ private:
 	///
 	odocstream & os_;
 	///
-	int tab_;
-	///
-	int line_;
+	int tab_ = 0;
 	///
-	bool in_text_;
+	bool in_text_ = false;
 	///
 	odocstringstream deferred_;
 	///


More information about the lyx-cvs mailing list