aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-11-06 09:30:54 +0100
committerMax Kellermann <max@duempel.org>2015-11-06 10:03:14 +0100
commit4d15db01346a4c1e7b2c25b9c36f40a27783851e (patch)
treee54574f388ac4dc9bd909beeccd217ab54237d70 /src/util
parent0d1a54262cfa7a1a6df34331e7cc28486fe46b35 (diff)
downloadmpd-4d15db01346a4c1e7b2c25b9c36f40a27783851e.tar.gz
mpd-4d15db01346a4c1e7b2c25b9c36f40a27783851e.tar.xz
mpd-4d15db01346a4c1e7b2c25b9c36f40a27783851e.zip
util/StringCompare: use StringView to simplify inline implementations
Diffstat (limited to 'src/util')
-rw-r--r--src/util/StringCompare.cxx26
-rw-r--r--src/util/StringCompare.hxx19
2 files changed, 14 insertions, 31 deletions
diff --git a/src/util/StringCompare.cxx b/src/util/StringCompare.cxx
index fbd8e1d6d..5db53ef2f 100644
--- a/src/util/StringCompare.cxx
+++ b/src/util/StringCompare.cxx
@@ -28,17 +28,6 @@
*/
#include "StringCompare.hxx"
-#include "StringAPI.hxx"
-
-#include <assert.h>
-#include <string.h>
-
-bool
-StringStartsWith(const char *haystack, const char *needle)
-{
- const size_t length = StringLength(needle);
- return StringIsEqual(haystack, needle, length);
-}
bool
StringEndsWith(const char *haystack, const char *needle)
@@ -52,21 +41,6 @@ StringEndsWith(const char *haystack, const char *needle)
}
const char *
-StringAfterPrefix(const char *string, const char *prefix)
-{
-#if !CLANG_CHECK_VERSION(3,6)
- /* disabled on clang due to -Wtautological-pointer-compare */
- assert(string != nullptr);
- assert(prefix != nullptr);
-#endif
-
- size_t prefix_length = strlen(prefix);
- return StringIsEqual(string, prefix, prefix_length)
- ? string + prefix_length
- : nullptr;
-}
-
-const char *
FindStringSuffix(const char *p, const char *suffix)
{
const size_t p_length = strlen(p);
diff --git a/src/util/StringCompare.hxx b/src/util/StringCompare.hxx
index a29892bc9..6d7b3474e 100644
--- a/src/util/StringCompare.hxx
+++ b/src/util/StringCompare.hxx
@@ -30,6 +30,7 @@
#ifndef STRING_COMPARE_HXX
#define STRING_COMPARE_HXX
+#include "StringView.hxx"
#include "Compiler.h"
#ifdef _UNICODE
@@ -42,9 +43,12 @@ StringIsEmpty(const char *string)
return *string == 0;
}
-gcc_pure
-bool
-StringStartsWith(const char *haystack, const char *needle);
+gcc_pure gcc_nonnull_all
+static inline bool
+StringStartsWith(const char *haystack, StringView needle)
+{
+ return strncmp(haystack, needle.data, needle.size) == 0;
+}
gcc_pure
bool
@@ -56,8 +60,13 @@ StringEndsWith(const char *haystack, const char *needle);
* nullptr.
*/
gcc_pure gcc_nonnull_all
-const char *
-StringAfterPrefix(const char *string, const char *prefix);
+static inline const char *
+StringAfterPrefix(const char *haystack, StringView needle)
+{
+ return StringStartsWith(haystack, needle)
+ ? haystack + needle.size
+ : nullptr;
+}
/**
* Check if the given string ends with the specified suffix. If yes,