*: add "noexcept" to many, many function prototypes
This eliminates some overhead, because the compiler doesn't need to consider these functions throwing.
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline bool
|
||||
StringEqualsCaseASCII(const char *a, const char *b)
|
||||
StringEqualsCaseASCII(const char *a, const char *b) noexcept
|
||||
{
|
||||
#if !CLANG_CHECK_VERSION(3,6)
|
||||
/* disabled on clang due to -Wtautological-pointer-compare */
|
||||
@@ -56,7 +56,7 @@ StringEqualsCaseASCII(const char *a, const char *b)
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline bool
|
||||
StringEqualsCaseASCII(const char *a, const char *b, size_t n)
|
||||
StringEqualsCaseASCII(const char *a, const char *b, size_t n) noexcept
|
||||
{
|
||||
#if !CLANG_CHECK_VERSION(3,6)
|
||||
/* disabled on clang due to -Wtautological-pointer-compare */
|
||||
|
@@ -45,7 +45,7 @@
|
||||
*/
|
||||
gcc_const
|
||||
static size_t
|
||||
AlignToPageSize(size_t size)
|
||||
AlignToPageSize(size_t size) noexcept
|
||||
{
|
||||
static const long page_size = sysconf(_SC_PAGESIZE);
|
||||
if (page_size <= 0)
|
||||
|
@@ -32,14 +32,14 @@ PeakBuffer::~PeakBuffer()
|
||||
}
|
||||
|
||||
bool
|
||||
PeakBuffer::IsEmpty() const
|
||||
PeakBuffer::IsEmpty() const noexcept
|
||||
{
|
||||
return (normal_buffer == nullptr || normal_buffer->IsEmpty()) &&
|
||||
(peak_buffer == nullptr || peak_buffer->IsEmpty());
|
||||
}
|
||||
|
||||
WritableBuffer<void>
|
||||
PeakBuffer::Read() const
|
||||
PeakBuffer::Read() const noexcept
|
||||
{
|
||||
if (normal_buffer != nullptr) {
|
||||
const auto p = normal_buffer->Read();
|
||||
@@ -57,7 +57,7 @@ PeakBuffer::Read() const
|
||||
}
|
||||
|
||||
void
|
||||
PeakBuffer::Consume(size_t length)
|
||||
PeakBuffer::Consume(size_t length) noexcept
|
||||
{
|
||||
if (normal_buffer != nullptr && !normal_buffer->IsEmpty()) {
|
||||
normal_buffer->Consume(length);
|
||||
@@ -76,7 +76,8 @@ PeakBuffer::Consume(size_t length)
|
||||
}
|
||||
|
||||
static size_t
|
||||
AppendTo(DynamicFifoBuffer<uint8_t> &buffer, const void *data, size_t length)
|
||||
AppendTo(DynamicFifoBuffer<uint8_t> &buffer,
|
||||
const void *data, size_t length) noexcept
|
||||
{
|
||||
assert(data != nullptr);
|
||||
assert(length > 0);
|
||||
|
@@ -57,12 +57,12 @@ public:
|
||||
PeakBuffer &operator=(const PeakBuffer &) = delete;
|
||||
|
||||
gcc_pure
|
||||
bool IsEmpty() const;
|
||||
bool IsEmpty() const noexcept;
|
||||
|
||||
gcc_pure
|
||||
WritableBuffer<void> Read() const;
|
||||
WritableBuffer<void> Read() const noexcept;
|
||||
|
||||
void Consume(size_t length);
|
||||
void Consume(size_t length) noexcept;
|
||||
|
||||
bool Append(const void *data, size_t length);
|
||||
};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright (C) 2010-2017 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
|
||||
@@ -40,70 +40,70 @@
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline size_t
|
||||
StringLength(const char *p)
|
||||
StringLength(const char *p) noexcept
|
||||
{
|
||||
return strlen(p);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const char *
|
||||
StringFind(const char *haystack, const char *needle)
|
||||
StringFind(const char *haystack, const char *needle) noexcept
|
||||
{
|
||||
return strstr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline char *
|
||||
StringFind(char *haystack, char needle, size_t size)
|
||||
StringFind(char *haystack, char needle, size_t size) noexcept
|
||||
{
|
||||
return (char *)memchr(haystack, needle, size);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const char *
|
||||
StringFind(const char *haystack, char needle, size_t size)
|
||||
StringFind(const char *haystack, char needle, size_t size) noexcept
|
||||
{
|
||||
return (const char *)memchr(haystack, needle, size);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const char *
|
||||
StringFind(const char *haystack, char needle)
|
||||
StringFind(const char *haystack, char needle) noexcept
|
||||
{
|
||||
return strchr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline char *
|
||||
StringFind(char *haystack, char needle)
|
||||
StringFind(char *haystack, char needle) noexcept
|
||||
{
|
||||
return strchr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const char *
|
||||
StringFindLast(const char *haystack, char needle)
|
||||
StringFindLast(const char *haystack, char needle) noexcept
|
||||
{
|
||||
return strrchr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline char *
|
||||
StringFindLast(char *haystack, char needle)
|
||||
StringFindLast(char *haystack, char needle) noexcept
|
||||
{
|
||||
return strrchr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_nonnull_all
|
||||
static inline void
|
||||
UnsafeCopyString(char *dest, const char *src)
|
||||
UnsafeCopyString(char *dest, const char *src) noexcept
|
||||
{
|
||||
strcpy(dest, src);
|
||||
}
|
||||
|
||||
gcc_nonnull_all
|
||||
static inline char *
|
||||
UnsafeCopyStringP(char *dest, const char *src)
|
||||
UnsafeCopyStringP(char *dest, const char *src) noexcept
|
||||
{
|
||||
#if defined(WIN32) || defined(__BIONIC__)
|
||||
/* emulate stpcpy() */
|
||||
@@ -119,7 +119,7 @@ UnsafeCopyStringP(char *dest, const char *src)
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline bool
|
||||
StringIsEqual(const char *a, const char *b)
|
||||
StringIsEqual(const char *a, const char *b) noexcept
|
||||
{
|
||||
return strcmp(a, b) == 0;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ StringIsEqual(const char *a, const char *b)
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline bool
|
||||
StringIsEqual(const char *a, const char *b, size_t length)
|
||||
StringIsEqual(const char *a, const char *b, size_t length) noexcept
|
||||
{
|
||||
return strncmp(a, b, length) == 0;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2015 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright (C) 2013-2017 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,7 +30,7 @@
|
||||
#include "StringCompare.hxx"
|
||||
|
||||
bool
|
||||
StringEndsWith(const char *haystack, const char *needle)
|
||||
StringEndsWith(const char *haystack, const char *needle) noexcept
|
||||
{
|
||||
const size_t haystack_length = strlen(haystack);
|
||||
const size_t needle_length = strlen(needle);
|
||||
@@ -41,7 +41,7 @@ StringEndsWith(const char *haystack, const char *needle)
|
||||
}
|
||||
|
||||
const char *
|
||||
FindStringSuffix(const char *p, const char *suffix)
|
||||
FindStringSuffix(const char *p, const char *suffix) noexcept
|
||||
{
|
||||
const size_t p_length = strlen(p);
|
||||
const size_t suffix_length = strlen(suffix);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2015 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright (C) 2013-2017 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
|
||||
@@ -45,14 +45,14 @@ StringIsEmpty(const char *string)
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline bool
|
||||
StringStartsWith(const char *haystack, StringView needle)
|
||||
StringStartsWith(const char *haystack, StringView needle) noexcept
|
||||
{
|
||||
return strncmp(haystack, needle.data, needle.size) == 0;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
bool
|
||||
StringEndsWith(const char *haystack, const char *needle);
|
||||
StringEndsWith(const char *haystack, const char *needle) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the portion of the string after a prefix. If the string
|
||||
@@ -61,7 +61,7 @@ StringEndsWith(const char *haystack, const char *needle);
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const char *
|
||||
StringAfterPrefix(const char *haystack, StringView needle)
|
||||
StringAfterPrefix(const char *haystack, StringView needle) noexcept
|
||||
{
|
||||
return StringStartsWith(haystack, needle)
|
||||
? haystack + needle.size
|
||||
@@ -74,6 +74,6 @@ StringAfterPrefix(const char *haystack, StringView needle)
|
||||
*/
|
||||
gcc_pure
|
||||
const char *
|
||||
FindStringSuffix(const char *p, const char *suffix);
|
||||
FindStringSuffix(const char *p, const char *suffix) noexcept;
|
||||
|
||||
#endif
|
||||
|
@@ -27,7 +27,8 @@
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
CopyString(char *gcc_restrict dest, const char *gcc_restrict src, size_t size)
|
||||
CopyString(char *gcc_restrict dest, const char *gcc_restrict src,
|
||||
size_t size) noexcept
|
||||
{
|
||||
size_t length = strlen(src);
|
||||
if (length >= size)
|
||||
@@ -39,7 +40,7 @@ CopyString(char *gcc_restrict dest, const char *gcc_restrict src, size_t size)
|
||||
}
|
||||
|
||||
const char *
|
||||
StripLeft(const char *p)
|
||||
StripLeft(const char *p) noexcept
|
||||
{
|
||||
while (IsWhitespaceNotNull(*p))
|
||||
++p;
|
||||
@@ -48,7 +49,7 @@ StripLeft(const char *p)
|
||||
}
|
||||
|
||||
const char *
|
||||
StripLeft(const char *p, const char *end)
|
||||
StripLeft(const char *p, const char *end) noexcept
|
||||
{
|
||||
while (p < end && IsWhitespaceOrNull(*p))
|
||||
++p;
|
||||
@@ -57,7 +58,7 @@ StripLeft(const char *p, const char *end)
|
||||
}
|
||||
|
||||
const char *
|
||||
StripRight(const char *p, const char *end)
|
||||
StripRight(const char *p, const char *end) noexcept
|
||||
{
|
||||
while (end > p && IsWhitespaceOrNull(end[-1]))
|
||||
--end;
|
||||
@@ -66,7 +67,7 @@ StripRight(const char *p, const char *end)
|
||||
}
|
||||
|
||||
size_t
|
||||
StripRight(const char *p, size_t length)
|
||||
StripRight(const char *p, size_t length) noexcept
|
||||
{
|
||||
while (length > 0 && IsWhitespaceOrNull(p[length - 1]))
|
||||
--length;
|
||||
@@ -75,7 +76,7 @@ StripRight(const char *p, size_t length)
|
||||
}
|
||||
|
||||
void
|
||||
StripRight(char *p)
|
||||
StripRight(char *p) noexcept
|
||||
{
|
||||
size_t old_length = strlen(p);
|
||||
size_t new_length = StripRight(p, old_length);
|
||||
@@ -83,7 +84,7 @@ StripRight(char *p)
|
||||
}
|
||||
|
||||
char *
|
||||
Strip(char *p)
|
||||
Strip(char *p) noexcept
|
||||
{
|
||||
p = StripLeft(p);
|
||||
StripRight(p);
|
||||
@@ -91,7 +92,8 @@ Strip(char *p)
|
||||
}
|
||||
|
||||
bool
|
||||
StringArrayContainsCase(const char *const*haystack, const char *needle)
|
||||
StringArrayContainsCase(const char *const*haystack,
|
||||
const char *needle) noexcept
|
||||
{
|
||||
assert(haystack != nullptr);
|
||||
assert(needle != nullptr);
|
||||
@@ -104,7 +106,7 @@ StringArrayContainsCase(const char *const*haystack, const char *needle)
|
||||
}
|
||||
|
||||
void
|
||||
ToUpperASCII(char *dest, const char *src, size_t size)
|
||||
ToUpperASCII(char *dest, const char *src, size_t size) noexcept
|
||||
{
|
||||
assert(dest != nullptr);
|
||||
assert(src != nullptr);
|
||||
|
@@ -34,7 +34,7 @@
|
||||
*/
|
||||
gcc_nonnull_all
|
||||
char *
|
||||
CopyString(char *dest, const char *src, size_t size);
|
||||
CopyString(char *dest, const char *src, size_t size) noexcept;
|
||||
|
||||
/**
|
||||
* Returns a pointer to the first non-whitespace character in the
|
||||
@@ -42,32 +42,32 @@ CopyString(char *dest, const char *src, size_t size);
|
||||
*/
|
||||
gcc_pure
|
||||
const char *
|
||||
StripLeft(const char *p);
|
||||
StripLeft(const char *p) noexcept;
|
||||
|
||||
gcc_pure
|
||||
static inline char *
|
||||
StripLeft(char *p)
|
||||
StripLeft(char *p) noexcept
|
||||
{
|
||||
return const_cast<char *>(StripLeft((const char *)p));
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
const char *
|
||||
StripLeft(const char *p, const char *end);
|
||||
StripLeft(const char *p, const char *end) noexcept;
|
||||
|
||||
/**
|
||||
* Determine the string's end as if it was stripped on the right side.
|
||||
*/
|
||||
gcc_pure
|
||||
const char *
|
||||
StripRight(const char *p, const char *end);
|
||||
StripRight(const char *p, const char *end) noexcept;
|
||||
|
||||
/**
|
||||
* Determine the string's end as if it was stripped on the right side.
|
||||
*/
|
||||
gcc_pure
|
||||
static inline char *
|
||||
StripRight(char *p, char *end)
|
||||
StripRight(char *p, char *end) noexcept
|
||||
{
|
||||
return const_cast<char *>(StripRight((const char *)p,
|
||||
(const char *)end));
|
||||
@@ -79,20 +79,20 @@ StripRight(char *p, char *end)
|
||||
*/
|
||||
gcc_pure
|
||||
size_t
|
||||
StripRight(const char *p, size_t length);
|
||||
StripRight(const char *p, size_t length) noexcept;
|
||||
|
||||
/**
|
||||
* Strip trailing whitespace by null-terminating the string.
|
||||
*/
|
||||
void
|
||||
StripRight(char *p);
|
||||
StripRight(char *p) noexcept;
|
||||
|
||||
/**
|
||||
* Skip whitespace at the beginning and terminate the string after the
|
||||
* last non-whitespace character.
|
||||
*/
|
||||
char *
|
||||
Strip(char *p);
|
||||
Strip(char *p) noexcept;
|
||||
|
||||
/**
|
||||
* Checks whether a string array contains the specified string.
|
||||
@@ -104,7 +104,8 @@ Strip(char *p);
|
||||
*/
|
||||
gcc_pure
|
||||
bool
|
||||
StringArrayContainsCase(const char *const*haystack, const char *needle);
|
||||
StringArrayContainsCase(const char *const*haystack,
|
||||
const char *needle) noexcept;
|
||||
|
||||
/**
|
||||
* Convert the specified ASCII string (0x00..0x7f) to upper case.
|
||||
@@ -112,6 +113,6 @@ StringArrayContainsCase(const char *const*haystack, const char *needle);
|
||||
* @param size the destination buffer size
|
||||
*/
|
||||
void
|
||||
ToUpperASCII(char *dest, const char *src, size_t size);
|
||||
ToUpperASCII(char *dest, const char *src, size_t size) noexcept;
|
||||
|
||||
#endif
|
||||
|
@@ -41,7 +41,7 @@
|
||||
*/
|
||||
gcc_const
|
||||
static time_t
|
||||
GetTimeZoneOffset()
|
||||
GetTimeZoneOffset() noexcept
|
||||
{
|
||||
time_t t = 1234567890;
|
||||
struct tm tm;
|
||||
|
@@ -124,7 +124,7 @@ MakeContinuation(unsigned char value)
|
||||
}
|
||||
|
||||
bool
|
||||
ValidateUTF8(const char *p)
|
||||
ValidateUTF8(const char *p) noexcept
|
||||
{
|
||||
for (; *p != 0; ++p) {
|
||||
unsigned char ch = *p;
|
||||
@@ -167,7 +167,7 @@ ValidateUTF8(const char *p)
|
||||
}
|
||||
|
||||
size_t
|
||||
SequenceLengthUTF8(char ch)
|
||||
SequenceLengthUTF8(char ch) noexcept
|
||||
{
|
||||
if (IsASCII(ch))
|
||||
return 1;
|
||||
@@ -196,14 +196,14 @@ SequenceLengthUTF8(char ch)
|
||||
template<size_t L>
|
||||
struct CheckSequenceUTF8 {
|
||||
gcc_pure
|
||||
bool operator()(const char *p) const {
|
||||
bool operator()(const char *p) const noexcept {
|
||||
return IsContinuation(*p) && CheckSequenceUTF8<L-1>()(p + 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct CheckSequenceUTF8<0u> {
|
||||
constexpr bool operator()(gcc_unused const char *p) const {
|
||||
constexpr bool operator()(gcc_unused const char *p) const noexcept {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -211,7 +211,7 @@ struct CheckSequenceUTF8<0u> {
|
||||
template<size_t L>
|
||||
gcc_pure
|
||||
static size_t
|
||||
InnerSequenceLengthUTF8(const char *p)
|
||||
InnerSequenceLengthUTF8(const char *p) noexcept
|
||||
{
|
||||
return CheckSequenceUTF8<L>()(p)
|
||||
? L + 1
|
||||
@@ -219,7 +219,7 @@ InnerSequenceLengthUTF8(const char *p)
|
||||
}
|
||||
|
||||
size_t
|
||||
SequenceLengthUTF8(const char *p)
|
||||
SequenceLengthUTF8(const char *p) noexcept
|
||||
{
|
||||
const unsigned char ch = *p++;
|
||||
|
||||
@@ -246,8 +246,9 @@ SequenceLengthUTF8(const char *p)
|
||||
return 0;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
static const char *
|
||||
FindNonASCIIOrZero(const char *p)
|
||||
FindNonASCIIOrZero(const char *p) noexcept
|
||||
{
|
||||
while (*p != 0 && IsASCII(*p))
|
||||
++p;
|
||||
@@ -256,7 +257,7 @@ FindNonASCIIOrZero(const char *p)
|
||||
|
||||
const char *
|
||||
Latin1ToUTF8(const char *gcc_restrict src, char *gcc_restrict buffer,
|
||||
size_t buffer_size)
|
||||
size_t buffer_size) noexcept
|
||||
{
|
||||
const char *p = FindNonASCIIOrZero(src);
|
||||
if (*p == 0)
|
||||
@@ -294,7 +295,7 @@ Latin1ToUTF8(const char *gcc_restrict src, char *gcc_restrict buffer,
|
||||
}
|
||||
|
||||
char *
|
||||
UnicodeToUTF8(unsigned ch, char *q)
|
||||
UnicodeToUTF8(unsigned ch, char *q) noexcept
|
||||
{
|
||||
if (gcc_likely(ch < 0x80)) {
|
||||
*q++ = (char)ch;
|
||||
@@ -331,7 +332,7 @@ UnicodeToUTF8(unsigned ch, char *q)
|
||||
}
|
||||
|
||||
size_t
|
||||
LengthUTF8(const char *p)
|
||||
LengthUTF8(const char *p) noexcept
|
||||
{
|
||||
/* this is a very naive implementation: it does not do any
|
||||
verification, it just counts the bytes that are not a UTF-8
|
||||
|
@@ -40,7 +40,7 @@
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
bool
|
||||
ValidateUTF8(const char *p);
|
||||
ValidateUTF8(const char *p) noexcept;
|
||||
|
||||
/**
|
||||
* @return the number of the sequence beginning with the given
|
||||
@@ -48,7 +48,7 @@ ValidateUTF8(const char *p);
|
||||
*/
|
||||
gcc_const
|
||||
size_t
|
||||
SequenceLengthUTF8(char ch);
|
||||
SequenceLengthUTF8(char ch) noexcept;
|
||||
|
||||
/**
|
||||
* @return the number of the first sequence in the given string, or 0
|
||||
@@ -56,7 +56,7 @@ SequenceLengthUTF8(char ch);
|
||||
*/
|
||||
gcc_pure
|
||||
size_t
|
||||
SequenceLengthUTF8(const char *p);
|
||||
SequenceLengthUTF8(const char *p) noexcept;
|
||||
|
||||
/**
|
||||
* Convert the specified string from ISO-8859-1 to UTF-8.
|
||||
@@ -67,7 +67,7 @@ SequenceLengthUTF8(const char *p);
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
const char *
|
||||
Latin1ToUTF8(const char *src, char *buffer, size_t buffer_size);
|
||||
Latin1ToUTF8(const char *src, char *buffer, size_t buffer_size) noexcept;
|
||||
|
||||
/**
|
||||
* Convert the specified Unicode character to UTF-8 and write it to
|
||||
@@ -77,7 +77,7 @@ Latin1ToUTF8(const char *src, char *buffer, size_t buffer_size);
|
||||
*/
|
||||
gcc_nonnull_all
|
||||
char *
|
||||
UnicodeToUTF8(unsigned ch, char *buffer);
|
||||
UnicodeToUTF8(unsigned ch, char *buffer) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the number of characters in the string. This is different
|
||||
@@ -85,6 +85,6 @@ UnicodeToUTF8(unsigned ch, char *buffer);
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
size_t
|
||||
LengthUTF8(const char *p);
|
||||
LengthUTF8(const char *p) noexcept;
|
||||
|
||||
#endif
|
||||
|
@@ -39,7 +39,7 @@ IsValidSchemeChar(char ch)
|
||||
|
||||
gcc_pure
|
||||
static bool
|
||||
IsValidScheme(StringView p)
|
||||
IsValidScheme(StringView p) noexcept
|
||||
{
|
||||
if (p.IsEmpty() || !IsValidSchemeStart(p.front()))
|
||||
return false;
|
||||
@@ -57,7 +57,7 @@ IsValidScheme(StringView p)
|
||||
*/
|
||||
gcc_pure
|
||||
static const char *
|
||||
uri_after_scheme(const char *uri)
|
||||
uri_after_scheme(const char *uri) noexcept
|
||||
{
|
||||
if (uri[0] == '/' && uri[1] == '/' && uri[2] != '/')
|
||||
return uri + 2;
|
||||
@@ -70,13 +70,14 @@ uri_after_scheme(const char *uri)
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
bool uri_has_scheme(const char *uri)
|
||||
bool
|
||||
uri_has_scheme(const char *uri) noexcept
|
||||
{
|
||||
return strstr(uri, "://") != nullptr;
|
||||
}
|
||||
|
||||
std::string
|
||||
uri_get_scheme(const char *uri)
|
||||
uri_get_scheme(const char *uri) noexcept
|
||||
{
|
||||
const char *end = strstr(uri, "://");
|
||||
if (end == nullptr)
|
||||
@@ -86,7 +87,7 @@ uri_get_scheme(const char *uri)
|
||||
}
|
||||
|
||||
const char *
|
||||
uri_get_path(const char *uri)
|
||||
uri_get_path(const char *uri) noexcept
|
||||
{
|
||||
const char *ap = uri_after_scheme(uri);
|
||||
if (ap != nullptr)
|
||||
@@ -97,7 +98,7 @@ uri_get_path(const char *uri)
|
||||
|
||||
/* suffixes should be ascii only characters */
|
||||
const char *
|
||||
uri_get_suffix(const char *uri)
|
||||
uri_get_suffix(const char *uri) noexcept
|
||||
{
|
||||
const char *suffix = strrchr(uri, '.');
|
||||
if (suffix == nullptr || suffix == uri ||
|
||||
@@ -113,7 +114,7 @@ uri_get_suffix(const char *uri)
|
||||
}
|
||||
|
||||
const char *
|
||||
uri_get_suffix(const char *uri, UriSuffixBuffer &buffer)
|
||||
uri_get_suffix(const char *uri, UriSuffixBuffer &buffer) noexcept
|
||||
{
|
||||
const char *suffix = uri_get_suffix(uri);
|
||||
if (suffix == nullptr)
|
||||
@@ -130,7 +131,7 @@ uri_get_suffix(const char *uri, UriSuffixBuffer &buffer)
|
||||
}
|
||||
|
||||
static const char *
|
||||
verify_uri_segment(const char *p)
|
||||
verify_uri_segment(const char *p) noexcept
|
||||
{
|
||||
unsigned dots = 0;
|
||||
while (*p == '.') {
|
||||
@@ -146,7 +147,7 @@ verify_uri_segment(const char *p)
|
||||
}
|
||||
|
||||
bool
|
||||
uri_safe_local(const char *uri)
|
||||
uri_safe_local(const char *uri) noexcept
|
||||
{
|
||||
while (true) {
|
||||
uri = verify_uri_segment(uri);
|
||||
@@ -164,7 +165,7 @@ uri_safe_local(const char *uri)
|
||||
|
||||
gcc_pure
|
||||
static const char *
|
||||
SkipUriScheme(const char *uri)
|
||||
SkipUriScheme(const char *uri) noexcept
|
||||
{
|
||||
const char *const schemes[] = { "http://", "https://", "ftp://" };
|
||||
for (auto scheme : schemes) {
|
||||
@@ -177,7 +178,7 @@ SkipUriScheme(const char *uri)
|
||||
}
|
||||
|
||||
std::string
|
||||
uri_remove_auth(const char *uri)
|
||||
uri_remove_auth(const char *uri) noexcept
|
||||
{
|
||||
const char *auth = SkipUriScheme(uri);
|
||||
if (auth == nullptr)
|
||||
@@ -201,7 +202,7 @@ uri_remove_auth(const char *uri)
|
||||
}
|
||||
|
||||
bool
|
||||
uri_is_child(const char *parent, const char *child)
|
||||
uri_is_child(const char *parent, const char *child) noexcept
|
||||
{
|
||||
#if !CLANG_CHECK_VERSION(3,6)
|
||||
/* disabled on clang due to -Wtautological-pointer-compare */
|
||||
@@ -216,13 +217,13 @@ uri_is_child(const char *parent, const char *child)
|
||||
|
||||
|
||||
bool
|
||||
uri_is_child_or_same(const char *parent, const char *child)
|
||||
uri_is_child_or_same(const char *parent, const char *child) noexcept
|
||||
{
|
||||
return strcmp(parent, child) == 0 || uri_is_child(parent, child);
|
||||
}
|
||||
|
||||
std::string
|
||||
uri_apply_base(const std::string &uri, const std::string &base)
|
||||
uri_apply_base(const std::string &uri, const std::string &base) noexcept
|
||||
{
|
||||
if (uri.front() == '/') {
|
||||
/* absolute path: replace the whole URI path in base */
|
||||
|
@@ -29,14 +29,15 @@
|
||||
* "scheme://".
|
||||
*/
|
||||
gcc_pure
|
||||
bool uri_has_scheme(const char *uri);
|
||||
bool
|
||||
uri_has_scheme(const char *uri) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the scheme name of the specified URI, or an empty string.
|
||||
*/
|
||||
gcc_pure
|
||||
std::string
|
||||
uri_get_scheme(const char *uri);
|
||||
uri_get_scheme(const char *uri) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the URI path (including the query string) or nullptr if the
|
||||
@@ -44,11 +45,11 @@ uri_get_scheme(const char *uri);
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
const char *
|
||||
uri_get_path(const char *uri);
|
||||
uri_get_path(const char *uri) noexcept;
|
||||
|
||||
gcc_pure
|
||||
const char *
|
||||
uri_get_suffix(const char *uri);
|
||||
uri_get_suffix(const char *uri) noexcept;
|
||||
|
||||
struct UriSuffixBuffer {
|
||||
char data[8];
|
||||
@@ -59,7 +60,7 @@ struct UriSuffixBuffer {
|
||||
*/
|
||||
gcc_pure
|
||||
const char *
|
||||
uri_get_suffix(const char *uri, UriSuffixBuffer &buffer);
|
||||
uri_get_suffix(const char *uri, UriSuffixBuffer &buffer) noexcept;
|
||||
|
||||
/**
|
||||
* Returns true if this is a safe "local" URI:
|
||||
@@ -71,7 +72,7 @@ uri_get_suffix(const char *uri, UriSuffixBuffer &buffer);
|
||||
*/
|
||||
gcc_pure
|
||||
bool
|
||||
uri_safe_local(const char *uri);
|
||||
uri_safe_local(const char *uri) noexcept;
|
||||
|
||||
/**
|
||||
* Removes HTTP username and password from the URI. This may be
|
||||
@@ -81,7 +82,7 @@ uri_safe_local(const char *uri);
|
||||
*/
|
||||
gcc_pure
|
||||
std::string
|
||||
uri_remove_auth(const char *uri);
|
||||
uri_remove_auth(const char *uri) noexcept;
|
||||
|
||||
/**
|
||||
* Check whether #child specifies a resource "inside" the directory
|
||||
@@ -90,11 +91,11 @@ uri_remove_auth(const char *uri);
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
bool
|
||||
uri_is_child(const char *parent, const char *child);
|
||||
uri_is_child(const char *parent, const char *child) noexcept;
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
bool
|
||||
uri_is_child_or_same(const char *parent, const char *child);
|
||||
uri_is_child_or_same(const char *parent, const char *child) noexcept;
|
||||
|
||||
/**
|
||||
* Translate the given URI in the context of #base. For example,
|
||||
@@ -102,6 +103,6 @@ uri_is_child_or_same(const char *parent, const char *child);
|
||||
*/
|
||||
gcc_pure
|
||||
std::string
|
||||
uri_apply_base(const std::string &uri, const std::string &base);
|
||||
uri_apply_base(const std::string &uri, const std::string &base) noexcept;
|
||||
|
||||
#endif
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright (C) 2010-2017 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
|
||||
@@ -36,70 +36,70 @@
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline size_t
|
||||
StringLength(const wchar_t *p)
|
||||
StringLength(const wchar_t *p) noexcept
|
||||
{
|
||||
return wcslen(p);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const wchar_t *
|
||||
StringFind(const wchar_t *haystack, const wchar_t *needle)
|
||||
StringFind(const wchar_t *haystack, const wchar_t *needle) noexcept
|
||||
{
|
||||
return wcsstr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const wchar_t *
|
||||
StringFind(const wchar_t *haystack, wchar_t needle, size_t size)
|
||||
StringFind(const wchar_t *haystack, wchar_t needle, size_t size) noexcept
|
||||
{
|
||||
return wmemchr(haystack, needle, size);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline wchar_t *
|
||||
StringFind(wchar_t *haystack, wchar_t needle, size_t size)
|
||||
StringFind(wchar_t *haystack, wchar_t needle, size_t size) noexcept
|
||||
{
|
||||
return wmemchr(haystack, needle, size);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const wchar_t *
|
||||
StringFind(const wchar_t *haystack, wchar_t needle)
|
||||
StringFind(const wchar_t *haystack, wchar_t needle) noexcept
|
||||
{
|
||||
return wcschr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline wchar_t *
|
||||
StringFind(wchar_t *haystack, wchar_t needle)
|
||||
StringFind(wchar_t *haystack, wchar_t needle) noexcept
|
||||
{
|
||||
return wcschr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline const wchar_t *
|
||||
StringFindLast(const wchar_t *haystack, wchar_t needle)
|
||||
StringFindLast(const wchar_t *haystack, wchar_t needle) noexcept
|
||||
{
|
||||
return wcsrchr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline wchar_t *
|
||||
StringFindLast(wchar_t *haystack, wchar_t needle)
|
||||
StringFindLast(wchar_t *haystack, wchar_t needle) noexcept
|
||||
{
|
||||
return wcsrchr(haystack, needle);
|
||||
}
|
||||
|
||||
gcc_nonnull_all
|
||||
static inline void
|
||||
UnsafeCopyString(wchar_t *dest, const wchar_t *src)
|
||||
UnsafeCopyString(wchar_t *dest, const wchar_t *src) noexcept
|
||||
{
|
||||
wcscpy(dest, src);
|
||||
}
|
||||
|
||||
gcc_nonnull_all
|
||||
static inline wchar_t *
|
||||
UnsafeCopyStringP(wchar_t *dest, const wchar_t *src)
|
||||
UnsafeCopyStringP(wchar_t *dest, const wchar_t *src) noexcept
|
||||
{
|
||||
#if defined(WIN32) || defined(__BIONIC__) || defined(__OpenBSD__) || \
|
||||
defined(__NetBSD__)
|
||||
@@ -119,7 +119,7 @@ UnsafeCopyStringP(wchar_t *dest, const wchar_t *src)
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline bool
|
||||
StringIsEqual(const wchar_t *str1, const wchar_t *str2)
|
||||
StringIsEqual(const wchar_t *str1, const wchar_t *str2) noexcept
|
||||
{
|
||||
return wcscmp(str1, str2) == 0;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ StringIsEqual(const wchar_t *str1, const wchar_t *str2)
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
static inline bool
|
||||
StringIsEqual(const wchar_t *a, const wchar_t *b, size_t length)
|
||||
StringIsEqual(const wchar_t *a, const wchar_t *b, size_t length) noexcept
|
||||
{
|
||||
return wcsncmp(a, b, length) == 0;
|
||||
}
|
||||
|
@@ -24,14 +24,14 @@
|
||||
#include <string.h>
|
||||
|
||||
bool
|
||||
StringStartsWith(const wchar_t *haystack, const wchar_t *needle)
|
||||
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)
|
||||
StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept
|
||||
{
|
||||
const size_t haystack_length = StringLength(haystack);
|
||||
const size_t needle_length = StringLength(needle);
|
||||
@@ -41,7 +41,7 @@ StringEndsWith(const wchar_t *haystack, const wchar_t *needle)
|
||||
}
|
||||
|
||||
const wchar_t *
|
||||
StringAfterPrefix(const wchar_t *string, const wchar_t *prefix)
|
||||
StringAfterPrefix(const wchar_t *string, const wchar_t *prefix) noexcept
|
||||
{
|
||||
#if !CLANG_CHECK_VERSION(3,6)
|
||||
/* disabled on clang due to -Wtautological-pointer-compare */
|
||||
@@ -56,7 +56,7 @@ StringAfterPrefix(const wchar_t *string, const wchar_t *prefix)
|
||||
}
|
||||
|
||||
const wchar_t *
|
||||
FindStringSuffix(const wchar_t *p, const wchar_t *suffix)
|
||||
FindStringSuffix(const wchar_t *p, const wchar_t *suffix) noexcept
|
||||
{
|
||||
const size_t p_length = StringLength(p);
|
||||
const size_t suffix_length = StringLength(suffix);
|
||||
|
@@ -42,20 +42,20 @@ StringIsEmpty(const wchar_t *string)
|
||||
|
||||
gcc_pure
|
||||
bool
|
||||
StringStartsWith(const wchar_t *haystack, const wchar_t *needle);
|
||||
StringStartsWith(const wchar_t *haystack, const wchar_t *needle) noexcept;
|
||||
|
||||
gcc_pure
|
||||
bool
|
||||
StringEndsWith(const wchar_t *haystack, const wchar_t *needle);
|
||||
StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the portion of the string after a prefix. If the string
|
||||
* does not begin with the specified prefix, this function returns
|
||||
* nullptr.
|
||||
*/
|
||||
gcc_nonnull_all
|
||||
gcc_pure gcc_nonnull_all
|
||||
const wchar_t *
|
||||
StringAfterPrefix(const wchar_t *string, const wchar_t *prefix);
|
||||
StringAfterPrefix(const wchar_t *string, const wchar_t *prefix) noexcept;
|
||||
|
||||
/**
|
||||
* Check if the given string ends with the specified suffix. If yes,
|
||||
@@ -63,6 +63,6 @@ StringAfterPrefix(const wchar_t *string, const wchar_t *prefix);
|
||||
*/
|
||||
gcc_pure
|
||||
const wchar_t *
|
||||
FindStringSuffix(const wchar_t *p, const wchar_t *suffix);
|
||||
FindStringSuffix(const wchar_t *p, const wchar_t *suffix) noexcept;
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user