From 398ebac4849fa0f97112f62190236fdf6ac64676 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 3 Jan 2025 11:17:16 +0100 Subject: [PATCH] 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. --- ChangeLog | 9 +++++++++ lib/string.in.h | 10 ++++++++++ m4/string_h.m4 | 3 ++- modules/mbs_startswith | 22 ++++++++++++++++++++++ modules/string-h | 1 + 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 modules/mbs_startswith diff --git a/ChangeLog b/ChangeLog index 300538b682..a7b87e7061 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2025-01-03 Bruno Haible + + 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 tests: Use str_endswith. diff --git a/lib/string.in.h b/lib/string.in.h index f11b8f5706..ce5b493d71 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -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@ diff --git a/m4/string_h.m4 b/m4/string_h.m4 index d2adb95bad..a2c8536f38 100644 --- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -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 index 0000000000..b7145de034 --- /dev/null +++ b/modules/mbs_startswith @@ -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: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/string-h b/modules/string-h index 0897afe206..1114bcf9eb 100644 --- a/modules/string-h +++ b/modules/string-h @@ -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' \ -- 2.39.5