aboutsummaryrefslogtreecommitdiff
path: root/src/lib/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/core')
-rw-r--r--src/lib/core/include/utils.h4
-rw-r--r--src/lib/core/str.c23
2 files changed, 26 insertions, 1 deletions
diff --git a/src/lib/core/include/utils.h b/src/lib/core/include/utils.h
index 87f28cc..1906808 100644
--- a/src/lib/core/include/utils.h
+++ b/src/lib/core/include/utils.h
@@ -413,4 +413,8 @@ int env_manipulate_pathstr(const char *key, char *path, int mode);
*/
int gen_file_extension_str(char *filename, const char *extension);
+/**
+ * Remove [extra]s from a spec string
+ */
+char *remove_extras(char *s);
#endif //STASIS_UTILS_H
diff --git a/src/lib/core/str.c b/src/lib/core/str.c
index 6457afe..1d0b268 100644
--- a/src/lib/core/str.c
+++ b/src/lib/core/str.c
@@ -671,4 +671,25 @@ void unindent(char *s) {
pos++;
}
}
-} \ No newline at end of file
+}
+
+char *remove_extras(char *s) {
+ // an "extra" is a string encapsulated by square brackets "text[toremove]"
+ char *extra_stop = NULL;
+ char *extra_start = strchr(s, '[');
+ size_t len = strlen(s);
+ if (extra_start) {
+ extra_stop = strchr(extra_start, ']');
+ if (extra_stop) {
+ size_t last = strlen(s);
+ if (last) {
+ extra_stop++;
+ last = strlen(extra_stop);
+ }
+ memmove(extra_start, extra_stop, last);
+ s[len - (extra_stop - extra_start)] = 0;
+ }
+ }
+ return s;
+}
+