From 78b62f8320f8dffb813222c1480563ed14251ca3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Sep 2023 17:44:12 -0700 Subject: [PATCH] propername: support GNULIB_MCEL_PREFER Support mcel API for apps that prefer it. The following changes are in effect only if GNULIB_MCEL_PREFER. * lib/propername.c: Include mcel.h, not mbchar.h and mbuiter.h. (mbsstr_trimmed_wordbounded): Use mcel API. * modules/propername (Depends-on): Add c32isalnum. --- ChangeLog | 7 +++++++ lib/propername.c | 36 ++++++++++++++++++++++++++++++++++-- modules/propername | 1 + 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b0569af8b..a01e01a657 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2023-09-09 Paul Eggert + propername: support GNULIB_MCEL_PREFER + Support mcel API for apps that prefer it. + The following changes are in effect only if GNULIB_MCEL_PREFER. + * lib/propername.c: Include mcel.h, not mbchar.h and mbuiter.h. + (mbsstr_trimmed_wordbounded): Use mcel API. + * modules/propername (Depends-on): Add c32isalnum. + trim: support GNULIB_MCEL_PREFER Support mcel API for apps that prefer it. The following changes are in effect only if GNULIB_MCEL_PREFER. diff --git a/lib/propername.c b/lib/propername.c index dbd96b8772..7199dcaa50 100644 --- a/lib/propername.c +++ b/lib/propername.c @@ -35,8 +35,12 @@ #endif #include "trim.h" -#include "mbchar.h" -#include "mbuiter.h" +#if GNULIB_MCEL_PREFER +# include "mcel.h" +#else +# include "mbchar.h" +# include "mbuiter.h" +#endif #include "localcharset.h" #include "c-strcase.h" #include "xstriconv.h" @@ -69,6 +73,33 @@ mbsstr_trimmed_wordbounded (const char *string, const char *sub) { if (multibyte_locale) { +#if GNULIB_MCEL_PREFER + char const *string_iter = string; + + char32_t last_char_before_tsub = 0; + while (string_iter < tsub_in_string) + { + mcel_t g = mcel_scanz (string_iter); + last_char_before_tsub = g.ch; + string_iter += g.len; + } + + string_iter = tsub_in_string; + for (char const *tsub_iter = tsub; *tsub_iter; + tsub_iter += mcel_scanz (tsub_iter).len) + string_iter += mcel_scanz (string_iter).len; + + if (!c32isalnum (last_char_before_tsub) + && !c32isalnum (mcel_scanz (string_iter).ch)) + { + found = true; + break; + } + + if (!*tsub_in_string) + break; + string = tsub_in_string + mcel_scanz (tsub_in_string).len; +#else mbui_iterator_t string_iter; bool word_boundary_before; bool word_boundary_after; @@ -121,6 +152,7 @@ mbsstr_trimmed_wordbounded (const char *string, const char *sub) if (!mbui_avail (string_iter)) break; string = tsub_in_string + mb_len (mbui_cur (string_iter)); +#endif } else { diff --git a/modules/propername b/modules/propername index 8ee9c5e320..7384881d89 100644 --- a/modules/propername +++ b/modules/propername @@ -6,6 +6,7 @@ lib/propername.h lib/propername.c Depends-on: +c32isalnum stdbool trim mbsstr -- 2.39.5