1 /* Searching a string for a character among a given set of characters.
2 Copyright (C) 1999, 2002, 2006-2024 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2007.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation, either version 3 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
25 #if GNULIB_MCEL_PREFER
28 # include "mbuiterf.h"
31 /* Find the first occurrence in the character string STRING of any character
32 in the character string ACCEPT. Return the pointer to it, or NULL if none
35 mbspbrk (const char *string
, const char *accept
)
37 /* Optimize two cases. */
38 if (accept
[0] == '\0')
40 if (accept
[1] == '\0')
41 return mbschr (string
, accept
[0]);
45 char const *iter
= string
;
46 #if GNULIB_MCEL_PREFER
48 for (; *iter
; iter
+= g
.len
)
50 g
= mcel_scanz (iter
);
53 if (mbschr (accept
, *iter
))
57 for (char const *aiter
= accept
; *aiter
; aiter
+= a
.len
)
59 a
= mcel_scanz (aiter
);
60 if (mcel_cmp (a
, g
) == 0)
66 for (mbuif_init (state
); mbuif_avail (state
, iter
); )
68 mbchar_t cur
= mbuif_next (state
, iter
);
69 if (mb_len (cur
) == 1)
71 if (mbschr (accept
, *iter
))
78 for (mbuif_init (astate
), aiter
= accept
;
79 mbuif_avail (astate
, aiter
); )
81 mbchar_t acur
= mbuif_next (astate
, aiter
);
82 if (mb_equal (acur
, cur
))
84 aiter
+= mb_len (acur
);
93 return strpbrk (string
, accept
);