From c793de02c74f5a84b228f117293b64afa8603f59 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Sep 2023 17:22:19 -0700 Subject: [PATCH] trim: support GNULIB_MCEL_PREFER Support mcel API for apps that prefer it. The following changes are in effect only if GNULIB_MCEL_PREFER. * lib/trim.c: Include mcel.h, not mbchar.h and mbuiterf.h. (trim2): Use mcel API. * modules/trim (Depends-on): Add c32isspace. --- ChangeLog | 7 +++++++ lib/trim.c | 29 +++++++++++++++++++++++++++-- modules/trim | 1 + 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a97a5081b0..2b0569af8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2023-09-09 Paul Eggert + trim: support GNULIB_MCEL_PREFER + Support mcel API for apps that prefer it. + The following changes are in effect only if GNULIB_MCEL_PREFER. + * lib/trim.c: Include mcel.h, not mbchar.h and mbuiterf.h. + (trim2): Use mcel API. + * modules/trim (Depends-on): Add c32isspace. + mbsstr: support GNULIB_MCEL_PREFER Support mcel API for apps that prefer it. * lib/mbsstr.c [GNULIB_MCEL_PREFER]: Include mcel.h not mbuiter.h. diff --git a/lib/trim.c b/lib/trim.c index 8ebbc29658..bad19c13b6 100644 --- a/lib/trim.c +++ b/lib/trim.c @@ -26,8 +26,12 @@ #include #include -#include "mbchar.h" -#include "mbuiterf.h" +#if GNULIB_MCEL_PREFER +# include "mcel.h" +#else +# include "mbchar.h" +# include "mbuiterf.h" +#endif #include "xalloc.h" char * @@ -38,6 +42,26 @@ trim2 (const char *s, int how) if (MB_CUR_MAX > 1) { +#if GNULIB_MCEL_PREFER + /* Skip leading whitespace. */ + if (how != TRIM_TRAILING) + for (mcel_t g; *start; start += g.len) + { + g = mcel_scanz (start); + if (!c32isspace (g.ch)) + break; + } + + /* Find start of any trailing whitespace. */ + if (how != TRIM_LEADING) + for (const char *p = end = start; *p; ) + { + mcel_t g = mcel_scanz (p); + p += g.len; + if (!c32isspace (g.ch)) + end = p; + } +#else mbuif_state_t state; mbuif_init (state); @@ -60,6 +84,7 @@ trim2 (const char *s, int how) if (!mb_isspace (cur)) end = p; } +#endif } else { diff --git a/modules/trim b/modules/trim index 9f45dade80..f20d8ad84e 100644 --- a/modules/trim +++ b/modules/trim @@ -6,6 +6,7 @@ lib/trim.h lib/trim.c Depends-on: +c32isspace mbchar mbuiterf mempcpy -- 2.39.5