These APIs are to strrspn(), like strcspn() is to strspn().
They are like strcspn(3), but search from the end of the string.
The function is meant for internal use, and consistency with libc.
The macro is meant for normal use, since it returns a pointer,
which is what algorithms using this need.
See also strspn(3) and strcspn(3).
Signed-off-by: Alejandro Colomar <alx@kernel.org>
string/strchr/strchrscnt.h \
string/strchr/stpspn.c \
string/strchr/stpspn.h \
+ string/strchr/stprcspn.c \
+ string/strchr/stprcspn.h \
string/strchr/strnul.c \
string/strchr/strnul.h \
+ string/strchr/strrcspn.c \
+ string/strchr/strrcspn.h \
string/strchr/strrspn.c \
string/strchr/strrspn.h \
string/strcmp/strcaseeq.c \
--- /dev/null
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "string/strchr/stprcspn.h"
--- /dev/null
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_STRCHR_STPRCSPN_H_
+#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STPRCSPN_H_
+
+
+#include <config.h>
+
+#include <string.h>
+
+#include "string/strchr/strrcspn.h"
+
+
+#define stprcspn(s, reject) \
+({ \
+ __auto_type s_ = (s); \
+ \
+ s_ + strrcspn(s_, reject); \
+})
+
+
+#endif // include guard
--- /dev/null
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "string/strchr/strrcspn.h"
+
+#include <stddef.h>
+
+
+extern inline size_t strrcspn(const char *s, const char *reject);
--- /dev/null
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_STRCHR_STRRCSPN_H_
+#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STRRCSPN_H_
+
+
+#include <config.h>
+
+#include <stddef.h>
+#include <string.h>
+
+#include "attr.h"
+#include "string/strchr/strnul.h"
+
+
+ATTR_STRING(1)
+ATTR_STRING(2)
+inline size_t strrcspn(const char *s, const char *reject);
+
+
+inline size_t
+strrcspn(const char *s, const char *reject)
+{
+ char *p;
+
+ p = strnul(s);
+ while (p > s) {
+ p--;
+ if (strchr(reject, *p) != NULL)
+ return p + 1 - s;
+ }
+ return 0;
+}
+
+
+#endif // include guard