]> Savannah Git Hosting - gnulib.git/commitdiff
propername: support GNULIB_MCEL_PREFER
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 10 Sep 2023 00:44:12 +0000 (17:44 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 10 Sep 2023 01:11:45 +0000 (18:11 -0700)
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
lib/propername.c
modules/propername

index 2b0569af8bdf1523bb0bff411d3f2b9f0a382673..a01e01a6570ea39b2d8fc20a2a75a12328c5e8fa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2023-09-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       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.
index dbd96b87729153571ea2fa1f8d488aa599a86dbe..7199dcaa5080570ea8d9422457a71e982a0c0eb3 100644 (file)
 #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
             {
index 8ee9c5e32051d3682021d8b63af851a5ec564b55..7384881d8911c12503bb2423d3d177b4be94d350 100644 (file)
@@ -6,6 +6,7 @@ lib/propername.h
 lib/propername.c
 
 Depends-on:
+c32isalnum
 stdbool
 trim
 mbsstr