Commit 116edf5f authored by Max Kellermann's avatar Max Kellermann

util/ASCII: add StringStartsWithCaseASCII()

parent 85810139
/*
* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment