Refactoring based on cppcheck suggestions

This commit is contained in:
Yuriy Skalko 2020-10-01 13:34:15 +03:00 committed by Jean-Marc Lasgouttes
parent a43d8501a2
commit 715b8cda54
34 changed files with 49 additions and 59 deletions

View File

@ -53,8 +53,7 @@ docstring Author::nameAndEmail() const
{
if (email().empty())
return name();
else
return bformat(_("%1$s[[name]] (%2$s[[email]])"), name(), email());
return bformat(_("%1$s[[name]] (%2$s[[email]])"), name(), email());
}

View File

@ -1549,9 +1549,8 @@ bool Buffer::save() const
// time stamp is invalidated by copying/moving
saveCheckSum();
markClean();
if (d->file_format != LYX_FORMAT)
// the file associated with this buffer is now in the current format
d->file_format = LYX_FORMAT;
// the file associated with this buffer is now in the current format
d->file_format = LYX_FORMAT;
return true;
}
// else we saved the file, but failed to move it to the right location.

View File

@ -232,7 +232,7 @@ public:
///
Impl(Compare const & compare)
: abort_(false), n_(0), m_(0), offset_reverse_diagonal_(0),
odd_offset_(0), compare_(compare),
odd_offset_(false), compare_(compare),
old_buf_(nullptr), new_buf_(nullptr), dest_buf_(nullptr),
dest_pars_(nullptr), recursion_level_(0), nested_inset_level_(0), D_(0)
{}
@ -413,7 +413,6 @@ void Compare::run()
static_cast<InsetText &>(dest_buffer->inset()), el);
finished(pimpl_->abort_);
return;
}

View File

@ -737,7 +737,7 @@ void region(CursorSlice const & i1, CursorSlice const & i2,
Inset::row_type & r1, Inset::row_type & r2,
Inset::col_type & c1, Inset::col_type & c2)
{
Inset & p = i1.inset();
Inset const & p = i1.inset();
c1 = p.col(i1.idx());
c2 = p.col(i2.idx());
if (c1 > c2)
@ -1079,7 +1079,7 @@ void copySelectionToStack()
}
void copySelectionToTemp(Cursor & cur)
void copySelectionToTemp(Cursor const & cur)
{
copySelectionToStack(cur, tempCut);
}

View File

