summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-01-07 15:42:28 +0100
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-01-11 06:07:13 +0100
commit6a07ccbad273cdcbea3f984c5c2e9d1b272aae05 (patch)
treed389058bb3a66b0cce63331ce325ad34fee6ff22
parente85ecdd9254a8bd222ccb2dfed7d3b3bb96c8294 (diff)
downloadsubsurface-6a07ccbad273cdcbea3f984c5c2e9d1b272aae05.tar.gz
Use helper function empty_string() instead of manual checks
For code consistency, substitute boolean expressions: s && *s -> !empty_string(s) s && s[0] -> !empty_string(s) !s || !*s -> empty_string(s) !s || !s[0] -> empty_string(s) Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/divecomputer.cpp2
-rw-r--r--core/import-csv.c2
-rw-r--r--core/linux.c4
-rw-r--r--core/qthelper.cpp2
-rw-r--r--core/save-git.c4
-rw-r--r--core/uemis-downloader.c2
-rw-r--r--desktop-widgets/mainwindow.cpp4
-rw-r--r--qt-models/divetripmodel.cpp2
8 files changed, 11 insertions, 11 deletions
diff --git a/core/divecomputer.cpp b/core/divecomputer.cpp
index 820a20a51..43219ed05 100644
--- a/core/divecomputer.cpp
+++ b/core/divecomputer.cpp
@@ -158,7 +158,7 @@ extern "C" void set_dc_nickname(struct dive *dive)
struct divecomputer *dc;
for_each_dc (dive, dc) {
- if (dc->model && *dc->model && dc->deviceid &&
+ if (!empty_string(dc->model) && dc->deviceid &&
!dcList.getExact(dc->model, dc->deviceid)) {
// we don't have this one, yet
const DiveComputerNode *existNode = dcList.get(dc->model);
diff --git a/core/import-csv.c b/core/import-csv.c
index 347ef7896..f1a55950f 100644
--- a/core/import-csv.c
+++ b/core/import-csv.c
@@ -561,7 +561,7 @@ int parse_txt_file(const char *filename, const char *csv)
cur_cylinder_index++;
lineptr = strstr(memtxt.buffer, "Dive started at");
- while (lineptr && *lineptr && (lineptr = strchr(lineptr, '\n')) && ++lineptr) {
+ while (!empty_string(lineptr) && (lineptr = strchr(lineptr, '\n')) && ++lineptr) {
key = next_mkvi_key(lineptr);
if (!key)
break;
diff --git a/core/linux.c b/core/linux.c
index 5403990b7..2ae4d5c7e 100644
--- a/core/linux.c
+++ b/core/linux.c
@@ -31,12 +31,12 @@ void subsurface_user_info(struct user_info *user)
const char *username = getenv("USER");
if (pwd) {
- if (pwd->pw_gecos && *pwd->pw_gecos)
+ if (!empty_string(pwd->pw_gecos))
user->name = pwd->pw_gecos;
if (!username)
username = pwd->pw_name;
}
- if (username && *username) {
+ if (!empty_string(username)) {
char hostname[64];
struct membuffer mb = {};
gethostname(hostname, sizeof(hostname));
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index 6916b1a68..262399a5f 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -1163,7 +1163,7 @@ QString localFilePath(const QString originalFilename)
QString fileFromHash(const char *hash)
{
- if (!hash || !*hash)
+ if (empty_string(hash))
return "";
QMutexLocker locker(&hashOfMutex);
diff --git a/core/save-git.c b/core/save-git.c
index 6eab07580..287a8bab9 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -1088,11 +1088,11 @@ static void create_commit_message(struct membuffer *msg, bool create_empty)
nr = dive->number;
put_format(msg, "dive %d: %s", nr, location);
- if (trip && trip->location && *trip->location && strcmp(trip->location, location))
+ if (trip && !empty_string(trip->location) && strcmp(trip->location, location))
put_format(msg, " (%s)", trip->location);
put_format(msg, "\n");
do {
- if (dc->model && *dc->model) {
+ if (!empty_string(dc->model)) {
put_format(msg, "%s%s", sep, dc->model);
sep = ", ";
}
diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c
index 8909ee381..b327f29e8 100644
--- a/core/uemis-downloader.c
+++ b/core/uemis-downloader.c
@@ -112,7 +112,7 @@ static void uemis_add_string(const char *buffer, char **text, const char *delimi
{
/* do nothing if this is an empty buffer (Uemis sometimes returns a single
* space for empty buffers) */
- if (!buffer || !*buffer || (*buffer == ' ' && *(buffer + 1) == '\0'))
+ if (empty_string(buffer) || (*buffer == ' ' && *(buffer + 1) == '\0'))
return;
if (!*text) {
*text = strdup(buffer);
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 93df3aea9..5cf3dc27f 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -102,7 +102,7 @@ extern "C" void showErrorFromC()
void MainWindow::showErrors()
{
const char *error = get_error_string();
- if (error && error[0])
+ if (!empty_string(error))
getNotificationWidget()->showNotification(error, KMessageWidget::Error);
}
@@ -1766,7 +1766,7 @@ void MainWindow::setAutomaticTitle()
void MainWindow::setTitle()
{
- if (!existing_filename || !existing_filename[0]) {
+ if (empty_string(existing_filename)) {
setWindowTitle("Subsurface");
return;
}
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index b2ca11844..63e5f6afd 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -70,7 +70,7 @@ QVariant TripItem::data(int column, int role) const
}
if (countShown < trip->nrdives)
shownText = tr("(%1 shown)").arg(countShown);
- if (trip->location && *trip->location)
+ if (!empty_string(trip->location))
ret = QString(trip->location) + ", " + get_trip_date_string(trip->when, trip->nrdives, oneDayTrip) + " "+ shownText;
else
ret = get_trip_date_string(trip->when, trip->nrdives, oneDayTrip) + shownText;