aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/StringUtil.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util/StringUtil.cxx35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/util/StringUtil.cxx b/src/util/StringUtil.cxx
index 7e295bf90..9a1a74f86 100644
--- a/src/util/StringUtil.cxx
+++ b/src/util/StringUtil.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -22,6 +22,7 @@
#include "ASCII.hxx"
#include <assert.h>
+#include <string.h>
const char *
strchug_fast(const char *p)
@@ -32,6 +33,38 @@ strchug_fast(const char *p)
return p;
}
+char *
+Strip(char *p)
+{
+ p = strchug_fast(p);
+
+ size_t length = strlen(p);
+ while (length > 0 && IsWhitespaceNotNull(p[length - 1]))
+ --length;
+
+ p[length] = 0;
+
+ return p;
+}
+
+bool
+StringStartsWith(const char *haystack, const char *needle)
+{
+ const size_t length = strlen(needle);
+ return memcmp(haystack, needle, length) == 0;
+}
+
+bool
+StringEndsWith(const char *haystack, const char *needle)
+{
+ const size_t haystack_length = strlen(haystack);
+ const size_t needle_length = strlen(needle);
+
+ return haystack_length >= needle_length &&
+ memcmp(haystack + haystack_length - needle_length,
+ needle, needle_length) == 0;
+}
+
bool
string_array_contains(const char *const* haystack, const char *needle)
{