Add braces around single line statements

* Ran clang-tidy with "readability-braces-around-statements" to find missing braces around statements.
This commit is contained in:
Jonathan White 2020-01-07 22:06:31 -05:00
parent c427000184
commit c663b5d5fc
12 changed files with 98 additions and 54 deletions

View File

@ -67,15 +67,17 @@ bool CsvParser::parse(QFile* device)
appendStatusMsg(QObject::tr("NULL device"), true);
return false;
}
if (!readFile(device))
if (!readFile(device)) {
return false;
}
return parseFile();
}
bool CsvParser::readFile(QFile* device)
{
if (device->isOpen())
if (device->isOpen()) {
device->close();
}
device->open(QIODevice::ReadOnly);
if (!Tools::readAllFromDevice(device, m_array)) {
@ -86,8 +88,9 @@ bool CsvParser::readFile(QFile* device)
m_array.replace("\r\n", "\n");
m_array.replace("\r", "\n");
if (0 == m_array.size())
if (0 == m_array.size()) {
appendStatusMsg(QObject::tr("file empty").append("\n"));
}
m_isFileLoaded = true;
}
return m_isFileLoaded;
@ -124,8 +127,9 @@ bool CsvParser::parseFile()
{
parseRecord();
while (!m_isEof) {
if (!skipEndline())
if (!skipEndline()) {
appendStatusMsg(QObject::tr("malformed string"), true);
}
m_currRow++;
m_currCol = 1;
parseRecord();
@ -146,15 +150,17 @@ void CsvParser::parseRecord()
getChar(m_ch);
} while (isSeparator(m_ch) && !m_isEof);
if (!m_isEof)
if (!m_isEof) {
ungetChar();
}
if (isEmptyRow(row)) {
row.clear();
return;
}
m_table.push_back(row);
if (m_maxCols < row.size())
if (m_maxCols < row.size()) {
m_maxCols = row.size();
}
m_currCol++;
}
@ -163,10 +169,11 @@ void CsvParser::parseField(CsvRow& row)
QString field;
peek(m_ch);
if (!isTerminator(m_ch)) {
if (isQualifier(m_ch))
if (isQualifier(m_ch)) {
parseQuoted(field);
else
} else {
parseSimple(field);
}
}
row.push_back(field);
}
@ -179,8 +186,9 @@ void CsvParser::parseSimple(QString& s)
s.append(c);
getChar(c);
}
if (!m_isEof)
if (!m_isEof) {
ungetChar();
}
}
void CsvParser::parseQuoted(QString& s)
@ -189,17 +197,20 @@ void CsvParser::parseQuoted(QString& s)
getChar(m_ch);
parseEscaped(s);
// getChar(m_ch);
if (!isQualifier(m_ch))
if (!isQualifier(m_ch)) {
appendStatusMsg(QObject::tr("missing closing quote"), true);
}
}
void CsvParser::parseEscaped(QString& s)
{
parseEscapedText(s);
while (processEscapeMark(s, m_ch))
while (processEscapeMark(s, m_ch)) {
parseEscapedText(s);
if (!m_isEof)
}
if (!m_isEof) {
ungetChar();
}
}
void CsvParser::parseEscapedText(QString& s)
@ -233,8 +244,9 @@ bool CsvParser::processEscapeMark(QString& s, QChar c)
}
} else {
// double quote syntax, e.g. ""
if (!isQualifier(c))
if (!isQualifier(c)) {
return false;
}
peek(c2);
if (!m_isEof) { // not EOF, can read one char
if (isQualifier(c2)) {
@ -294,16 +306,18 @@ void CsvParser::ungetChar()
void CsvParser::peek(QChar& c)
{
getChar(c);
if (!m_isEof)
if (!m_isEof) {
ungetChar();
}
}
bool CsvParser::isQualifier(const QChar& c) const
{
if (true == m_isBackslashSyntax && (c != m_qualifier))
if (true == m_isBackslashSyntax && (c != m_qualifier)) {
return (c == '\\');
else
} else {
return (c == m_qualifier);
}
}
bool CsvParser::isComment()
@ -312,12 +326,13 @@ bool CsvParser::isComment()
QChar c2;
qint64 pos = m_ts.pos();
do
do {
getChar(c2);
while ((isSpace(c2) || isTab(c2)) && (!m_isEof));
} while ((isSpace(c2) || isTab(c2)) && (!m_isEof));
if (c2 == m_comment)
if (c2 == m_comment) {
result = true;
}
m_ts.seek(pos);
return result;
}
@ -330,9 +345,11 @@ bool CsvParser::isText(QChar c) const
bool CsvParser::isEmptyRow(const CsvRow& row) const
{
CsvRow::const_iterator it = row.constBegin();
for (; it != row.constEnd(); ++it)
if (((*it) != "\n") && ((*it) != ""))
for (; it != row.constEnd(); ++it) {
if (((*it) != "\n") && ((*it) != "")) {
return false;
}
}
return true;
}

View File

@ -779,8 +779,9 @@ Entry* Entry::clone(CloneFlags flags) const
entry->m_data.timeInfo.setLocationChanged(now);
}
if (flags & CloneRenameTitle)
if (flags & CloneRenameTitle) {
entry->setTitle(tr("%1 - Clone").arg(entry->title()));
}
entry->setUpdateTimeinfo(true);
@ -1075,8 +1076,9 @@ QString Entry::resolvePlaceholder(const QString& placeholder) const
QString Entry::resolveUrlPlaceholder(const QString& str, Entry::PlaceholderType placeholderType) const
{
if (str.isEmpty())
if (str.isEmpty()) {
return QString();
}
const QUrl qurl(str);
switch (placeholderType) {

View File

@ -113,8 +113,9 @@ namespace Tools
extensions += "\n- " + QObject::tr("Secret Service Integration");
#endif
if (extensions.isEmpty())
if (extensions.isEmpty()) {
extensions = " " + QObject::tr("None");
}
debugInfo.append(QObject::tr("Enabled extensions:").append(extensions).append("\n"));
return debugInfo;

View File

@ -28,8 +28,9 @@ namespace
{
QString PixmapToHTML(const QPixmap& pixmap)
{
if (pixmap.isNull())
if (pixmap.isNull()) {
return "";
}
// Based on https://stackoverflow.com/a/6621278
QByteArray a;

View File

@ -65,8 +65,9 @@ QStringList FileDialog::getOpenFileNames(QWidget* parent,
const auto& workingDir = dir.isEmpty() ? config()->get("LastDir").toString() : dir;
auto results = QFileDialog::getOpenFileNames(parent, caption, workingDir, filter, selectedFilter, options);
for (auto& path : results)
for (auto& path : results) {
path = QDir::toNativeSeparators(path);
}
#ifdef Q_OS_MACOS
// on Mac OS X the focus is lost after closing the native dialog

View File

@ -294,27 +294,30 @@ void CsvImportWidget::setRootGroup()
for (int r = 0; r < m_parserModel->rowCount(); ++r) {
// use validity of second column as a GO/NOGO for all others fields
if (not m_parserModel->data(m_parserModel->index(r, 1)).isValid())
if (not m_parserModel->data(m_parserModel->index(r, 1)).isValid()) {
continue;
}
groupLabel = m_parserModel->data(m_parserModel->index(r, 0)).toString();
// check if group name is either "root", "" (empty) or some other label
groupList = groupLabel.split("/", QString::SkipEmptyParts);
if (groupList.isEmpty())
if (groupList.isEmpty()) {
is_empty = true;
else if (not groupList.first().compare("Root", Qt::CaseSensitive))
} else if (not groupList.first().compare("Root", Qt::CaseSensitive)) {
is_root = true;
else if (not groupLabel.compare(""))
} else if (not groupLabel.compare("")) {
is_empty = true;
else
} else {
is_label = true;
}
groupList.clear();
}
if ((is_empty and is_root) or (is_label and not is_empty and is_root))
if ((is_empty and is_root) or (is_label and not is_empty and is_root)) {
m_db->rootGroup()->setName("CSV IMPORTED");
else
} else {
m_db->rootGroup()->setName("Root");
}
}
Group* CsvImportWidget::splitGroups(const QString& label)

View File

@ -55,8 +55,9 @@ bool CsvParserModel::parse()
QFile csv(m_filename);
r = CsvParser::parse(&csv);
}
for (int i = 0; i < columnCount(); ++i)
for (int i = 0; i < columnCount(); ++i) {
m_columnMap.insert(i, 0);
}
addEmptyColumn();
endResetModel();
return r;
@ -73,13 +74,15 @@ void CsvParserModel::addEmptyColumn()
void CsvParserModel::mapColumns(int csvColumn, int dbColumn)
{
if ((csvColumn < 0) || (dbColumn < 0))
if ((csvColumn < 0) || (dbColumn < 0)) {
return;
}
beginResetModel();
if (csvColumn >= getCsvCols())
if (csvColumn >= getCsvCols()) {
m_columnMap[dbColumn] = 0; // map to the empty column
else
} else {
m_columnMap[dbColumn] = csvColumn;
}
endResetModel();
}
@ -99,15 +102,17 @@ void CsvParserModel::setHeaderLabels(const QStringList& labels)
int CsvParserModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid())
if (parent.isValid()) {
return 0;
}
return getCsvRows();
}
int CsvParserModel::columnCount(const QModelIndex& parent) const
{
if (parent.isValid())
if (parent.isValid()) {
return 0;
}
return m_columnHeader.size();
}
@ -116,8 +121,9 @@ QVariant CsvParserModel::data(const QModelIndex& index, int role) const
if ((index.column() >= m_columnHeader.size()) || (index.row() + m_skipped >= rowCount()) || !index.isValid()) {
return QVariant();
}
if (role == Qt::DisplayRole)
if (role == Qt::DisplayRole) {
return m_table.at(index.row() + m_skipped).at(m_columnMap[index.column()]);
}
return QVariant();
}
@ -125,12 +131,14 @@ QVariant CsvParserModel::headerData(int section, Qt::Orientation orientation, in
{
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
if ((section < 0) || (section >= m_columnHeader.size()))
if ((section < 0) || (section >= m_columnHeader.size())) {
return QVariant();
}
return m_columnHeader.at(section);
} else if (orientation == Qt::Vertical) {
if (section + m_skipped >= rowCount())
if (section + m_skipped >= rowCount()) {
return QVariant();
}
return QString::number(section + 1);
}
}

View File

@ -155,10 +155,11 @@ void GroupView::syncExpandedState(const QModelIndex& parent, int start, int end)
void GroupView::setCurrentGroup(Group* group)
{
if (group == nullptr)
if (group == nullptr) {
setCurrentIndex(QModelIndex());
else
} else {
setCurrentIndex(m_model->index(group));
}
}
void GroupView::modelReset()

View File

@ -56,8 +56,9 @@ QString ElidedLabel::url() const
void ElidedLabel::setElideMode(Qt::TextElideMode elideMode)
{
if (m_elideMode == elideMode)
if (m_elideMode == elideMode) {
return;
}
if (m_elideMode != Qt::ElideNone) {
setWordWrap(false);
@ -69,8 +70,9 @@ void ElidedLabel::setElideMode(Qt::TextElideMode elideMode)
void ElidedLabel::setRawText(const QString& elidedText)
{
if (m_rawText == elidedText)
if (m_rawText == elidedText) {
return;
}
m_rawText = elidedText;
emit rawTextChanged(m_rawText);
@ -78,8 +80,9 @@ void ElidedLabel::setRawText(const QString& elidedText)
void ElidedLabel::setUrl(const QString& url)
{
if (m_url == url)
if (m_url == url) {
return;
}
m_url = url;
emit urlChanged(m_url);

View File

@ -30,8 +30,9 @@ void TestCsvParser::initTestCase()
void TestCsvParser::init()
{
file.reset(new QTemporaryFile());
if (not file->open())
if (not file->open()) {
QFAIL("Cannot open file!");
}
parser->setBackslashSyntax(false);
parser->setComment('#');
parser->setFieldSeparator(',');

View File

@ -289,14 +289,16 @@ void TestSymmetricCipher::testTwofish256CbcEncryption()
QCOMPARE(cipher.blockSize(), 16);
for (int j = 0; j < 5000; ++j) {
ctCur = cipher.process(ptNext, &ok);
if (!ok)
if (!ok) {
break;
}
ptNext = ctPrev;
ctPrev = ctCur;
ctCur = cipher.process(ptNext, &ok);
if (!ok)
if (!ok) {
break;
}
ptNext = ctPrev;
ctPrev = ctCur;
}
@ -342,13 +344,15 @@ void TestSymmetricCipher::testTwofish256CbcDecryption()
QCOMPARE(cipher.blockSize(), 16);
for (int j = 0; j < 5000; ++j) {
ptCur = cipher.process(ctNext, &ok);
if (!ok)
if (!ok) {
break;
}
ctNext = ptCur;
ptCur = cipher.process(ctNext, &ok);
if (!ok)
if (!ok) {
break;
}
ctNext = ptCur;
}

View File

@ -84,12 +84,14 @@ void TestYubiKeyChalResp::ykDetected(int slot, bool blocking)
{
Q_UNUSED(blocking);
if (slot > 0)
if (slot > 0) {
m_detected++;
}
/* Key used for later testing */
if (!m_key)
if (!m_key) {
m_key.reset(new YkChallengeResponseKey(slot, blocking));
}
}
void TestYubiKeyChalResp::deinit()