diff options
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 |