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>
This commit is contained in:
Berthold Stoeger 2018-01-07 15:42:28 +01:00 committed by Lubomir I. Ivanov
parent e85ecdd925
commit 6a07ccbad2
8 changed files with 11 additions and 11 deletions

View file

@ -158,7 +158,7 @@ extern "C" void set_dc_nickname(struct dive *dive)
struct divecomputer *dc; struct divecomputer *dc;
for_each_dc (dive, 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)) { !dcList.getExact(dc->model, dc->deviceid)) {
// we don't have this one, yet // we don't have this one, yet
const DiveComputerNode *existNode = dcList.get(dc->model); const DiveComputerNode *existNode = dcList.get(dc->model);

View file

@ -561,7 +561,7 @@ int parse_txt_file(const char *filename, const char *csv)
cur_cylinder_index++; cur_cylinder_index++;
lineptr = strstr(memtxt.buffer, "Dive started at"); 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); key = next_mkvi_key(lineptr);
if (!key) if (!key)
break; break;

View file

@ -31,12 +31,12 @@ void subsurface_user_info(struct user_info *user)
const char *username = getenv("USER"); const char *username = getenv("USER");
if (pwd) { if (pwd) {
if (pwd->pw_gecos && *pwd->pw_gecos) if (!empty_string(pwd->pw_gecos))
user->name = pwd->pw_gecos; user->name = pwd->pw_gecos;
if (!username) if (!username)
username = pwd->pw_name; username = pwd->pw_name;
} }
if (username && *username) { if (!empty_string(username)) {
char hostname[64]; char hostname[64];
struct membuffer mb = {}; struct membuffer mb = {};
gethostname(hostname, sizeof(hostname)); gethostname(hostname, sizeof(hostname));

View file

@ -1163,7 +1163,7 @@ QString localFilePath(const QString originalFilename)
QString fileFromHash(const char *hash) QString fileFromHash(const char *hash)
{ {
if (!hash || !*hash) if (empty_string(hash))
return ""; return "";
QMutexLocker locker(&hashOfMutex); QMutexLocker locker(&hashOfMutex);

View file

@ -1088,11 +1088,11 @@ static void create_commit_message(struct membuffer *msg, bool create_empty)
nr = dive->number; nr = dive->number;
put_format(msg, "dive %d: %s", nr, location); 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, " (%s)", trip->location);
put_format(msg, "\n"); put_format(msg, "\n");
do { do {
if (dc->model && *dc->model) { if (!empty_string(dc->model)) {
put_format(msg, "%s%s", sep, dc->model); put_format(msg, "%s%s", sep, dc->model);
sep = ", "; sep = ", ";
} }

View file

@ -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 /* do nothing if this is an empty buffer (Uemis sometimes returns a single
* space for empty buffers) */ * space for empty buffers) */
if (!buffer || !*buffer || (*buffer == ' ' && *(buffer + 1) == '\0')) if (empty_string(buffer) || (*buffer == ' ' && *(buffer + 1) == '\0'))
return; return;
if (!*text) { if (!*text) {
*text = strdup(buffer); *text = strdup(buffer);

View file

@ -102,7 +102,7 @@ extern "C" void showErrorFromC()
void MainWindow::showErrors() void MainWindow::showErrors()
{ {
const char *error = get_error_string(); const char *error = get_error_string();
if (error && error[0]) if (!empty_string(error))
getNotificationWidget()->showNotification(error, KMessageWidget::Error); getNotificationWidget()->showNotification(error, KMessageWidget::Error);
} }
@ -1766,7 +1766,7 @@ void MainWindow::setAutomaticTitle()
void MainWindow::setTitle() void MainWindow::setTitle()
{ {
if (!existing_filename || !existing_filename[0]) { if (empty_string(existing_filename)) {
setWindowTitle("Subsurface"); setWindowTitle("Subsurface");
return; return;
} }

View file

@ -70,7 +70,7 @@ QVariant TripItem::data(int column, int role) const
} }
if (countShown < trip->nrdives) if (countShown < trip->nrdives)
shownText = tr("(%1 shown)").arg(countShown); 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; ret = QString(trip->location) + ", " + get_trip_date_string(trip->when, trip->nrdives, oneDayTrip) + " "+ shownText;
else else
ret = get_trip_date_string(trip->when, trip->nrdives, oneDayTrip) + shownText; ret = get_trip_date_string(trip->when, trip->nrdives, oneDayTrip) + shownText;