X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fxml.cpp;h=e50e55972b042b53ca6459b64ff371d62bf78efa;hb=2b02b73f4a59bb73f9e819a960ea98c86ef8716f;hp=dd9790f2e85efdfa66a7d20d2e87355b6392517c;hpb=7a1b82a16ae5594e7354c507ecb47082abada9f4;p=lyx.git diff --git a/src/xml.cpp b/src/xml.cpp index dd9790f2e8..e50e55972b 100644 --- a/src/xml.cpp +++ b/src/xml.cpp @@ -28,6 +28,7 @@ #include "support/lstrings.h" #include "support/textutils.h" +#include #include #include #include @@ -108,12 +109,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; @@ -480,7 +478,8 @@ XMLStream &XMLStream::operator<<(xml::EndTag const &etag) + "' when other tags were pending. Last pending tag is `" + to_utf8(pending_tags_.back()->writeTag()) + "'. Tag discarded."); - pending_tags_.erase(dit); + if (!pending_tags_.empty()) + pending_tags_.erase(dit); return *this; } } @@ -601,6 +600,28 @@ 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::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.