Support mcel API for apps that prefer it.
* lib/mbschr.c, lib/mbsrchr.c: Include stdlib.h, for MB_CUR_MAX.
[GNULIB_MCEL_PREFER]: Include mcel.h instead of mbuiterf.h.
(mbschr, mbsrchr) [GNULIB_MCEL_PREFER]: Use mcel API.
2023-09-21 Paul Eggert <eggert@cs.ucla.edu>
+ mbschr, mbsrchr: support GNULIB_MCEL_PREFER
+ Support mcel API for apps that prefer it.
+ The following changes are in effect only if GNULIB_MCEL_PREFER.
+ * lib/mbschr.c, lib/mbsrchr.c: Include stdlib.h, for MB_CUR_MAX.
+ [GNULIB_MCEL_PREFER]: Include mcel.h instead of mbuiterf.h.
+ (mbschr, mbsrchr) [GNULIB_MCEL_PREFER]: Use mcel API.
+
gnulib-common: don’t suppress -Wpedantic
Problem reported by Pádraig Brady in:
https://lists.gnu.org/r/bug-gnulib/2023-09/msg00130.html
/* Specification. */
#include <string.h>
-#include "mbuiterf.h"
+#include <stdlib.h>
+
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiterf.h"
+#endif
/* Locate the first single-byte character C in the character string STRING,
and return a pointer to it. Return NULL if C is not found in STRING. */
the faster unibyte loop can be used. */
&& (unsigned char) c >= 0x30)
{
+#if GNULIB_MCEL_PREFER
+ while (*string)
+ {
+ mcel_t g = mcel_scanz (string);
+ if (g.len == 1 && (unsigned char) *string == (unsigned char) c)
+ return (char *) string;
+ string += g.len;
+ }
+#else
mbuif_state_t state;
const char *iter;
for (mbuif_init (state), iter = string;; )
}
return (char *) iter;
notfound:
+#endif
return NULL;
}
else
/* Specification. */
#include <string.h>
-#include "mbuiterf.h"
+#include <stdlib.h>
+
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiterf.h"
+#endif
/* Locate the last single-byte character C in the character string STRING,
and return a pointer to it. Return NULL if C is not found in STRING. */
{
const char *result = NULL;
+#if GNULIB_MCEL_PREFER
+ while (*string)
+ {
+ mcel_t g = mcel_scanz (string);
+ if (g.len == 1 && (unsigned char) *string == (unsigned char) c)
+ result = string;
+ string += g.len;
+ }
+#else
mbuif_state_t state;
const char *iter;
for (mbuif_init (state), iter = string; mbuif_avail (state, iter); )
result = iter;
iter += mb_len (cur);
}
+#endif
return (char *) result;
}