summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-05-08 14:44:49 +0200
committerMax Kellermann <max@musicpd.org>2017-05-08 14:44:49 +0200
commit71f0ed8b7499011b53f90998ebfbd3250fd80948 (patch)
treee9c2f66fbef231858f46d878864199d46e6ce21c /src/util
parentac2e4e593d407e41db49fdb9ae2da6bc1557f618 (diff)
*: add "noexcept" to many, many function prototypes
This eliminates some overhead, because the compiler doesn't need to consider these functions throwing.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/ASCII.hxx4
-rw-r--r--src/util/HugeAllocator.cxx2
-rw-r--r--src/util/PeakBuffer.cxx9
-rw-r--r--src/util/PeakBuffer.hxx6
-rw-r--r--src/util/StringAPI.hxx26
-rw-r--r--src/util/StringCompare.cxx6
-rw-r--r--src/util/StringCompare.hxx10
-rw-r--r--src/util/StringUtil.cxx20
-rw-r--r--src/util/StringUtil.hxx23
-rw-r--r--src/util/TimeParser.cxx2
-rw-r--r--src/util/UTF8.cxx21
-rw-r--r--src/util/UTF8.hxx12
-rw-r--r--src/util/UriUtil.cxx29
-rw-r--r--src/util/UriUtil.hxx21
-rw-r--r--src/util/WStringAPI.hxx26
-rw-r--r--src/util/WStringCompare.cxx8
-rw-r--r--src/util/WStringCompare.hxx10
17 files changed, 121 insertions, 114 deletions
diff --git a/src/util/ASCII.hxx b/src/util/ASCII.hxx
index 38cd9b765..6d31d836a 100644
--- a/src/util/ASCII.hxx
+++ b/src/util/ASCII.hxx
@@ -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 */
diff --git a/src/util/HugeAllocator.cxx b/src/util/HugeAllocator.cxx
index 67fba1c6d..5116a5923 100644
--- a/src/util/HugeAllocator.cxx
+++ b/src/util/HugeAllocator.cxx
@@ -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)
diff --git a/src/util/PeakBuffer.cxx b/src/util/PeakBuffer.cxx
index 05d2f9e89..ea7ad94f3 100644
--- a/src/util/PeakBuffer.cxx
+++ b/src/util/PeakBuffer.cxx
@@ -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);
diff --git a/src/util/PeakBuffer.hxx b/src/util/PeakBuffer.hxx
index a508062dc..294cba380 100644
--- a/src/util/PeakBuffer.hxx
+++ b/src/util/PeakBuffer.hxx
@@ -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);
};
diff --git a/src/util/StringAPI.hxx b/src/util/StringAPI.hxx
index d9e89c628..85456fb8f 100644
--- a/src/util/StringAPI.hxx
+++ b/src/util/StringAPI.hxx
@@ -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;
}
diff --git a/src/util/StringCompare.cxx b/src/util/StringCompare.cxx
index 0eb99034d..58ac5a2c1 100644
--- a/src/util/StringCompare.cxx
+++ b/src/util/StringCompare.cxx
@@ -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);
diff --git a/src/util/StringCompare.hxx b/src/util/StringCompare.hxx
index 39df6c519..b8c69031a 100644
--- a/src/util/StringCompare.hxx
+++ b/src/util/StringCompare.hxx
@@ -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
diff --git a/src/util/StringUtil.cxx b/src/util/StringUtil.cxx
index 9f9d16c41..b8851edb6 100644
--- a/src/util/StringUtil.cxx
+++ b/src/util/StringUtil.cxx
@@ -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);
diff --git a/src/util/StringUtil.hxx b/src/util/StringUtil.hxx
index c2fc5dcbc..0fe131f25 100644
--- a/src/util/StringUtil.hxx
+++ b/src/util/StringUtil.hxx
@@ -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
diff --git a/src/util/TimeParser.cxx b/src/util/TimeParser.cxx
index 1a3417928..b99433a75 100644
--- a/src/util/TimeParser.cxx
+++ b/src/util/TimeParser.cxx
@@ -41,7 +41,7 @@
*/
gcc_const
static time_t
-GetTimeZoneOffset()
+GetTimeZoneOffset() noexcept
{
time_t t = 1234567890;
struct tm tm;
diff --git a/src/util/UTF8.cxx b/src/util/UTF8.cxx
index e0d0a4fd7..21ce6e1a8 100644
--- a/src/util/UTF8.cxx
+++ b/src/util/UTF8.cxx
@@ -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
diff --git a/src/util/UTF8.hxx b/src/util/UTF8.hxx
index e829407bb..62decb4f5 100644
--- a/src/util/UTF8.hxx
+++ b/src/util/UTF8.hxx
@@ -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
diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx
index 74f831513..61b90da29 100644
--- a/src/util/UriUtil.cxx
+++ b/src/util/UriUtil.cxx
@@ -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 */
diff --git a/src/util/UriUtil.hxx b/src/util/UriUtil.hxx
index 3f673ca7b..10ed67cc0 100644
--- a/src/util/UriUtil.hxx
+++ b/src/util/UriUtil.hxx
@@ -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
diff --git a/src/util/WStringAPI.hxx b/src/util/WStringAPI.hxx
index 1feaf78c6..f69aaf6d1 100644
--- a/src/util/WStringAPI.hxx
+++ b/src/util/WStringAPI.hxx
@@ -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;
}
diff --git a/src/util/WStringCompare.cxx b/src/util/WStringCompare.cxx
index 1ffdb82c3..c030d84ac 100644
--- a/src/util/WStringCompare.cxx
+++ b/src/util/WStringCompare.cxx
@@ -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);
diff --git a/src/util/WStringCompare.hxx b/src/util/WStringCompare.hxx
index ce5d3163d..03bb19794 100644
--- a/src/util/WStringCompare.hxx
+++ b/src/util/WStringCompare.hxx
@@ -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