Commit 05f529ff authored by Max Kellermann's avatar Max Kellermann

util/StringStrip: use [[gnu::...]] attributes

parent f0138855
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "LogBackend.hxx" #include "LogBackend.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "util/Compiler.h"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/StringStrip.hxx" #include "util/StringStrip.hxx"
#include "Version.h" #include "Version.h"
...@@ -110,7 +111,7 @@ chomp_length(std::string_view p) noexcept ...@@ -110,7 +111,7 @@ chomp_length(std::string_view p) noexcept
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
gcc_const [[gnu::const]]
static int static int
ToSysLogLevel(LogLevel log_level) noexcept ToSysLogLevel(LogLevel log_level) noexcept
{ {
......
/* /*
* Copyright 2009-2020 Max Kellermann <max.kellermann@gmail.com> * Copyright 2009-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
......
/* /*
* Copyright 2009-2020 Max Kellermann <max.kellermann@gmail.com> * Copyright 2009-2021 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
#ifndef STRING_STRIP_HXX #ifndef STRING_STRIP_HXX
#define STRING_STRIP_HXX #define STRING_STRIP_HXX
#include "Compiler.h"
#include <cstddef> #include <cstddef>
/** /**
...@@ -40,11 +38,11 @@ ...@@ -40,11 +38,11 @@
* non-whitespace characters, then a pointer to the NULL terminator is * non-whitespace characters, then a pointer to the NULL terminator is
* returned. * returned.
*/ */
gcc_pure gcc_returns_nonnull gcc_nonnull_all [[gnu::pure]] [[gnu::returns_nonnull]] [[gnu::nonnull]]
const char * const char *
StripLeft(const char *p) noexcept; StripLeft(const char *p) noexcept;
gcc_pure gcc_returns_nonnull gcc_nonnull_all [[gnu::pure]] [[gnu::returns_nonnull]] [[gnu::nonnull]]
static inline char * static inline char *
StripLeft(char *p) noexcept StripLeft(char *p) noexcept
{ {
...@@ -55,21 +53,21 @@ StripLeft(char *p) noexcept ...@@ -55,21 +53,21 @@ StripLeft(char *p) noexcept
* Skips whitespace at the beginning of the string, and returns the * Skips whitespace at the beginning of the string, and returns the
* first non-whitespace character or the end pointer. * first non-whitespace character or the end pointer.
*/ */
gcc_pure gcc_returns_nonnull gcc_nonnull_all [[gnu::pure]] [[gnu::returns_nonnull]] [[gnu::nonnull]]
const char * const char *
StripLeft(const char *p, const char *end) noexcept; StripLeft(const char *p, const char *end) noexcept;
/** /**
* Determine the string's end as if it was stripped on the right side. * Determine the string's end as if it was stripped on the right side.
*/ */
gcc_pure gcc_returns_nonnull gcc_nonnull_all [[gnu::pure]] [[gnu::returns_nonnull]] [[gnu::nonnull]]
const char * const char *
StripRight(const char *p, const char *end) noexcept; StripRight(const char *p, const char *end) noexcept;
/** /**
* Determine the string's end as if it was stripped on the right side. * Determine the string's end as if it was stripped on the right side.
*/ */
gcc_pure gcc_returns_nonnull gcc_nonnull_all [[gnu::pure]] [[gnu::returns_nonnull]] [[gnu::nonnull]]
static inline char * static inline char *
StripRight(char *p, char *end) noexcept StripRight(char *p, char *end) noexcept
{ {
...@@ -81,14 +79,14 @@ StripRight(char *p, char *end) noexcept ...@@ -81,14 +79,14 @@ StripRight(char *p, char *end) noexcept
* Determine the string's length as if it was stripped on the right * Determine the string's length as if it was stripped on the right
* side. * side.
*/ */
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
std::size_t std::size_t
StripRight(const char *p, std::size_t length) noexcept; StripRight(const char *p, std::size_t length) noexcept;
/** /**
* Strip trailing whitespace by null-terminating the string. * Strip trailing whitespace by null-terminating the string.
*/ */
gcc_nonnull_all [[gnu::nonnull]]
void void
StripRight(char *p) noexcept; StripRight(char *p) noexcept;
...@@ -96,7 +94,7 @@ StripRight(char *p) noexcept; ...@@ -96,7 +94,7 @@ StripRight(char *p) noexcept;
* Skip whitespace at the beginning and terminate the string after the * Skip whitespace at the beginning and terminate the string after the
* last non-whitespace character. * last non-whitespace character.
*/ */
gcc_returns_nonnull gcc_nonnull_all [[gnu::returns_nonnull]] [[gnu::nonnull]]
char * char *
Strip(char *p) noexcept; Strip(char *p) noexcept;
......
/* /*
* Copyright 2011-2019 Max Kellermann <max.kellermann@gmail.com> * Copyright 2011-2021 Max Kellermann <max.kellermann@gmail.com>
* http://www.musicpd.org
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -30,6 +29,7 @@ ...@@ -30,6 +29,7 @@
#include "UTF8.hxx" #include "UTF8.hxx"
#include "CharUtil.hxx" #include "CharUtil.hxx"
#include "Compiler.h"
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
...@@ -196,7 +196,7 @@ SequenceLengthUTF8(char ch) noexcept ...@@ -196,7 +196,7 @@ SequenceLengthUTF8(char ch) noexcept
template<std::size_t L> template<std::size_t L>
struct CheckSequenceUTF8 { struct CheckSequenceUTF8 {
gcc_pure [[gnu::pure]]
bool operator()(const char *p) const noexcept { bool operator()(const char *p) const noexcept {
return IsContinuation(*p) && CheckSequenceUTF8<L-1>()(p + 1); return IsContinuation(*p) && CheckSequenceUTF8<L-1>()(p + 1);
} }
...@@ -210,7 +210,7 @@ struct CheckSequenceUTF8<0U> { ...@@ -210,7 +210,7 @@ struct CheckSequenceUTF8<0U> {
}; };
template<std::size_t L> template<std::size_t L>
gcc_pure [[gnu::pure]]
static std::size_t static std::size_t
InnerSequenceLengthUTF8(const char *p) noexcept InnerSequenceLengthUTF8(const char *p) noexcept
{ {
...@@ -247,7 +247,7 @@ SequenceLengthUTF8(const char *p) noexcept ...@@ -247,7 +247,7 @@ SequenceLengthUTF8(const char *p) noexcept
return 0; return 0;
} }
gcc_pure [[gnu::pure]]
static const char * static const char *
FindNonASCIIOrZero(const char *p) noexcept FindNonASCIIOrZero(const char *p) noexcept
{ {
......
/* /*
* Copyright 2011-2019 Max Kellermann <max.kellermann@gmail.com> * Copyright 2011-2021 Max Kellermann <max.kellermann@gmail.com>
* http://www.musicpd.org
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -31,14 +30,12 @@ ...@@ -31,14 +30,12 @@
#ifndef UTF8_HXX #ifndef UTF8_HXX
#define UTF8_HXX #define UTF8_HXX
#include "Compiler.h"
#include <cstddef> #include <cstddef>
/** /**
* Is this a valid UTF-8 string? * Is this a valid UTF-8 string?
*/ */
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
bool bool
ValidateUTF8(const char *p) noexcept; ValidateUTF8(const char *p) noexcept;
...@@ -46,7 +43,7 @@ ValidateUTF8(const char *p) noexcept; ...@@ -46,7 +43,7 @@ ValidateUTF8(const char *p) noexcept;
* @return the number of the sequence beginning with the given * @return the number of the sequence beginning with the given
* character, or 0 if the character is not a valid start byte * character, or 0 if the character is not a valid start byte
*/ */
gcc_const [[gnu::const]]
std::size_t std::size_t
SequenceLengthUTF8(char ch) noexcept; SequenceLengthUTF8(char ch) noexcept;
...@@ -54,7 +51,7 @@ SequenceLengthUTF8(char ch) noexcept; ...@@ -54,7 +51,7 @@ SequenceLengthUTF8(char ch) noexcept;
* @return the number of the first sequence in the given string, or 0 * @return the number of the first sequence in the given string, or 0
* if the sequence is malformed * if the sequence is malformed
*/ */
gcc_pure [[gnu::pure]]
std::size_t std::size_t
SequenceLengthUTF8(const char *p) noexcept; SequenceLengthUTF8(const char *p) noexcept;
...@@ -65,7 +62,7 @@ SequenceLengthUTF8(const char *p) noexcept; ...@@ -65,7 +62,7 @@ SequenceLengthUTF8(const char *p) noexcept;
* there are no non-ASCII characters; returns nullptr if the destination * there are no non-ASCII characters; returns nullptr if the destination
* buffer is too small * buffer is too small
*/ */
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
const char * const char *
Latin1ToUTF8(const char *src, char *buffer, std::size_t buffer_size) noexcept; Latin1ToUTF8(const char *src, char *buffer, std::size_t buffer_size) noexcept;
...@@ -75,7 +72,7 @@ Latin1ToUTF8(const char *src, char *buffer, std::size_t buffer_size) noexcept; ...@@ -75,7 +72,7 @@ Latin1ToUTF8(const char *src, char *buffer, std::size_t buffer_size) noexcept;
* *
* @return a pointer to the buffer plus the added bytes(s) * @return a pointer to the buffer plus the added bytes(s)
*/ */
gcc_nonnull_all [[gnu::nonnull]]
char * char *
UnicodeToUTF8(unsigned ch, char *buffer) noexcept; UnicodeToUTF8(unsigned ch, char *buffer) noexcept;
...@@ -83,7 +80,7 @@ UnicodeToUTF8(unsigned ch, char *buffer) noexcept; ...@@ -83,7 +80,7 @@ UnicodeToUTF8(unsigned ch, char *buffer) noexcept;
* Returns the number of characters in the string. This is different * Returns the number of characters in the string. This is different
* from strlen(), which counts the number of bytes. * from strlen(), which counts the number of bytes.
*/ */
gcc_pure gcc_nonnull_all [[gnu::pure]] [[gnu::nonnull]]
std::size_t std::size_t
LengthUTF8(const char *p) noexcept; LengthUTF8(const char *p) noexcept;
......
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