mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
DocBook: avoid using isspace in StartTag::writeTag.
This is the cause of crashes (on both Windows and Linux).
This commit is contained in:
parent
2cd7a94f8b
commit
1a76fb9658
@ -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,
|
||||
@ -531,7 +521,7 @@ void makeParagraph(
|
||||
++nextpar;
|
||||
auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end, special_case);
|
||||
for (docstring const & parXML : pars) {
|
||||
if (isNotOnlySpace(parXML)) {
|
||||
if (xml::isNotOnlySpace(parXML)) {
|
||||
if (open_par)
|
||||
openParTag(xs, &*par, prevpar);
|
||||
|
||||
|
29
src/xml.cpp
29
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,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.
|
||||
|
@ -160,6 +160,12 @@ 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);
|
||||
|
||||
/// trims the string to the left, i.e. remove any space-like character at the beginning of the string
|
||||
docstring trimLeft(docstring const & str);
|
||||
|
||||
struct FontTag;
|
||||
struct EndFontTag;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user