From 43f6b1672b5ef442b4e9b7e4f7ea76dc14ac4fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sun, 21 Oct 2012 21:14:16 +0200 Subject: [PATCH] Use empty() to check empty and non-empty'ness not size() Also add FormatList::empty(). --- src/BiblioInfo.cpp | 8 ++--- src/Cursor.cpp | 4 +-- src/Format.h | 2 ++ src/KeySequence.cpp | 3 +- src/Paragraph.cpp | 4 +-- src/client/client.cpp | 10 +++--- src/frontends/qt4/GuiPrefs.cpp | 4 +-- src/frontends/qt4/GuiToolbar.cpp | 2 +- src/frontends/qt4/Menus.cpp | 12 +++---- src/graphics/GraphicsLoader.cpp | 2 +- src/lyxfind.cpp | 4 +-- src/mathed/CommandInset.cpp | 2 +- src/mathed/InsetMathBox.cpp | 4 +-- src/mathed/InsetMathExInt.cpp | 6 ++-- src/mathed/InsetMathGrid.cpp | 4 +-- src/mathed/InsetMathHull.cpp | 4 +-- src/mathed/InsetMathScript.cpp | 62 ++++++++++++++++---------------- src/mathed/InsetMathXArrow.cpp | 2 +- src/mathed/InsetMathXYArrow.cpp | 4 +-- src/mathed/MathAutoCorrect.cpp | 2 +- src/mathed/MathData.cpp | 4 +-- src/mathed/MathExtern.cpp | 12 +++---- src/mathed/MathMacro.cpp | 5 ++- src/mathed/MathMacroTemplate.cpp | 13 ++++--- src/mathed/MathParser.cpp | 22 ++++++------ src/rowpainter.cpp | 4 +-- src/support/docstring.cpp | 2 +- src/support/weighted_btree.h | 4 +-- src/tex2lyx/text.cpp | 2 +- 29 files changed, 106 insertions(+), 107 deletions(-) diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index bc46e17448..93094f8bfa 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -66,7 +66,7 @@ docstring familyName(docstring const & name) vector::const_iterator it = pieces.begin(); vector::const_iterator en = pieces.end(); for (; it != en; ++it) { - if ((*it).size() == 0) + if ((*it).empty()) continue; char_type const c = (*it)[0]; if (isLower(c)) @@ -99,7 +99,7 @@ docstring convertLaTeXCommands(docstring const & str) bool scanning_cmd = false; bool scanning_math = false; bool escaped = false; // used to catch \$, etc. - while (val.size()) { + while (!val.empty()) { char_type const ch = val[0]; // if we're scanning math, we output everything until we @@ -323,7 +323,7 @@ namespace { fmt = fmt.substr(2); // we'll remove characters from the front of fmt as we // deal with them - while (fmt.size()) { + while (!fmt.empty()) { if (fmt[0] == ']' && fmt.size() > 1 && fmt[1] == ']') { // that's the end fmt = fmt.substr(2); @@ -415,7 +415,7 @@ docstring BibTeXInfo::expandFormat(string const & format, string fmt = format; // we'll remove characters from the front of fmt as we // deal with them - while (fmt.size()) { + while (!fmt.empty()) { if (counter++ > max_passes) { LYXERR0("Recursion limit reached while parsing `" << format << "'."); diff --git a/src/Cursor.cpp b/src/Cursor.cpp index b0f7b7074e..e38ca5ec13 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -588,7 +588,7 @@ void Cursor::checkNewWordPosition() clearNewWordPosition(); else { FontSpan nw = locateWord(WHOLE_WORD); - if (nw.size()) { + if (!nw.empty()) { FontSpan ow = new_word_.locateWord(WHOLE_WORD); if (nw.intersect(ow).empty()) clearNewWordPosition(); @@ -1637,7 +1637,7 @@ bool Cursor::macroModeClose() // we have to resolve the macro here manually and check its arity // to put the selection behind it if arity > 0. MacroData const * data = buffer()->getMacro(atomAsMacro->name()); - if (selection.size() > 0 && data && data->numargs() - data->optionals() > 0) { + if (!selection.empty() && data && data->numargs() - data->optionals() > 0) { macroArg = true; atomAsMacro->setDisplayMode(MathMacro::DISPLAY_INTERACTIVE_INIT, 1); } else diff --git a/src/Format.h b/src/Format.h index 9d91ae1442..b96120bc71 100644 --- a/src/Format.h +++ b/src/Format.h @@ -201,6 +201,8 @@ public: /// const_iterator end() const { return formatlist.end(); } /// + bool empty() const { return formatlist.empty(); } + /// FormatList::size_type size() const { return formatlist.size(); } private: /// diff --git a/src/KeySequence.cpp b/src/KeySequence.cpp index a0f2f5bda2..3bee9caadb 100644 --- a/src/KeySequence.cpp +++ b/src/KeySequence.cpp @@ -125,8 +125,7 @@ size_t KeySequence::parse(string const & s) } } - // empty sequence? - if (sequence.size() == 0) + if (sequence.empty()) return 0; // everything is fine diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index e80ddc1de3..5a68047850 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -3733,7 +3733,7 @@ SpellChecker::Result Paragraph::spellCheck(pos_type & from, pos_type & to, wl = WordLangTuple(word, lang); - if (!word.size()) + if (word.empty()) return result; if (needsSpellCheck() || check_learned) { @@ -3830,7 +3830,7 @@ void Paragraph::Private::markMisspelledWords( void Paragraph::spellCheck() const { SpellChecker * speller = theSpellChecker(); - if (!speller || !size() ||!needsSpellCheck()) + if (!speller || empty() ||!needsSpellCheck()) return; pos_type start; pos_type endpos; diff --git a/src/client/client.cpp b/src/client/client.cpp index 105c1e9c01..19e38fae51 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -462,7 +462,7 @@ docstring clientName = int n(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -n requires 1 argument." << endl; return -1; @@ -477,7 +477,7 @@ docstring singleCommand; int c(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -c requires 1 argument." << endl; return -1; @@ -507,7 +507,7 @@ docstring serverAddress; int a(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -a requires 1 argument." << endl; return -1; @@ -522,7 +522,7 @@ int a(vector const & arg) int t(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -t requires 1 argument." << endl; return -1; @@ -537,7 +537,7 @@ string serverPid; // Init to empty string int p(vector const & arg) { - if (arg.size() < 1) { + if (arg.empty()) { cerr << "lyxclient: The option -p requires 1 argument." << endl; return -1; diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index a65af05d76..902d2dd9cd 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1678,7 +1678,7 @@ void PrefConverters::changeConverter() void PrefConverters::updateButtons() { - if (form_->formats().size() == 0) + if (form_->formats().empty()) return; Format const & from = form_->formats().get(converterFromCO->currentIndex()); Format const & to = form_->formats().get(converterToCO->currentIndex()); @@ -1975,7 +1975,7 @@ void PrefFileformats::updateView() void PrefFileformats::on_formatsCB_currentIndexChanged(int i) { - if (form_->formats().size() == 0) + if (form_->formats().empty()) return; int const nr = formatsCB->itemData(i).toInt(); Format const f = form_->formats().get(nr); diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index ec80a0b430..a6f4505ce0 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -99,7 +99,7 @@ Action * GuiToolbar::addItem(ToolbarItem const & item) // Get the keys bound to this action, but keep only the // first one later KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(item.func_); - if (bindings.size()) + if (!bindings.empty()) text += " [" + toqstr(bindings.begin()->print(KeySequence::ForGui)) + "]"; Action * act = new Action(&owner_, getIcon(item.func_, false), diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 674afaf09a..279ccaea3c 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -241,7 +241,7 @@ public: // Get the keys bound to this action, but keep only the // first one later KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func_); - if (bindings.size()) + if (!bindings.empty()) return toqstr(bindings.begin()->print(KeySequence::ForGui)); LYXERR(Debug::KBMAP, "No binding for " @@ -1301,7 +1301,7 @@ void MenuDefinition::expandToc(Buffer const * buf) if (cit == end) LYXERR(Debug::GUI, "No table of contents."); else { - if (cit->second.size() > 0 ) + if (!cit->second.empty()) expandToc2(cit->second, 0, cit->second.size(), 0); else add(MenuItem(MenuItem::Info, qt_(""))); @@ -1574,7 +1574,7 @@ static QString label(MenuItem const & mi) void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu) { LYXERR(Debug::GUI, "populating menu " << menu.name()); - if (menu.size() == 0) { + if (menu.empty()) { LYXERR(Debug::GUI, "\tERROR: empty menu " << menu.name()); return; } @@ -1759,7 +1759,7 @@ void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb) {LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole} }; const size_t num_entries = sizeof(entries) / sizeof(entries[0]); - const bool first_call = mac_special_menu_.size() == 0; + const bool first_call = mac_special_menu_.empty(); // the special menu for Menus. Fill it up only once. if (first_call) { @@ -2050,7 +2050,7 @@ void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial) LYXERR(Debug::GUI, "populating menu bar" << d->menubar_.name()); - if (d->menubar_.size() == 0) { + if (d->menubar_.empty()) { LYXERR(Debug::GUI, "\tERROR: empty menu bar" << d->menubar_.name()); return; @@ -2115,7 +2115,7 @@ void Menus::updateMenu(Menu * qmenu) MenuDefinition cat_menu = d->getMenu(toqstr(menu_name)); //FIXME: 50 is a wild guess. We should take into account here //the expansion of menu items, disabled optional items etc. - bool const in_sub_menu = fromLyxMenu.size() > 0 + bool const in_sub_menu = !fromLyxMenu.empty() && fromLyxMenu.size() + cat_menu.size() > 50 ; if (in_sub_menu) fromLyxMenu.catSub(menu_name); diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp index 5ed19c60ea..9f873baf3d 100644 --- a/src/graphics/GraphicsLoader.cpp +++ b/src/graphics/GraphicsLoader.cpp @@ -89,7 +89,7 @@ void LoaderQueue::loadNext() LYXERR(Debug::GRAPHICS, "LoaderQueue: " << cache_queue_.size() << " items in the queue"); int counter = s_numimages_; - while (cache_queue_.size() && counter--) { + while (!cache_queue_.empty() && counter--) { Cache::ItemPtr ptr = cache_queue_.front(); cache_set_.erase(ptr); cache_queue_.pop_front(); diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 33dbd8a9d4..74b045c4bb 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -968,10 +968,10 @@ string MatchStringAdv::normalize(docstring const & s, bool hack_braces) const else t = lyx::to_utf8(s); // Remove \n at begin - while (t.size() > 0 && t[0] == '\n') + while (!t.empty() && t[0] == '\n') t = t.substr(1); // Remove \n at end - while (t.size() > 0 && t[t.size() - 1] == '\n') + while (!t.empty() && t[t.size() - 1] == '\n') t = t.substr(0, t.size() - 1); size_t pos; // Replace all other \n with spaces diff --git a/src/mathed/CommandInset.cpp b/src/mathed/CommandInset.cpp index e09604e241..0cf041c23e 100644 --- a/src/mathed/CommandInset.cpp +++ b/src/mathed/CommandInset.cpp @@ -67,7 +67,7 @@ void CommandInset::write(WriteStream & os) const ModeSpecifier specifier(os, currentMode(), lockedMode(), asciiOnly()); MathEnsurer ensurer(os, needs_math_mode_); os << '\\' << name_; - if (cell(1).size()) + if (!cell(1).empty()) os << '[' << cell(1) << ']'; os << '{' << cell(0) << '}'; } diff --git a/src/mathed/InsetMathBox.cpp b/src/mathed/InsetMathBox.cpp index 60983bca80..8b3cb2b427 100644 --- a/src/mathed/InsetMathBox.cpp +++ b/src/mathed/InsetMathBox.cpp @@ -282,9 +282,9 @@ void InsetMathMakebox::write(WriteStream & os) const { ModeSpecifier specifier(os, TEXT_MODE); os << (framebox_ ? "\\framebox" : "\\makebox"); - if (cell(0).size() || !os.latex()) { + if (!cell(0).empty() || !os.latex()) { os << '[' << cell(0) << ']'; - if (cell(1).size() || !os.latex()) + if (!cell(1).empty() || !os.latex()) os << '[' << cell(1) << ']'; } os << '{' << cell(2) << '}'; diff --git a/src/mathed/InsetMathExInt.cpp b/src/mathed/InsetMathExInt.cpp index ac5409f469..64f49cd996 100644 --- a/src/mathed/InsetMathExInt.cpp +++ b/src/mathed/InsetMathExInt.cpp @@ -76,7 +76,7 @@ void InsetMathExInt::draw(PainterInfo &, int, int) const void InsetMathExInt::maple(MapleStream & os) const { os << symbol_ << '('; - if (cell(0).size()) + if (!cell(0).empty()) os << cell(0); else os << '1'; @@ -94,7 +94,7 @@ void InsetMathExInt::maxima(MaximaStream & os) const else os << symbol_ << '('; - if (cell(0).size()) + if (!cell(0).empty()) os << cell(0) << ','; else os << '1' << ','; @@ -113,7 +113,7 @@ void InsetMathExInt::mathematica(MathematicaStream & os) const else os << symbol_ << '['; - if (cell(0).size()) + if (!cell(0).empty()) os << cell(0) << ','; else os << '1' << ','; diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index ac8cd491ac..e74d549c48 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -674,7 +674,7 @@ docstring InsetMathGrid::eolString(row_type row, bool fragile, // make sure an upcoming '[' does not break anything if (row + 1 < nrows()) { MathData const & c = cell(index(row + 1, 0)); - if (c.size() && c.front()->getChar() == '[') + if (!c.empty() && c.front()->getChar() == '[') //eol += "[0pt]"; eol += "{}"; } @@ -905,7 +905,7 @@ bool InsetMathGrid::idxDelete(idx_type & idx) // try to delete entire sequence of ncols() empty cells if possible for (idx_type i = idx; i < idx + ncols(); ++i) - if (cell(i).size()) + if (!cell(i).empty()) return false; // move cells if necessary diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 1f135f54c2..6598bd913d 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -1039,7 +1039,7 @@ void InsetMathHull::splitTo3Cols() InsetMathGrid::addCol(2); for (row_type row = 0; row < nrows(); ++row) { idx_type const i = 3 * row + 1; - if (cell(i).size()) { + if (!cell(i).empty()) { cell(i + 1) = MathData(buffer_, cell(i).begin() + 1, cell(i).end()); cell(i).erase(1, cell(i).size()); } @@ -1309,7 +1309,7 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func) MathData ar; if (cur.inMathed() && cur.selection()) { asArray(grabAndEraseSelection(cur), ar); - } else if (pos == cur.cell().size()) { + } else if (!pos == cur.cell().empty()) { ar = cur.cell(); lyxerr << "use whole cell: " << ar << endl; } else { diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp index 9dae426bea..ba2be2f729 100644 --- a/src/mathed/InsetMathScript.cpp +++ b/src/mathed/InsetMathScript.cpp @@ -177,7 +177,7 @@ int InsetMathScript::dy01(BufferView const & bv, int asc, int des, int what) con { int dasc = 0; int slevel = 0; - bool isCharBox = nuc().size() ? isAlphaSymbol(nuc().back()) : false; + bool isCharBox = !nuc().empty() ? isAlphaSymbol(nuc().back()) : false; if (hasDown()) { Dimension const & dimdown = down().dimension(bv); dasc = dimdown.ascent(); @@ -271,25 +271,25 @@ int InsetMathScript::dxx(BufferView const & bv) const int InsetMathScript::nwid(BufferView const & bv) const { - return nuc().size() ? nuc().dimension(bv).width() : 2; + return !nuc().empty() ? nuc().dimension(bv).width() : 2; } int InsetMathScript::nasc(BufferView const & bv) const { - return nuc().size() ? nuc().dimension(bv).ascent() : 5; + return !nuc().empty() ? nuc().dimension(bv).ascent() : 5; } int InsetMathScript::ndes(BufferView const & bv) const { - return nuc().size() ? nuc().dimension(bv).descent() : 0; + return !nuc().empty() ? nuc().dimension(bv).descent() : 0; } int InsetMathScript::nker(BufferView const * bv) const { - if (nuc().size()) { + if (!nuc().empty()) { int kerning = nuc().kerning(bv); return kerning > 0 ? kerning : 0; } @@ -351,7 +351,7 @@ void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathScript::draw(PainterInfo & pi, int x, int y) const { BufferView & bv = *pi.base.bv; - if (nuc().size()) + if (!nuc().empty()) nuc().draw(pi, x + dxx(bv), y); else { nuc().setXY(bv, x + dxx(bv), y); @@ -380,7 +380,7 @@ void InsetMathScript::metricsT(TextMetricsInfo const & mi, Dimension & dim) cons void InsetMathScript::drawT(TextPainter & pain, int x, int y) const { // FIXME: BROKEN - if (nuc().size()) + if (!nuc().empty()) nuc().drawT(pain, x + 1, y); if (hasUp()) up().drawT(pain, x + 1, y - 1 /*dy1()*/); @@ -399,7 +399,7 @@ bool InsetMathScript::hasLimits() const return false; // we can only display limits if the nucleus wants some - if (!nuc().size()) + if (nuc().empty()) return false; if (!nuc().back()->isScriptable()) return false; @@ -530,7 +530,7 @@ void InsetMathScript::write(WriteStream & os) const { MathEnsurer ensurer(os); - if (nuc().size()) { + if (!nuc().empty()) { os << nuc(); //if (nuc().back()->takesLimits()) { if (limits_ == -1) @@ -545,13 +545,13 @@ void InsetMathScript::write(WriteStream & os) const os << "{}"; } - if (hasDown() /*&& down().size()*/) + if (hasDown() /*&& !down().empty()*/) os << "_{" << down() << '}'; - if (hasUp() /*&& up().size()*/) { + if (hasUp() /*&& !up().empty()*/) { // insert space if up() is empty or an empty brace inset // (see bug 8305) - if (os.latex() && (up().size() == 0 || + if (os.latex() && (up().empty() || (up().size() == 1 && up().back()->asBraceInset() && up().back()->asBraceInset()->cell(0).empty()))) os << "^ {}"; @@ -566,8 +566,8 @@ void InsetMathScript::write(WriteStream & os) const void InsetMathScript::normalize(NormalStream & os) const { - bool d = hasDown() && down().size(); - bool u = hasUp() && up().size(); + bool d = hasDown() && !down().empty(); + bool u = hasUp() && !up().empty(); if (u && d) os << "[subsup "; @@ -576,7 +576,7 @@ void InsetMathScript::normalize(NormalStream & os) const else if (d) os << "[sub "; - if (nuc().size()) + if (!nuc().empty()) os << nuc() << ' '; else os << "[par]"; @@ -592,21 +592,21 @@ void InsetMathScript::normalize(NormalStream & os) const void InsetMathScript::maple(MapleStream & os) const { - if (nuc().size()) + if (!nuc().empty()) os << nuc(); - if (hasDown() && down().size()) + if (hasDown() && !down().empty()) os << '[' << down() << ']'; - if (hasUp() && up().size()) + if (hasUp() && !up().empty()) os << "^(" << up() << ')'; } void InsetMathScript::mathematica(MathematicaStream & os) const { - bool d = hasDown() && down().size(); - bool u = hasUp() && up().size(); + bool d = hasDown() && !down().empty(); + bool u = hasUp() && !up().empty(); - if (nuc().size()) { + if (!nuc().empty()) { if (d) os << "Subscript[" << nuc(); else @@ -616,7 +616,7 @@ void InsetMathScript::mathematica(MathematicaStream & os) const if (u) os << "^(" << up() << ')'; - if (nuc().size()) { + if (!nuc().empty()) { if (d) os << ',' << down() << ']'; } @@ -629,8 +629,8 @@ void InsetMathScript::mathematica(MathematicaStream & os) const // need to know if we're in a display formula. void InsetMathScript::mathmlize(MathStream & os) const { - bool d = hasDown() && down().size(); - bool u = hasUp() && up().size(); + bool d = hasDown() && !down().empty(); + bool u = hasUp() && !up().empty(); if (u && d) os << MTag("msubsup"); @@ -639,7 +639,7 @@ void InsetMathScript::mathmlize(MathStream & os) const else if (d) os << MTag("msub"); - if (nuc().size()) + if (!nuc().empty()) os << MTag("mrow") << nuc() << ETag("mrow"); else os << ""; @@ -657,10 +657,10 @@ void InsetMathScript::mathmlize(MathStream & os) const void InsetMathScript::htmlize(HtmlStream & os) const { - bool d = hasDown() && down().size(); - bool u = hasUp() && up().size(); + bool d = hasDown() && !down().empty(); + bool u = hasUp() && !up().empty(); - if (nuc().size()) + if (!nuc().empty()) os << nuc(); if (u && d) @@ -677,11 +677,11 @@ void InsetMathScript::htmlize(HtmlStream & os) const void InsetMathScript::octave(OctaveStream & os) const { - if (nuc().size()) + if (!nuc().empty()) os << nuc(); - if (hasDown() && down().size()) + if (hasDown() && !down().empty()) os << '[' << down() << ']'; - if (hasUp() && up().size()) + if (hasUp() && !up().empty()) os << "^(" << up() << ')'; } diff --git a/src/mathed/InsetMathXArrow.cpp b/src/mathed/InsetMathXArrow.cpp index 44799bac2f..eef5b4388c 100644 --- a/src/mathed/InsetMathXArrow.cpp +++ b/src/mathed/InsetMathXArrow.cpp @@ -64,7 +64,7 @@ void InsetMathXArrow::write(WriteStream & os) const { MathEnsurer ensurer(os); os << '\\' << name_; - if (cell(1).size()) + if (!cell(1).empty()) os << '[' << cell(1) << ']'; os << '{' << cell(0) << '}'; } diff --git a/src/mathed/InsetMathXYArrow.cpp b/src/mathed/InsetMathXYArrow.cpp index 69227564ee..0cb525c15a 100644 --- a/src/mathed/InsetMathXYArrow.cpp +++ b/src/mathed/InsetMathXYArrow.cpp @@ -142,9 +142,9 @@ void InsetMathXYArrow::write(WriteStream & os) const { MathEnsurer ensurer(os); os << "\\ar"; - if (cell(0).size()) + if (!cell(0).empty()) os << '[' << cell(0) << ']'; - if (cell(1).size()) + if (!cell(1).empty()) os << (up_ ? '^' : '_') << '{' << cell(1) << '}'; os << " "; } diff --git a/src/mathed/MathAutoCorrect.cpp b/src/mathed/MathAutoCorrect.cpp index fcc9f7705a..e49959a16d 100644 --- a/src/mathed/MathAutoCorrect.cpp +++ b/src/mathed/MathAutoCorrect.cpp @@ -149,7 +149,7 @@ void initAutoCorrect() string line; ifstream is(file.toFilesystemEncoding().c_str()); while (getline(is, line)) { - if (line.size() == 0 || line[0] == '#') { + if (line.empty() || line[0] == '#') { //LYXERR(Debug::MATHED, "ignoring line '" << line << '\''); continue; } diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index 12fb6c1907..2992c41f1d 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -339,13 +339,13 @@ void MathData::draw(PainterInfo & pi, int x, int y) const docstring s1 = completion.substr(0, uniqueTo); docstring s2 = completion.substr(uniqueTo); - if (s1.size() > 0) { + if (!s1.empty()) { f.setColor(Color_inlinecompletion); pi.pain.text(x, y, s1, f); x += mathed_string_width(f, s1); } - if (s2.size() > 0) { + if (!s2.empty()) { f.setColor(Color_nonunique_inlinecompletion); pi.pain.text(x, y, s2, f); x += mathed_string_width(f, s2); diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp index 8d1df06f77..d3bf738753 100644 --- a/src/mathed/MathExtern.cpp +++ b/src/mathed/MathExtern.cpp @@ -352,7 +352,7 @@ void splitScripts(MathData & ar) continue; // we must have a nucleus if we only have a superscript - if (!script->hasDown() && script->nuc().size() == 0) + if (!script->hasDown() && script->nuc().empty()) continue; if (script->nuc().size() == 1) { @@ -619,7 +619,7 @@ bool testIntegral(MathAtom const & at) return testIntSymbol(at) || ( at->asScriptInset() - && at->asScriptInset()->nuc().size() + && !at->asScriptInset()->nuc().empty() && testIntSymbol(at->asScriptInset()->nuc().back()) ); } @@ -719,7 +719,7 @@ bool testSum(MathAtom const & at) return testSumSymbol(at) || ( at->asScriptInset() - && at->asScriptInset()->nuc().size() + && !at->asScriptInset()->nuc().empty() && testSumSymbol(at->asScriptInset()->nuc().back()) ); } @@ -800,7 +800,7 @@ bool testDiffItem(MathAtom const & at) bool testDiffArray(MathData const & ar) { - return ar.size() && testDiffItem(ar.front()); + return !ar.empty() && testDiffItem(ar.front()); } @@ -1419,7 +1419,7 @@ void mathmlize(MathData const & dat, MathStream & os) { MathData ar = dat; extractStructure(ar, MATHML); - if (ar.size() == 0) + if (ar.empty()) os << ""; else if (ar.size() == 1) os << ar.front(); @@ -1436,7 +1436,7 @@ void htmlize(MathData const & dat, HtmlStream & os) { MathData ar = dat; extractStructure(ar, HTML); - if (ar.size() == 0) + if (ar.empty()) return; if (ar.size() == 1) { os << ar.front(); diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index cd9b757a51..1786e81c29 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -465,7 +465,7 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const void MathMacro::drawSelection(PainterInfo & pi, int x, int y) const { // We may have 0 arguments, but InsetMathNest requires at least one. - if (cells_.size() > 0) + if (!cells_.empty()) InsetMathNest::drawSelection(pi, x, y); } @@ -507,8 +507,7 @@ bool MathMacro::validName() const { docstring n = name(); - // empty name? - if (n.size() == 0) + if (n.empty()) return false; // converting back and force doesn't swallow anything? diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index 2d36e4d223..8220aa68a6 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -994,7 +994,7 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd) commitEditChanges(cur, cur); cur.recordUndoFullDocument(); size_t pos = numargs_; - if (arg.size() != 0) + if (!arg.empty()) pos = (size_t)convert(arg) - 1; // it is checked for >=0 in getStatus insertParameter(cur, cur, pos); } @@ -1006,7 +1006,7 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd) commitEditChanges(cur, cur); cur.recordUndoFullDocument(); size_t pos = numargs_ - 1; - if (arg.size() != 0) + if (!arg.empty()) pos = (size_t)convert(arg) - 1; // it is checked for >=0 in getStatus removeParameter(cur, cur, pos); } @@ -1080,7 +1080,7 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd, switch (cmd.action()) { case LFUN_MATH_MACRO_ADD_PARAM: { int num = numargs_ + 1; - if (arg.size() != 0) + if (!arg.empty()) num = convert(arg); bool on = (num >= optionals_ && numargs_ < 9 && num <= numargs_ + 1); @@ -1095,7 +1095,7 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd, case LFUN_MATH_MACRO_REMOVE_GREEDY_PARAM: case LFUN_MATH_MACRO_REMOVE_PARAM: { int num = numargs_; - if (arg.size() != 0) + if (!arg.empty()) num = convert(arg); flag.setEnabled(num >= 1 && num <= numargs_); break; @@ -1266,8 +1266,7 @@ bool MathMacroTemplate::validName() const { docstring n = name(); - // empty name? - if (n.size() == 0) + if (n.empty()) return false; // converting back and force doesn't swallow anything? @@ -1316,7 +1315,7 @@ bool MathMacroTemplate::fixNameAndCheckIfValid() } // now it should be valid if anything in the name survived - return data.size() > 0; + return !data.empty(); } diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 9752320095..1982af3c86 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -334,9 +334,9 @@ public: /// char_type character() const { return char_; } /// - docstring asString() const { return cs_.size() ? cs_ : docstring(1, char_); } + docstring asString() const { return !cs_.empty() ? cs_ : docstring(1, char_); } /// - docstring asInput() const { return cs_.size() ? '\\' + cs_ : docstring(1, char_); } + docstring asInput() const { return !cs_.empty() ? '\\' + cs_ : docstring(1, char_); } private: /// @@ -350,7 +350,7 @@ private: ostream & operator<<(ostream & os, Token const & t) { - if (t.cs().size()) { + if (!t.cs().empty()) { docstring const & cs = t.cs(); // FIXME: For some strange reason, the stream operator instanciate // a new Token before outputting the contents of t.cs(). @@ -951,7 +951,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, bool up = (t.cat() == catSuper); // we need no new script inset if the last thing was a scriptinset, // which has that script already not the same script already - if (!cell->size()) + if (cell->empty()) cell->push_back(MathAtom(new InsetMathScript(buf, up))); else if (cell->back()->asScriptInset() && !cell->back()->asScriptInset()->has(up)) @@ -1029,7 +1029,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // else if (t.cs() == "lyxlock") { - if (cell->size()) + if (!cell->empty()) cell->back().nucleus()->lock(true); } @@ -1377,7 +1377,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "sqrt") { MathData ar; parse(ar, FLAG_OPTION, mode); - if (ar.size()) { + if (!ar.empty()) { cell->push_back(MathAtom(new InsetMathRoot(buf))); cell->back().nucleus()->cell(0) = ar; parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode); @@ -1399,7 +1399,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // Allowed formats \unit[val]{unit} MathData ar; parse(ar, FLAG_OPTION, mode); - if (ar.size()) { + if (!ar.empty()) { cell->push_back(MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNIT))); cell->back().nucleus()->cell(0) = ar; parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode); @@ -1413,7 +1413,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // Here allowed formats are \unitfrac[val]{num}{denom} MathData ar; parse(ar, FLAG_OPTION, mode); - if (ar.size()) { + if (!ar.empty()) { cell->push_back(MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNITFRAC, 3))); cell->back().nucleus()->cell(2) = ar; } else { @@ -1845,10 +1845,10 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, rem.clear(); } else cmd.clear(); - } while (cmd.size()); + } while (!cmd.empty()); } - else if (t.cs().size()) { + else if (!t.cs().empty()) { bool const no_mhchem = (t.cs() == "ce" || t.cs() == "cf") && buf && buf->params().use_package("mhchem") == @@ -1979,7 +1979,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // this fails on \bigg[...\bigg] //MathData opt; //parse(opt, FLAG_OPTION, InsetMath::VERBATIM_MODE); - //if (opt.size()) { + //if (!opt.empty()) { // start = 1; // at.nucleus()->cell(0) = opt; //} diff --git a/src/rowpainter.cpp b/src/rowpainter.cpp index 7c7fd3ef41..0a902b7ef2 100644 --- a/src/rowpainter.cpp +++ b/src/rowpainter.cpp @@ -1111,13 +1111,13 @@ void RowPainter::paintInlineCompletion(Font const & font) swap(c1, c2); } - if (s1.size() > 0) { + if (!s1.empty()) { f.setColor(c1); pi_.pain.text(int(x_), yo_, s1, f); x_ += theFontMetrics(font).width(s1); } - if (s2.size() > 0) { + if (!s2.empty()) { f.setColor(c2); pi_.pain.text(int(x_), yo_, s2, f); x_ += theFontMetrics(font).width(s2); diff --git a/src/support/docstring.cpp b/src/support/docstring.cpp index d19c2e39be..c937ba3721 100644 --- a/src/support/docstring.cpp +++ b/src/support/docstring.cpp @@ -133,7 +133,7 @@ string const to_local8bit(docstring const & s) if (s.empty()) return string(); QByteArray const local = toqstr(s).toLocal8Bit(); - if (local.size() == 0) + if (local.isEmpty()) throw to_local8bit_failure(); return string(local.begin(), local.end()); } diff --git a/src/support/weighted_btree.h b/src/support/weighted_btree.h index 10f4793ff3..0b833740d0 100644 --- a/src/support/weighted_btree.h +++ b/src/support/weighted_btree.h @@ -1769,7 +1769,7 @@ public: clear(); key_less = other.key_comp(); - if (other.size() != 0) + if (!other.empty()) { stats.leaves = stats.innernodes = 0; root = copy_recursive(other.root); @@ -1788,7 +1788,7 @@ public: stats( other.stats ), key_less( other.key_comp() ) { - if (size() > 0) + if (!empty()) { stats.leaves = stats.innernodes = 0; root = copy_recursive(other.root); diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index e397c32fd7..01626f3a50 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -4384,7 +4384,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, /* string s = t.asInput(); string z = p.verbatim_item(); - while (p.good() && z != " " && z.size()) { + while (p.good() && z != " " && !z.empty()) { //cerr << "read: " << z << endl; s += z; z = p.verbatim_item();