@ -66,7 +66,7 @@ void cutSelectionToTemp(Cursor & cur, bool realcut = true);
/// Push the current selection to the cut buffer and the system clipboard.
void copySelection(Cursor const & cur);
/// Like copySelection, but only put to temporary cut buffer
void copySelectionToTemp(Cursor & cur);
void copySelectionToTemp(Cursor const & cur);
///
void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext);
/**

View File

@ -1648,7 +1648,6 @@ int LaTeX::scanIlgFile(TeXErrors & terr)
string prevtoken;
while (getline(ifs, token)) {
token = rtrim(token, "\r");
smatch sub;
if (prefixIs(token, "!! "))
prevtoken = token;
else if (!prevtoken.empty()) {

View File

@ -522,10 +522,10 @@ bool LaTeXFont::readFont(Lexer & lex)
bool LaTeXFont::read(Lexer & lex)
{
switchdefault_ = 0;
osfdefault_ = 0;
moreopts_ = 0;
osffontonly_ = 0;
switchdefault_ = false;
osfdefault_ = false;
moreopts_ = false;
osffontonly_ = false;
if (!lex.next()) {
lex.printError("No name given for LaTeX font: `$$Token'.");

View File

@ -278,9 +278,9 @@ bool Language::readLanguage(Lexer & lex)
bool Language::read(Lexer & lex)
{
encoding_ = 0;
internal_enc_ = 0;
rightToLeft_ = 0;
encoding_ = nullptr;
internal_enc_ = false;
rightToLeft_ = false;
if (!lex.next()) {
lex.printError("No name given for language: `$$Token'.");

View File

@ -1087,7 +1087,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
runparams.local_font = &basefont;
}
if (fontswitch_inset && !closeLanguage && fontswitch_inset) {
if (fontswitch_inset && !closeLanguage) {
// The directionality has been switched at inset.
// Force markup inside.
runparams.local_font = &basefont;

View File

@ -94,11 +94,11 @@ public:
};
/// Increase or decrease the nesting depth of the selected paragraph(s)
/// FIXME: replace Cursor with DocIterator.
void changeDepth(Cursor & cur, DEPTH_CHANGE type);
void changeDepth(Cursor const & cur, DEPTH_CHANGE type);
/// Returns whether something would be changed by changeDepth
/// FIXME: replace Cursor with DocIterator.
bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
bool changeDepthAllowed(Cursor const & cur, DEPTH_CHANGE type) const;
/// Set font over selection paragraphs and rebreak.
/// FIXME: replace Cursor with DocIterator.
@ -356,7 +356,7 @@ private:
/// handle the case where bibitems were deleted
bool handleBibitems(Cursor & cur);
/// are we in a list item (description etc.)?
bool inDescriptionItem(Cursor & cur) const;
bool inDescriptionItem(Cursor const & cur) const;
///
void charInserted(Cursor & cur);
/// set 'number' font property

View File

@ -222,7 +222,7 @@ static bool changeDepthAllowed(Text::DEPTH_CHANGE type,
}
bool Text::changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const
bool Text::changeDepthAllowed(Cursor const & cur, DEPTH_CHANGE type) const
{
LBUFERR(this == cur.text());
// this happens when selecting several cells in tabular (bug 2630)
@ -242,7 +242,7 @@ bool Text::changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const
}
void Text::changeDepth(Cursor & cur, DEPTH_CHANGE type)
void Text::changeDepth(Cursor const & cur, DEPTH_CHANGE type)
{
LBUFERR(this == cur.text());
pit_type const beg = cur.selBegin().pit();

View File

@ -3683,9 +3683,9 @@ void Text::pasteString(Cursor & cur, docstring const & clip,
// FIXME: an item inset would make things much easier.
bool Text::inDescriptionItem(Cursor & cur) const
bool Text::inDescriptionItem(Cursor const & cur) const
{
Paragraph & par = cur.paragraph();
Paragraph const & par = cur.paragraph();
pos_type const pos = cur.pos();
pos_type const body_pos = par.beginOfBody();

View File

@ -221,7 +221,7 @@ void TextMetrics::newParMetricsUp()
}
bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width,
bool TextMetrics::metrics(MetricsInfo const & mi, Dimension & dim, int min_width,
bool const expand_on_multipars)
{
LBUFERR(mi.base.textwidth > 0);
@ -676,7 +676,7 @@ void TextMetrics::setRowAlignment(Row & row, int width) const
}
// are there any hfills in the row?
ParagraphMetrics & pm = par_metrics_[row.pit()];
ParagraphMetrics const & pm = par_metrics_[row.pit()];
int nh = numberOfHfills(row, pm, par.beginOfBody());
int hfill = 0;
int hfill_rem = 0;

View File

@ -71,7 +71,7 @@ public:
void newParMetricsUp();
/// compute text metrics.
bool metrics(MetricsInfo & mi, Dimension & dim, int min_width = 0,
bool metrics(MetricsInfo const & mi, Dimension & dim, int min_width = 0,
bool const expand_on_multipars = true);
/// The "nodraw" drawing stage for one single paragraph: set the

View File

@ -180,7 +180,7 @@ bool TocBackend::updateItem(DocIterator const & dit_in)
//
// FIXME: This is supposed to accomplish the same as the body of
// InsetText::iterateForToc(), probably
Paragraph & par = toc_item->dit().paragraph();
Paragraph const & par = toc_item->dit().paragraph();
for (auto const & table : par.insetList())
if (InsetArgument const * arg = table.inset->asInsetArgument()) {
tocstring = par.labelString();

View File

@ -200,9 +200,7 @@ void Trans::addDeadkey(tex_accent accent, docstring const & keys)
int Trans::load(Lexer & lex)
{
bool error = false;
while (lex.isOK() && !error) {
while (lex.isOK()) {
switch (lex.lex()) {
case KMOD:
{

View File

@ -108,7 +108,7 @@ bool FindAndReplaceWidget::eventFilter(QObject * obj, QEvent * event)
// with shift we (temporarily) change search/replace direction
bool const searchback = searchbackCB->isChecked();
if (e->modifiers() == Qt::ShiftModifier && !searchback)
searchbackCB->setChecked(!searchback);
searchbackCB->setChecked(true);
if (obj == find_work_area_)
on_findNextPB_clicked();

View File

@ -269,7 +269,7 @@ void GuiBibtex::clearSelection()
}
void GuiBibtex::setSelectedBibs(QStringList const sl)
void GuiBibtex::setSelectedBibs(QStringList const & sl)
{
selected_model_.clear();
QStringList headers;

View File

@ -75,7 +75,7 @@ private:
/// Clear selected keys
void clearSelection();
/// Set selected keys
void setSelectedBibs(QStringList const);
void setSelectedBibs(QStringList const &);
/// prepares a call to GuiCitation::searchKeys when we
/// are ready to search the Bib entries
void findText(QString const & text);

View File

@ -286,8 +286,8 @@ void GuiBox::on_pagebreakCB_stateChanged()
{
bool pbreak = (pagebreakCB->checkState() == Qt::Checked);
if (pbreak)
widthCB->setChecked(!pbreak);
if (!pbreak) {
widthCB->setChecked(false);
else {
on_typeCO_activated(typeCO->currentIndex());
return;
}

View File

@ -654,7 +654,7 @@ void GuiCitation::clearSelection()
}
void GuiCitation::setSelectedKeys(QStringList const sl)
void GuiCitation::setSelectedKeys(QStringList const & sl)
{
selected_model_.clear();
selected_model_.setColumnCount(3);

View File

@ -117,7 +117,7 @@ private:
void clearSelection();
/// Set selected keys
void setSelectedKeys(QStringList const);
void setSelectedKeys(QStringList const &);
/// Get selected keys
QStringList selectedKeys();
/// Set pre texts of qualified lists

View File

@ -569,7 +569,7 @@ void GuiLyXFiles::passParams(string const & data)
}
void GuiLyXFiles::selectItem(QString const item)
void GuiLyXFiles::selectItem(QString const & item)
{
/* Using an intermediary variable flags is needed up to at least
* Qt 5.5 because of a subtle namespace issue. See:

View File

@ -35,7 +35,7 @@ public:
/// A way to pass params to the dialog directly
void passParams(std::string const & data);
/// A way to pass params to the dialog directly
void selectItem(QString const item);
void selectItem(QString const & item);
Q_SIGNALS:
void fileSelected(QString const file);

View File

@ -357,11 +357,10 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
bool whole, bool forward, bool findnext)
{
Cursor & cur = bv->cursor();
bool found = false;
if (!cur.selection()) {
// no selection, non-empty search string: find it
if (!searchstr.empty()) {
found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
bool found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
return make_pair(found, 0);
}
// empty search string
@ -390,7 +389,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
// no selection or current selection is not search word:
// just find the search word
if (!have_selection || !match) {
found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
bool found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
return make_pair(found, 0);
}

View File

@ -129,7 +129,7 @@ WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
OutputType output, Encoding const * encoding)
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
output_(output), pendingspace_(false), pendingbrace_(false),
textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
textmode_(false), locked_(false), ascii_(false), canbreakline_(true),
mathsout_(false), ulemcmd_(NONE), line_(0), encoding_(encoding),
row_entry_(TexRow::row_none), mathclass_(false)
{}

View File

@ -1668,7 +1668,7 @@ void latexParagraphs(Buffer const & buf,
|| par->params().leftIndent() == nextpar->params().leftIndent())
&& !runparams.for_search && cpar.size() > 0
&& cpar.isDeleted(0, cpar.size()) && !bparams.output_changes) {
if (!bparams.output_changes && !cpar.parEndChange().deleted())
if (!cpar.parEndChange().deleted())
os << '\n' << '\n';
continue;
}

View File

@ -448,7 +448,7 @@ ForkedCall::sigPtr add(string const & process);
static queue<Process> callQueue_;
/// flag whether queue is running
static bool running_ = 0;
static bool running_ = false;
///
void startCaller();

View File

@ -134,7 +134,7 @@ Debug::Type Debug::value(string const & val)
break;
}
if (st == string::npos)
break;
break;
v.erase(0, st + 1);
}
return l;

View File

@ -344,8 +344,7 @@ protected:
const int c = wctob(i);
if (c == EOF)
break;
else
M_narrow[i] = static_cast<char>(c);
M_narrow[i] = static_cast<char>(c);
}
if (i == 128)
M_narrow_ok = true;

View File

@ -497,8 +497,7 @@ void removeTempFile(FileName const & fn)
return;
string const abs = fn.absFileName();
if (tmp_names_.find(abs) != tmp_names_.end())
tmp_names_.erase(abs);
tmp_names_.erase(abs);
fn.removeFile();
}

View File

@ -252,8 +252,8 @@ IconvProcessor & getProc(map<string, IconvProcessor> & processors,
if (it == processors.end()) {
IconvProcessor p(fromcode, tocode);
return processors.insert(make_pair(encoding, move(p))).first->second;
} else
return it->second;
}
return it->second;
}
} // namespace

View File

@ -2764,7 +2764,6 @@ void Preamble::parse(Parser & p, string const & forceclass,
// paper sizes
// some size options are known by the document class, other sizes
// are handled by the \geometry command of the geometry package
string paper;
vector<string> class_psizes = getVectorFromString(tc.opt_pagesize(), "|");
string const psize_format = tc.pagesizeformat();
for (auto const & psize : class_psizes) {

View File

@ -48,7 +48,7 @@ extern std::string rgbcolor2code(std::string const & name);
std::string translate_len(std::string const &);
void parse_text(Parser & p, std::ostream & os, unsigned flags, bool outer,
Context & context, std::string const & rdelim = std::string());
Context & context, std::string const & rdelim = "");
void check_comment_bib(std::ostream & os, Context & context);
void fix_child_filename(std::string & name);
@ -67,8 +67,8 @@ std::string find_file(std::string const & name, std::string const & path,
*/
void parse_text_in_inset(Parser & p, std::ostream & os, unsigned flags,
bool outer, Context const & context,
InsetLayout const * layout = 0,
std::string const & rdelim = std::string());
InsetLayout const * layout = nullptr,
std::string const & rdelim = "");
/// Guess document language from \p p if CJK is used.
/// \p lang is used for all non-CJK contents.