]> git.mdlowis.com Git - proto/labwc.git/commitdiff
rc.xml: split out rstrip() to string-helpers.c
authorJohan Malm <jgm323@gmail.com>
Tue, 16 Feb 2021 21:03:38 +0000 (21:03 +0000)
committerJohan Malm <jgm323@gmail.com>
Tue, 16 Feb 2021 21:03:38 +0000 (21:03 +0000)
include/common/string-helpers.h
src/common/string-helpers.c
src/config/rcxml.c

index 9897319a6e23f23daa5b55d6f1d98ef17c232508..286c216d259f17b8fc4aa4b5599e30d3498d9659 100644 (file)
@@ -8,4 +8,11 @@
  */
 char *string_strip(char *s);
 
+/**
+ * string_truncate_at_pattern - remove pattern and everything after it
+ * @buf: pointer to buffer
+ * @pattern: string to remove
+ */
+void string_truncate_at_pattern(char *buf, const char *pattern);
+
 #endif /* __LABWC_STRING_HELPERS_H */
index 5476da805df817bb644c3b09081abbe2873384ac..3a2205f4ee8862ffdcce6cd18f496862c3956bd5 100644 (file)
@@ -25,3 +25,13 @@ string_strip(char *s)
        }
        return s;
 }
+
+void
+string_truncate_at_pattern(char *buf, const char *pattern)
+{
+       char *p = strstr(buf, pattern);
+       if (!p) {
+               return;
+       }
+       *p = '\0';
+}
index 5008b1dec2fbd51fc074e9dae593f4b4b4e46d1e..e390c8d090eb9b6b0c0fd4ffc3143841797d88ae 100644 (file)
@@ -14,6 +14,7 @@
 #include "common/dir.h"
 #include "common/font.h"
 #include "common/log.h"
+#include "common/string-helpers.h"
 #include "config/keybind.h"
 #include "config/rcxml.h"
 
@@ -30,23 +31,13 @@ enum font_place {
        /* TODO: Add all places based on Openbox's rc.xml */
 };
 
-static void
-rstrip(char *buf, const char *pattern)
-{
-       char *p = strstr(buf, pattern);
-       if (!p) {
-               return;
-       }
-       *p = '\0';
-}
-
 static void
 fill_keybind(char *nodename, char *content)
 {
        if (!content) {
                return;
        }
-       rstrip(nodename, ".keybind.keyboard");
+       string_truncate_at_pattern(nodename, ".keybind.keyboard");
        if (!strcmp(nodename, "key")) {
                current_keybind = keybind_create(content);
        }
@@ -82,7 +73,7 @@ fill_font(char *nodename, char *content, enum font_place place)
        if (!content) {
                return;
        }
-       rstrip(nodename, ".font.theme");
+       string_truncate_at_pattern(nodename, ".font.theme");
 
        /* TODO: implement for all font places */
        if (place != FONT_PLACE_ACTIVEWINDOW) {
@@ -118,7 +109,7 @@ entry(xmlNode *node, char *nodename, char *content)
        if (!nodename) {
                return;
        }
-       rstrip(nodename, ".openbox_config");
+       string_truncate_at_pattern(nodename, ".openbox_config");
 
        /* for debugging */
        if (write_to_nodename_buffer) {