Diff between a287cb4229a9120c32d30efd43e84b04f5440d05 and 4653ff97a3988cf52cb4c8b9ebd464be369f1e28

Changed Files

File Additions Deletions Status
src/shared/util.c +45 -0 modified
src/shared/util.h +3 -0 modified

Full Patch

diff --git a/src/shared/util.c b/src/shared/util.c
index f6f265e..986e2b2 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -980,3 +980,48 @@ const char *bt_appear_to_str(uint16_t appearance)
 
 	return str;
 }
+
+char *strdelimit(char *str, char *del, char c)
+{
+	char *dup;
+
+	if (!str)
+		return NULL;
+
+	dup = strdup(str);
+	if (dup[0] == '\0')
+		return dup;
+
+	while (del[0] != '\0') {
+		char *rep = dup;
+
+		while ((rep = strchr(rep, del[0])))
+			rep[0] = c;
+
+		del++;
+	}
+
+	return dup;
+}
+
+int strsuffix(const char *str, const char *suffix)
+{
+	int len;
+	int suffix_len;
+
+	if (!str || !suffix)
+		return false;
+
+	if (str[0] == '\0' && suffix[0] != '\0')
+		return false;
+
+	if (suffix[0] == '\0' && str[0] != '\0')
+		return false;
+
+	len = strlen(str);
+	suffix_len = strlen(suffix);
+	if (len < suffix_len)
+		return false;
+
+	return strncmp(str + len - suffix_len, suffix, suffix_len);
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 3f5f6df..604dc3b 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -92,6 +92,9 @@ do {						\
 #define newa(t, n) ((t*) alloca(sizeof(t)*(n)))
 #define malloc0(n) (calloc((n), 1))
 
+char *strdelimit(char *str, char *del, char c);
+int strsuffix(const char *str, const char *suffix);
+
 void *btd_malloc(size_t size);
 
 typedef void (*util_debug_func_t)(const char *str, void *user_data);