util/StringStrip: add more "nonnull" attributes

This commit is contained in:
Max Kellermann 2018-08-20 16:28:43 +02:00
parent ec54754e22
commit 441440101d
2 changed files with 10 additions and 8 deletions

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009-2017 Max Kellermann <max.kellermann@gmail.com> * Copyright 2009-2018 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

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009-2017 Max Kellermann <max.kellermann@gmail.com> * Copyright 2009-2018 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
@ -38,32 +38,32 @@
* Returns a pointer to the first non-whitespace character in the * Returns a pointer to the first non-whitespace character in the
* string, or to the end of the string. * string, or to the end of the string.
*/ */
gcc_pure gcc_pure gcc_returns_nonnull gcc_nonnull_all
const char * const char *
StripLeft(const char *p) noexcept; StripLeft(const char *p) noexcept;
gcc_pure gcc_pure gcc_returns_nonnull gcc_nonnull_all
static inline char * static inline char *
StripLeft(char *p) noexcept StripLeft(char *p) noexcept
{ {
return const_cast<char *>(StripLeft((const char *)p)); return const_cast<char *>(StripLeft((const char *)p));
} }
gcc_pure gcc_pure gcc_returns_nonnull gcc_nonnull_all
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_pure gcc_returns_nonnull gcc_nonnull_all
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_pure gcc_returns_nonnull gcc_nonnull_all
static inline char * static inline char *
StripRight(char *p, char *end) noexcept StripRight(char *p, char *end) noexcept
{ {
@ -75,13 +75,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_pure gcc_nonnull_all
size_t size_t
StripRight(const char *p, size_t length) noexcept; StripRight(const char *p, size_t length) noexcept;
/** /**
* Strip trailing whitespace by null-terminating the string. * Strip trailing whitespace by null-terminating the string.
*/ */
gcc_nonnull_all
void void
StripRight(char *p) noexcept; StripRight(char *p) noexcept;
@ -89,6 +90,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
char * char *
Strip(char *p) noexcept; Strip(char *p) noexcept;