mbs_startswith: New module.
authorBruno Haible <bruno@clisp.org>
Fri, 3 Jan 2025 10:17:16 +0000 (11:17 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 3 Jan 2025 10:17:16 +0000 (11:17 +0100)
* lib/string.in.h (mbs_startswith): New declaration.
* m4/string_h.m4 (gl_STRING_H_REQUIRE_DEFAULTS): Initialize
GNULIB_MBS_STARTSWITH.
* modules/string-h (Makefile.am): Substitute GNULIB_MBS_STARTSWITH.
* modules/mbs_startswith: New file.

ChangeLog
lib/string.in.h
m4/string_h.m4
modules/mbs_startswith [new file with mode: 0644]
modules/string-h

index 300538b6825311e3acc1b2a9350a20017e5fd6bd..a7b87e70610645de719240bdbd905507f3091bcd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-01-03  Bruno Haible  <bruno@clisp.org>
+
+       mbs_startswith: New module.
+       * lib/string.in.h (mbs_startswith): New declaration.
+       * m4/string_h.m4 (gl_STRING_H_REQUIRE_DEFAULTS): Initialize
+       GNULIB_MBS_STARTSWITH.
+       * modules/string-h (Makefile.am): Substitute GNULIB_MBS_STARTSWITH.
+       * modules/mbs_startswith: New file.
+
 2025-01-03  Bruno Haible  <bruno@clisp.org>
 
        tests: Use str_endswith.
index f11b8f5706596361d598a43217df04c870d86a5d..ce5b493d7174583d55222891f9029b26238badcd 100644 (file)
@@ -1317,6 +1317,16 @@ _GL_EXTERN_C char * mbstok_r (char *restrict string, const char *delim,
      _GL_ARG_NONNULL ((2, 3));
 #endif
 
+#if @GNULIB_MBS_STARTSWITH@
+/* Returns true if STRING starts with PREFIX.
+   Returns false otherwise.  */
+_GL_EXTERN_C int mbs_startswith (const char *string, const char *prefix)
+     _GL_ATTRIBUTE_PURE
+     _GL_ARG_NONNULL ((1, 2));
+/* No extra code is needed for multibyte locales for this function.  */
+# define mbs_startswith str_startswith
+#endif
+
 /* Map any int, typically from errno, into an error message.  */
 #if @GNULIB_STRERROR@
 # if @REPLACE_STRERROR@
index d2adb95bad177cfdd96cdffe508ac954d28e1a83..a2c8536f38e3110389b8fc6af2f3fa6a99c6e7fd 100644 (file)
@@ -1,5 +1,5 @@
 # string_h.m4
-# serial 41
+# serial 42
 dnl Copyright (C) 2007-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -86,6 +86,7 @@ AC_DEFUN([gl_STRING_H_REQUIRE_DEFAULTS],
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSSPN])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSSEP])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSTOK_R])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBS_STARTSWITH])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRERROR])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRERROR_R])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRERRORNAME_NP])
diff --git a/modules/mbs_startswith b/modules/mbs_startswith
new file mode 100644 (file)
index 0000000..b7145de
--- /dev/null
@@ -0,0 +1,22 @@
+Description:
+mbs_startswith() function: test whether a multibyte string starts with a given prefix.
+
+Files:
+
+Depends-on:
+string-h
+str_startswith
+
+configure.ac:
+gl_STRING_MODULE_INDICATOR([mbs_startswith])
+
+Makefile.am:
+
+Include:
+<string.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
index 0897afe206c8aef63b2f2f910614ef10000f1303..1114bcf9eb4db8ca31a6458355a7f9c4fd1898a7 100644 (file)
@@ -51,6 +51,7 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's/@''GNULIB_MBSSPN''@/$(GNULIB_MBSSPN)/g' \
              -e 's/@''GNULIB_MBSSEP''@/$(GNULIB_MBSSEP)/g' \
              -e 's/@''GNULIB_MBSTOK_R''@/$(GNULIB_MBSTOK_R)/g' \
+             -e 's/@''GNULIB_MBS_STARTSWITH''@/$(GNULIB_MBS_STARTSWITH)/g' \
              -e 's/@''GNULIB_MEMCHR''@/$(GNULIB_MEMCHR)/g' \
              -e 's/@''GNULIB_MEMMEM''@/$(GNULIB_MEMMEM)/g' \
              -e 's/@''GNULIB_MEMPCPY''@/$(GNULIB_MEMPCPY)/g' \