X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraph.cpp;h=b5f31281f4da9ee0dff6d11b8825bdb8a68a63f1;hb=3256dbc78a76f947080dc8e3414abc60e4b5c5af;hp=aeece98bddc6e20b6b0b50b6757fdd69640a45a8;hpb=e69b723bf9d2e2d8bbd855cac164be4a1a24035e;p=lyx.git diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index aeece98bdd..b5f31281f4 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -53,7 +53,6 @@ #include "support/lstrings.h" #include "support/Messages.h" #include "support/textutils.h" -#include "support/unicode.h" #include #include @@ -280,8 +279,8 @@ void Paragraph::setChange(Change const & change) if (change.type != Change::DELETED) { for (pos_type pos = 0; pos < size(); ++pos) { - if (isInset(pos)) - getInset(pos)->setChange(change); + if (Inset * inset = getInset(pos)) + inset->setChange(change); } } } @@ -293,8 +292,9 @@ void Paragraph::setChange(pos_type pos, Change const & change) d->changes_.set(change, pos); // see comment in setChange(Change const &) above - if (change.type != Change::DELETED && pos < size() && isInset(pos)) - getInset(pos)->setChange(change); + if (change.type != Change::DELETED && pos < size()) + if (Inset * inset = getInset(pos)) + inset->setChange(change); } @@ -315,17 +315,15 @@ void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start, switch (lookupChange(pos).type) { case Change::UNCHANGED: // accept changes in nested inset - if (pos < size() && isInset(pos)) - getInset(pos)->acceptChanges(bparams); - + if (Inset * inset = getInset(pos)) + inset->acceptChanges(bparams); break; case Change::INSERTED: d->changes_.set(Change(Change::UNCHANGED), pos); // also accept changes in nested inset - if (pos < size() && isInset(pos)) { - getInset(pos)->acceptChanges(bparams); - } + if (Inset * inset = getInset(pos)) + inset->acceptChanges(bparams); break; case Change::DELETED: @@ -353,9 +351,8 @@ void Paragraph::rejectChanges(BufferParams const & bparams, switch (lookupChange(pos).type) { case Change::UNCHANGED: // reject changes in nested inset - if (pos < size() && isInset(pos)) { - getInset(pos)->rejectChanges(bparams); - } + if (Inset * inset = getInset(pos)) + inset->rejectChanges(bparams); break; case Change::INSERTED: @@ -992,13 +989,6 @@ void Paragraph::Private::validate(LaTeXFeatures & features, // then the layouts features.useLayout(layout.name()); - if (!layout.requires().empty()) { - vector req = layout.requires(); - for (vector::const_iterator it = req.begin(); - it != req.end(); ++it) { - features.require(*it); - } - } // then the fonts fontlist_.validate(features); @@ -1121,9 +1111,7 @@ void Paragraph::write(Buffer const & buf, ostream & os, char_type const c = d->text_[i]; switch (c) { case META_INSET: - { - Inset const * inset = getInset(i); - if (inset) + if (Inset const * inset = getInset(i)) { if (inset->directWrite()) { // international char, let it write // code directly so it's shorter in @@ -1137,8 +1125,8 @@ void Paragraph::write(Buffer const & buf, ostream & os, os << "\n\\end_inset\n\n"; column = 0; } - } - break; + } + break; case '\\': os << "\n\\backslash\n"; column = 0; @@ -1158,11 +1146,9 @@ void Paragraph::write(Buffer const & buf, ostream & os, } // this check is to amend a bug. LyX sometimes // inserts '\0' this could cause problems. - if (c != '\0') { - vector tmp = ucs4_to_utf8(c); - tmp.push_back('\0'); - os << &tmp[0]; - } else + if (c != '\0') + os << to_utf8(docstring(1, c)); + else lyxerr << "ERROR (Paragraph::writeFile):" " NULL char in structure." << endl; ++column; @@ -2085,8 +2071,7 @@ bool Paragraph::latex(Buffer const & buf, bool Paragraph::emptyTag() const { for (pos_type i = 0; i < size(); ++i) { - if (isInset(i)) { - Inset const * inset = getInset(i); + if (Inset const * inset = getInset(i)) { InsetCode lyx_code = inset->lyxCode(); if (lyx_code != TOC_CODE && lyx_code != INCLUDE_CODE && @@ -2110,8 +2095,7 @@ bool Paragraph::emptyTag() const string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) const { for (pos_type i = 0; i < size(); ++i) { - if (isInset(i)) { - Inset const * inset = getInset(i); + if (Inset const * inset = getInset(i)) { InsetCode lyx_code = inset->lyxCode(); if (lyx_code == LABEL_CODE) { InsetLabel const * const il = static_cast(inset); @@ -2119,7 +2103,6 @@ string Paragraph::getID(Buffer const & buf, OutputParams const & runparams) cons return "id='" + to_utf8(sgml::cleanID(buf, runparams, id)) + "'"; } } - } return string(); } @@ -2129,8 +2112,7 @@ pos_type Paragraph::getFirstWord(Buffer const & buf, odocstream & os, OutputPara { pos_type i; for (i = 0; i < size(); ++i) { - if (isInset(i)) { - Inset const * inset = getInset(i); + if (Inset const * inset = getInset(i)) { inset->docbook(buf, os, runparams); } else { char_type c = d->text_[i]; @@ -2190,8 +2172,7 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf, } } - if (isInset(i)) { - Inset const * inset = getInset(i); + if (Inset const * inset = getInset(i)) { inset->docbook(buf, os, runparams); } else { char_type c = d->text_[i]; @@ -2217,30 +2198,33 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf, bool Paragraph::isHfill(pos_type pos) const { - return isInset(pos) && getInset(pos)->lyxCode() == HFILL_CODE; + Inset const * inset = getInset(pos); + return inset && inset->lyxCode() == HFILL_CODE; } bool Paragraph::isNewline(pos_type pos) const { - return isInset(pos) && getInset(pos)->lyxCode() == NEWLINE_CODE; + Inset const * inset = getInset(pos); + return inset && inset->lyxCode() == NEWLINE_CODE; } bool Paragraph::isLineSeparator(pos_type pos) const { char_type const c = d->text_[pos]; - return isLineSeparatorChar(c) - || (c == META_INSET && getInset(pos) && - getInset(pos)->isLineSeparator()); + if (isLineSeparatorChar(c)) + return true; + Inset const * inset = getInset(pos); + return inset && inset->isLineSeparator(); } /// Used by the spellchecker bool Paragraph::isLetter(pos_type pos) const { - if (isInset(pos)) - return getInset(pos)->isLetter(); + if (Inset const * inset = getInset(pos)) + return inset->isLetter(); char_type const c = d->text_[pos]; return isLetterChar(c) || isDigit(c); } @@ -2535,18 +2519,20 @@ Inset * Paragraph::releaseInset(pos_type pos) Inset * Paragraph::getInset(pos_type pos) { - return d->insetlist_.get(pos); + return (pos < pos_type(d->text_.size()) && d->text_[pos] == META_INSET) + ? d->insetlist_.get(pos) : 0; } Inset const * Paragraph::getInset(pos_type pos) const { - return d->insetlist_.get(pos); + return (pos < pos_type(d->text_.size()) && d->text_[pos] == META_INSET) + ? d->insetlist_.get(pos) : 0; } void Paragraph::changeCase(BufferParams const & bparams, pos_type pos, - pos_type right, TextCase action) + pos_type & right, TextCase action) { // process sequences of modified characters; in change // tracking mode, this approach results in much better