diff options
author | Max Kellermann <max@musicpd.org> | 2018-08-02 10:41:34 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-08-02 10:42:28 +0200 |
commit | 116edf5fcea825455fcf212afebea547d28ad9f5 (patch) | |
tree | ea49ef234db99c4d53706c75f74b2b8af5f4356d /src/util/ASCII.hxx | |
parent | 85810139113f011adabdf1354b5824f0eb1bcd4b (diff) |
util/ASCII: add StringStartsWithCaseASCII()
Diffstat (limited to 'src/util/ASCII.hxx')
-rw-r--r-- | src/util/ASCII.hxx | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/util/ASCII.hxx b/src/util/ASCII.hxx index 6d31d836a..02bca648c 100644 --- a/src/util/ASCII.hxx +++ b/src/util/ASCII.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Max Kellermann <max.kellermann@gmail.com> + * Copyright (C) 2013-2018 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,6 +30,7 @@ #ifndef ASCII_HXX #define ASCII_HXX +#include "StringView.hxx" #include "Compiler.h" #include <assert.h> @@ -69,4 +70,20 @@ StringEqualsCaseASCII(const char *a, const char *b, size_t n) noexcept return strncasecmp(a, b, n) == 0; } +gcc_pure gcc_nonnull_all +static inline bool +StringStartsWithCaseASCII(const char *haystack, StringView needle) noexcept +{ + return StringEqualsCaseASCII(haystack, needle.data, needle.size); +} + +gcc_pure gcc_nonnull_all +static inline const char * +StringAfterPrefixCaseASCII(const char *haystack, StringView needle) noexcept +{ + return StringStartsWithCaseASCII(haystack, needle) + ? haystack + needle.size + : nullptr; +} + #endif |