Signed-off-by: Alejandro Colomar <[email protected]>
---
lib/string.in.h | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/lib/string.in.h b/lib/string.in.h
index 599203c44db9..d8214a3c2e09 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -1230,6 +1230,46 @@ _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
/* The following functions are not specified by POSIX. They are gnulib
extensions. */
+#if @GNULIB_STPSPN@
+/* Equivalent to s+strspn(s,accept). */
+# ifdef __cplusplus
+extern "C" {
+# endif
+_GL_STRING_INLINE const char *gl_stpspn (const char *s, const char *accept)
+ _GL_ATTRIBUTE_PURE
+ _GL_ARG_NONNULL ((1, 2));
+_GL_STRING_INLINE const char *gl_stpspn (const char *s)
+{
+ return s + strspn (s, accept);
+}
+# ifdef __cplusplus
+}
+# endif
+# ifdef __cplusplus
+template <typename T> T stpspn (T);
+template <>
+inline const char *stpspn<const char *> (const char *s, const char *accept)
+{ return gl_stpspn (s, accept) ; }
+template <>
+inline char *stpspn< char *> ( char *s, const char *accept)
+{ return const_cast<char *>(gl_stpspn (s, accept)); }
+# else
+# if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined
__cplusplus) \
+ || (defined __clang__ && __clang_major__ >= 3) \
+ || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) \
+ || (__STDC_VERSION__ >= 201112L && !defined __GNUC__)
+/* The compiler supports _Generic from ISO C11. */
+# define stpspn(s, accept) \
+ _Generic (s, \
+ char * : (char *) gl_stpspn (s, accept), \
+ const char * : gl_stpspn (s, accept))
+# else
+# define stpspn(s, accept) \
+ ((char *) gl_stpspn (s, accept))
+# endif
+# endif
+#endif
+
#if @GNULIB_STRNUL@
/* Returns a pointer to the terminating NUL byte of STRING.
strnul (string)
--
2.51.0