]> git.mdlowis.com Git - proto/labwc.git/commitdiff
string-helpers.c: add string_empty()
authorJohan Malm <jgm323@gmail.com>
Fri, 19 Jan 2024 19:06:07 +0000 (19:06 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 19 Jan 2024 20:00:37 +0000 (20:00 +0000)
include/common/string-helpers.h
src/button/button-png.c
src/button/button-svg.c
src/button/button-xbm.c
src/common/font.c
src/common/string-helpers.c
src/config/libinput.c
src/config/session.c
src/ssd/ssd_titlebar.c

index 20f74d5a3f3ab943c0696903211d6ff19360e015..4e20430285558916e74797c5db967dd4fed2d93b 100644 (file)
@@ -1,6 +1,13 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 #ifndef LABWC_STRING_HELPERS_H
 #define LABWC_STRING_HELPERS_H
+#include <stdbool.h>
+
+/**
+ * string_null_or_empty() - Check if string is NULL or empty
+ * @s: string to check
+ */
+bool string_null_or_empty(const char *s);
 
 /**
  * trim_last_field() - Trim last field of string splitting on provided delim
index e053ad4778507931e170d96158da2a4cb417ab5c..2c700a06c5f35d8ed0973c8730120f713dc79d88 100644 (file)
@@ -12,6 +12,7 @@
 #include "buffer.h"
 #include "button/button-png.h"
 #include "button/common.h"
+#include "common/string-helpers.h"
 #include "labwc.h"
 
 /*
@@ -49,7 +50,7 @@ button_png_load(const char *button_name, struct lab_data_buffer **buffer)
                wlr_buffer_drop(&(*buffer)->base);
                *buffer = NULL;
        }
-       if (!button_name || !*button_name) {
+       if (string_null_or_empty(button_name)) {
                return;
        }
 
index 2846e5b158fe169644d02fd26638aa2e606f9d85..2128524fa37380dc2ddbb4e6334e98b0710604ca 100644 (file)
@@ -12,6 +12,7 @@
 #include "buffer.h"
 #include "button/button-svg.h"
 #include "button/common.h"
+#include "common/string-helpers.h"
 #include "labwc.h"
 
 void
@@ -22,7 +23,7 @@ button_svg_load(const char *button_name, struct lab_data_buffer **buffer,
                wlr_buffer_drop(&(*buffer)->base);
                *buffer = NULL;
        }
-       if (!button_name || !*button_name) {
+       if (string_null_or_empty(button_name)) {
                return;
        }
 
index fe7460fa9f0f313776702e14b71fe912eb01cdca..125873c07831b1336186542b4a076ca91e599e71 100644 (file)
@@ -17,6 +17,7 @@
 #include "button/common.h"
 #include "common/grab-file.h"
 #include "common/mem.h"
+#include "common/string-helpers.h"
 #include "buffer.h"
 
 enum token_type {
@@ -279,7 +280,7 @@ button_xbm_load(const char *button_name, struct lab_data_buffer **buffer,
                wlr_buffer_drop(&(*buffer)->base);
                *buffer = NULL;
        }
-       if (!button_name || !*button_name) {
+       if (string_null_or_empty(button_name)) {
                return;
        }
        color = argb32(rgba);
index b27b7dde2189ebc00ace833e9087d4fbfb55f457..3b9973338bab4da639729b456cbcca9364f61738 100644 (file)
@@ -7,6 +7,7 @@
 #include <wlr/util/log.h>
 #include "common/font.h"
 #include "common/graphic-helpers.h"
+#include "common/string-helpers.h"
 #include "labwc.h"
 #include "buffer.h"
 
@@ -84,7 +85,7 @@ font_buffer_create(struct lab_data_buffer **buffer, int max_width,
                max_width = 2;
        }
 
-       if (!text || !*text) {
+       if (string_null_or_empty(text)) {
                return;
        }
 
index ec2c86bd911a1e949e82310c5a6b7c52bd646a5f..37fdf4d07966dee1edf70c57af49d3de176325d4 100644 (file)
@@ -6,6 +6,12 @@
 #include "common/mem.h"
 #include "common/string-helpers.h"
 
+bool
+string_null_or_empty(const char *s)
+{
+       return !s || !*s;
+}
+
 void
 trim_last_field(char *buf, char delim)
 {
index 4ea7499c72f1c7cd4fd53456ca244c163da1941c..7ce62b793c6e186a0c298e34586646c90a9bc7bc 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "common/mem.h"
 #include "common/list.h"
+#include "common/string-helpers.h"
 #include "config/libinput.h"
 #include "config/rcxml.h"
 
@@ -27,7 +28,7 @@ libinput_category_init(struct libinput_category *l)
 enum lab_libinput_device_type
 get_device_type(const char *s)
 {
-       if (!s || !*s) {
+       if (string_null_or_empty(s)) {
                return LAB_LIBINPUT_DEVICE_NONE;
        }
        if (!strcasecmp(s, "default")) {
index 6489752c0a0acfa7fed26375b9c9e3f13245d2a8..c87b08657e824e6a622f23fcb39868c0171ffb78 100644 (file)
 #include "config/session.h"
 #include "labwc.h"
 
-static bool
-string_empty(const char *s)
-{
-       return !s || !*s;
-}
-
 static void
 process_line(char *line)
 {
-       if (string_empty(line) || line[0] == '#') {
+       if (string_null_or_empty(line) || line[0] == '#') {
                return;
        }
        char *key = NULL;
@@ -39,7 +33,7 @@ process_line(char *line)
        buf_add(&value, string_strip(++p));
        buf_expand_shell_variables(&value);
        buf_expand_tilde(&value);
-       if (string_empty(key) || !value.len) {
+       if (string_null_or_empty(key) || !value.len) {
                goto error;
        }
        setenv(key, value.buf, 1);
index 6d3e936cc7fd823a72946a5a72baeab5bcf18b41..b0ffe8a04518457f1b12fc6414758ffea11f1745 100644 (file)
@@ -7,6 +7,7 @@
 #include "common/mem.h"
 #include "common/scaled_font_buffer.h"
 #include "common/scene-helpers.h"
+#include "common/string-helpers.h"
 #include "labwc.h"
 #include "node.h"
 #include "ssd-internal.h"
@@ -325,7 +326,7 @@ ssd_update_title(struct ssd *ssd)
 
        struct view *view = ssd->view;
        char *title = (char *)view_get_string_prop(view, "title");
-       if (!title || !*title) {
+       if (string_null_or_empty(title)) {
                return;
        }