From bb02897bc84cf01c9cb791375d280936931a2c98 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 9 Oct 2018 00:17:55 +0200 Subject: [PATCH] Introduce STR_EQ and STRN_EQ macros --- src/log.c | 2 ++ src/utils.c | 1 - src/utils.h | 9 +++++++++ src/x11/screen.c | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/log.c b/src/log.c index 3f41c0c..b822e85 100644 --- a/src/log.c +++ b/src/log.c @@ -8,6 +8,8 @@ #include +#include "utils.h" + static GLogLevelFlags log_level = G_LOG_LEVEL_WARNING; /* see log.h */ diff --git a/src/utils.c b/src/utils.c index fa5ae40..761dca9 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "log.h" diff --git a/src/utils.h b/src/utils.h index 5cef754..29c4812 100644 --- a/src/utils.h +++ b/src/utils.h @@ -3,9 +3,18 @@ #define DUNST_UTILS_H #include +#include +//! Test if a string is NULL or empty #define STR_EMPTY(s) (!s || (*s == '\0')) +//! Test if a string is non-NULL and not empty #define STR_FULL(s) !(STR_EMPTY(s)) +//! Test if string a and b contain the same chars +#define STR_EQ(a, b) (strcmp(a, b) == 0) +//! Test if string a and b are same up to n chars +#define STRN_EQ(a, b, n) (strncmp(a, b, n) == 0) +//! Test if string a and b are the same case-insensitively +#define STR_CASEQ(a, b) (strcasecmp(a, b) == 0) /* replace all occurrences of the character needle with the character replacement in haystack */ char *string_replace_char(char needle, char replacement, char *haystack); diff --git a/src/x11/screen.c b/src/x11/screen.c index edf9838..d7fbfbf 100644 --- a/src/x11/screen.c +++ b/src/x11/screen.c @@ -17,6 +17,7 @@ #include "src/log.h" #include "src/settings.h" +#include "src/utils.h" #include "x.h" struct screen_info *screens;