diff options
author | Max Kellermann <max@musicpd.org> | 2017-09-12 19:18:28 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-09-13 11:47:48 +0200 |
commit | 8d9347edc51788f9460c50a4b166b8f2d35732d9 (patch) | |
tree | 890b37306067ab9bf0044243bd21009a02893b9e /src/util | |
parent | eff821c1cae42dba23f7ebffd5d2ba5a3b066f9a (diff) |
Util/WStringCompare: use struct WStringView
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/WStringCompare.cxx | 26 | ||||
-rw-r--r-- | src/util/WStringCompare.hxx | 20 |
2 files changed, 15 insertions, 31 deletions
diff --git a/src/util/WStringCompare.cxx b/src/util/WStringCompare.cxx index c030d84ac..2ea0d8bdd 100644 --- a/src/util/WStringCompare.cxx +++ b/src/util/WStringCompare.cxx @@ -18,17 +18,6 @@ */ #include "WStringCompare.hxx" -#include "WStringAPI.hxx" - -#include <assert.h> -#include <string.h> - -bool -StringStartsWith(const wchar_t *haystack, const wchar_t *needle) noexcept -{ - const size_t length = StringLength(needle); - return StringIsEqual(haystack, needle, length); -} bool StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept @@ -41,21 +30,6 @@ StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept } const wchar_t * -StringAfterPrefix(const wchar_t *string, const wchar_t *prefix) noexcept -{ -#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 = StringLength(prefix); - return StringIsEqual(string, prefix, prefix_length) - ? string + prefix_length - : nullptr; -} - -const wchar_t * FindStringSuffix(const wchar_t *p, const wchar_t *suffix) noexcept { const size_t p_length = StringLength(p); diff --git a/src/util/WStringCompare.hxx b/src/util/WStringCompare.hxx index 7d3bd6d28..4b646928e 100644 --- a/src/util/WStringCompare.hxx +++ b/src/util/WStringCompare.hxx @@ -30,6 +30,8 @@ #ifndef WSTRING_COMPARE_HXX #define WSTRING_COMPARE_HXX +#include "WStringView.hxx" +#include "WStringAPI.hxx" #include "Compiler.h" #include <wchar.h> @@ -40,9 +42,12 @@ StringIsEmpty(const wchar_t *string) noexcept return *string == 0; } -gcc_pure -bool -StringStartsWith(const wchar_t *haystack, const wchar_t *needle) noexcept; +gcc_pure gcc_nonnull_all +static inline bool +StringStartsWith(const wchar_t *haystack, WStringView needle) noexcept +{ + return StringIsEqual(haystack, needle.data, needle.size); +} gcc_pure bool @@ -54,8 +59,13 @@ StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept; * nullptr. */ gcc_pure gcc_nonnull_all -const wchar_t * -StringAfterPrefix(const wchar_t *string, const wchar_t *prefix) noexcept; +static inline const wchar_t * +StringAfterPrefix(const wchar_t *haystack, WStringView needle) noexcept +{ + return StringStartsWith(haystack, needle) + ? haystack + needle.size + : nullptr; +} /** * Check if the given string ends with the specified suffix. If yes, |