[LyX features/feature/docbook] DocBook: avoid using isspace in StartTag::writeTag.

Thibaut Cuvelier tcuvelier at lyx.org
Wed Sep 2 22:56:58 UTC 2020


The branch, feature/docbook, has been updated.

- Log -----------------------------------------------------------------

commit eeedeb8a20e5bfd062943f794f10814b6c6f78b5
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Thu Sep 3 01:23:20 2020 +0200

    DocBook: avoid using isspace in StartTag::writeTag.
    
    This is the cause of crashes (on both Windows and Linux).

diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index addf24a..dbe081f 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -429,16 +429,6 @@ void makeBibliography(
 }
 
 
-bool isNotOnlySpace(docstring const & str)
-{
-	for (auto const & c: str) {
-		if (c != ' ' && c != '\t' && c != '\n' && c != '\v' && c != '\f' && c != '\r')
-			return true;
-	}
-	return false;
-}
-
-
 void makeParagraph(
 		Text const & text,
 		Buffer const & buf,
diff --git a/src/xml.cpp b/src/xml.cpp
index dd9790f..478f961 100644
--- a/src/xml.cpp
+++ b/src/xml.cpp
@@ -108,12 +108,9 @@ docstring StartTag::writeTag() const
 {
 	docstring output = '<' + tag_;
 	if (!attr_.empty()) {
-		docstring attributes = xml::escapeString(attr_, XMLStream::ESCAPE_NONE);
-		attributes.erase(attributes.begin(), std::find_if(attributes.begin(), attributes.end(),
-                                                          [](int c) {return !std::isspace(c);}));
-		if (!attributes.empty()) {
+		docstring attributes = xml::trimLeft(xml::escapeString(attr_, XMLStream::ESCAPE_NONE));
+		if (!attributes.empty())
 			output += ' ' + attributes;
-		}
 	}
 	output += ">";
 	return output;
@@ -601,6 +598,39 @@ docstring xml::uniqueID(docstring const & label)
 }
 
 
+bool xml::isNotOnlySpace(docstring const & str)
+{
+	for (auto const & c: str) {
+		if (c != ' ' && c != '\t' && c != '\n' && c != '\v' && c != '\f' && c != '\r')
+		return true;
+	}
+	return false;
+}
+
+
+docstring xml::removeSpace(docstring const & str)
+{
+	odocstringstream ss;
+	for (auto const & c: str) {
+		if (c != ' ' && c != '\t' && c != '\n' && c != '\v' && c != '\f' && c != '\r')
+			ss << c;
+	}
+	return ss.str();
+}
+
+
+docstring xml::trimLeft(docstring const & str)
+{
+	size_t i = 0;
+	for (auto const & c: str) {
+		if (c != ' ' && c != '\t' && c != '\n' && c != '\v' && c != '\f' && c != '\r')
+			return str.substr(i, docstring::npos);
+		i++;
+	}
+	return str;
+}
+
+
 docstring xml::cleanID(docstring const & orig)
 {
 	// The standard xml:id only allows letters, digits, '-' and '.' in a name.
diff --git a/src/xml.h b/src/xml.h
index ebb8b8e..568c5e5 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -162,6 +162,15 @@ docstring cleanID(docstring const &orig);
 /// returns a unique numeric ID
 docstring uniqueID(docstring const & label);
 
+/// determines whether a string only contains space characters
+bool isNotOnlySpace(docstring const & str);
+
+///
+docstring removeSpace(docstring const & str);
+
+///
+docstring trimLeft(docstring const & str);
+
 struct FontTag;
 struct EndFontTag;
 

-----------------------------------------------------------------------

Summary of changes:
 src/output_docbook.cpp |   10 ----------
 src/xml.cpp            |   40 +++++++++++++++++++++++++++++++++++-----
 src/xml.h              |    9 +++++++++
 3 files changed, 44 insertions(+), 15 deletions(-)


hooks/post-receive
-- 
Repository for new features


More information about the lyx-cvs mailing list