Merge remote-tracking branch 'origin/stable-2.0'
[bpt/guile.git] / lib / unistr.in.h
CommitLineData
24d56127 1/* Elementary Unicode string functions.
f0007cad 2 Copyright (C) 2001-2002, 2005-2012 Free Software Foundation, Inc.
24d56127
LC
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifndef _UNISTR_H
18#define _UNISTR_H
19
20#include "unitypes.h"
21
61cd9dc9
LC
22/* Get common macros for C. */
23#include "unused-parameter.h"
24
24d56127
LC
25/* Get bool. */
26#include <stdbool.h>
27
28/* Get size_t. */
29#include <stddef.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35
36/* Conventions:
37
38 All functions prefixed with u8_ operate on UTF-8 encoded strings.
39 Their unit is an uint8_t (1 byte).
40
41 All functions prefixed with u16_ operate on UTF-16 encoded strings.
42 Their unit is an uint16_t (a 2-byte word).
43
44 All functions prefixed with u32_ operate on UCS-4 encoded strings.
45 Their unit is an uint32_t (a 4-byte word).
46
47 All argument pairs (s, n) denote a Unicode string s[0..n-1] with exactly
48 n units.
49
50 All arguments starting with "str" and the arguments of functions starting
51 with u8_str/u16_str/u32_str denote a NUL terminated string, i.e. a string
52 which terminates at the first NUL unit. This termination unit is
53 considered part of the string for all memory allocation purposes, but
54 is not considered part of the string for all other logical purposes.
55
56 Functions returning a string result take a (resultbuf, lengthp) argument
57 pair. If resultbuf is not NULL and the result fits into *lengthp units,
58 it is put in resultbuf, and resultbuf is returned. Otherwise, a freshly
59 allocated string is returned. In both cases, *lengthp is set to the
60 length (number of units) of the returned string. In case of error,
61 NULL is returned and errno is set. */
62
63
64/* Elementary string checks. */
65
66/* Check whether an UTF-8 string is well-formed.
67 Return NULL if valid, or a pointer to the first invalid unit otherwise. */
68extern const uint8_t *
69 u8_check (const uint8_t *s, size_t n);
70
71/* Check whether an UTF-16 string is well-formed.
72 Return NULL if valid, or a pointer to the first invalid unit otherwise. */
73extern const uint16_t *
74 u16_check (const uint16_t *s, size_t n);
75
76/* Check whether an UCS-4 string is well-formed.
77 Return NULL if valid, or a pointer to the first invalid unit otherwise. */
78extern const uint32_t *
79 u32_check (const uint32_t *s, size_t n);
80
81
82/* Elementary string conversions. */
83
84/* Convert an UTF-8 string to an UTF-16 string. */
85extern uint16_t *
86 u8_to_u16 (const uint8_t *s, size_t n, uint16_t *resultbuf,
1cd4fffc 87 size_t *lengthp);
24d56127
LC
88
89/* Convert an UTF-8 string to an UCS-4 string. */
90extern uint32_t *
91 u8_to_u32 (const uint8_t *s, size_t n, uint32_t *resultbuf,
1cd4fffc 92 size_t *lengthp);
24d56127
LC
93
94/* Convert an UTF-16 string to an UTF-8 string. */
95extern uint8_t *
96 u16_to_u8 (const uint16_t *s, size_t n, uint8_t *resultbuf,
1cd4fffc 97 size_t *lengthp);
24d56127
LC
98
99/* Convert an UTF-16 string to an UCS-4 string. */
100extern uint32_t *
101 u16_to_u32 (const uint16_t *s, size_t n, uint32_t *resultbuf,
1cd4fffc 102 size_t *lengthp);
24d56127
LC
103
104/* Convert an UCS-4 string to an UTF-8 string. */
105extern uint8_t *
106 u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf,
1cd4fffc 107 size_t *lengthp);
24d56127
LC
108
109/* Convert an UCS-4 string to an UTF-16 string. */
110extern uint16_t *
111 u32_to_u16 (const uint32_t *s, size_t n, uint16_t *resultbuf,
1cd4fffc 112 size_t *lengthp);
24d56127
LC
113
114
115/* Elementary string functions. */
116
117/* Return the length (number of units) of the first character in S, which is
118 no longer than N. Return 0 if it is the NUL character. Return -1 upon
119 failure. */
120/* Similar to mblen(), except that s must not be NULL. */
121extern int
122 u8_mblen (const uint8_t *s, size_t n);
123extern int
124 u16_mblen (const uint16_t *s, size_t n);
125extern int
126 u32_mblen (const uint32_t *s, size_t n);
127
128/* Return the length (number of units) of the first character in S, putting
129 its 'ucs4_t' representation in *PUC. Upon failure, *PUC is set to 0xfffd,
130 and an appropriate number of units is returned.
131 The number of available units, N, must be > 0. */
132/* Similar to mbtowc(), except that puc and s must not be NULL, n must be > 0,
133 and the NUL character is not treated specially. */
134/* The variants with _safe suffix are safe, even if the library is compiled
135 without --enable-safety. */
136
dd7d0148 137#if GNULIB_UNISTR_U8_MBTOUC_UNSAFE || HAVE_LIBUNISTRING
24d56127
LC
138# if !HAVE_INLINE
139extern int
140 u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n);
141# else
142extern int
143 u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n);
144static inline int
145u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n)
146{
147 uint8_t c = *s;
148
149 if (c < 0x80)
150 {
151 *puc = c;
152 return 1;
153 }
154 else
155 return u8_mbtouc_unsafe_aux (puc, s, n);
156}
157# endif
158#endif
159
dd7d0148 160#if GNULIB_UNISTR_U16_MBTOUC_UNSAFE || HAVE_LIBUNISTRING
24d56127
LC
161# if !HAVE_INLINE
162extern int
163 u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n);
164# else
165extern int
166 u16_mbtouc_unsafe_aux (ucs4_t *puc, const uint16_t *s, size_t n);
167static inline int
168u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n)
169{
170 uint16_t c = *s;
171
172 if (c < 0xd800 || c >= 0xe000)
173 {
174 *puc = c;
175 return 1;
176 }
177 else
178 return u16_mbtouc_unsafe_aux (puc, s, n);
179}
180# endif
181#endif
182
dd7d0148 183#if GNULIB_UNISTR_U32_MBTOUC_UNSAFE || HAVE_LIBUNISTRING
24d56127
LC
184# if !HAVE_INLINE
185extern int
186 u32_mbtouc_unsafe (ucs4_t *puc, const uint32_t *s, size_t n);
187# else
188static inline int
61cd9dc9
LC
189u32_mbtouc_unsafe (ucs4_t *puc,
190 const uint32_t *s, size_t n _GL_UNUSED_PARAMETER)
24d56127
LC
191{
192 uint32_t c = *s;
193
dd7d0148 194# if CONFIG_UNICODE_SAFETY
24d56127
LC
195 if (c < 0xd800 || (c >= 0xe000 && c < 0x110000))
196# endif
197 *puc = c;
dd7d0148 198# if CONFIG_UNICODE_SAFETY
24d56127
LC
199 else
200 /* invalid multibyte character */
201 *puc = 0xfffd;
202# endif
203 return 1;
204}
205# endif
206#endif
207
dd7d0148 208#if GNULIB_UNISTR_U8_MBTOUC || HAVE_LIBUNISTRING
24d56127
LC
209# if !HAVE_INLINE
210extern int
211 u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n);
212# else
213extern int
214 u8_mbtouc_aux (ucs4_t *puc, const uint8_t *s, size_t n);
215static inline int
216u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n)
217{
218 uint8_t c = *s;
219
220 if (c < 0x80)
221 {
222 *puc = c;
223 return 1;
224 }
225 else
226 return u8_mbtouc_aux (puc, s, n);
227}
228# endif
229#endif
230
dd7d0148 231#if GNULIB_UNISTR_U16_MBTOUC || HAVE_LIBUNISTRING
24d56127
LC
232# if !HAVE_INLINE
233extern int
234 u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n);
235# else
236extern int
237 u16_mbtouc_aux (ucs4_t *puc, const uint16_t *s, size_t n);
238static inline int
239u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n)
240{
241 uint16_t c = *s;
242
243 if (c < 0xd800 || c >= 0xe000)
244 {
245 *puc = c;
246 return 1;
247 }
248 else
249 return u16_mbtouc_aux (puc, s, n);
250}
251# endif
252#endif
253
dd7d0148 254#if GNULIB_UNISTR_U32_MBTOUC || HAVE_LIBUNISTRING
24d56127
LC
255# if !HAVE_INLINE
256extern int
257 u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n);
258# else
259static inline int
61cd9dc9 260u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n _GL_UNUSED_PARAMETER)
24d56127
LC
261{
262 uint32_t c = *s;
263
264 if (c < 0xd800 || (c >= 0xe000 && c < 0x110000))
265 *puc = c;
266 else
267 /* invalid multibyte character */
268 *puc = 0xfffd;
269 return 1;
270}
271# endif
272#endif
273
274/* Return the length (number of units) of the first character in S, putting
275 its 'ucs4_t' representation in *PUC. Upon failure, *PUC is set to 0xfffd,
276 and -1 is returned for an invalid sequence of units, -2 is returned for an
277 incomplete sequence of units.
278 The number of available units, N, must be > 0. */
279/* Similar to u*_mbtouc(), except that the return value gives more details
280 about the failure, similar to mbrtowc(). */
281
dd7d0148 282#if GNULIB_UNISTR_U8_MBTOUCR || HAVE_LIBUNISTRING
24d56127
LC
283extern int
284 u8_mbtoucr (ucs4_t *puc, const uint8_t *s, size_t n);
285#endif
286
dd7d0148 287#if GNULIB_UNISTR_U16_MBTOUCR || HAVE_LIBUNISTRING
24d56127
LC
288extern int
289 u16_mbtoucr (ucs4_t *puc, const uint16_t *s, size_t n);
290#endif
291
dd7d0148 292#if GNULIB_UNISTR_U32_MBTOUCR || HAVE_LIBUNISTRING
24d56127
LC
293extern int
294 u32_mbtoucr (ucs4_t *puc, const uint32_t *s, size_t n);
295#endif
296
297/* Put the multibyte character represented by UC in S, returning its
298 length. Return -1 upon failure, -2 if the number of available units, N,
299 is too small. The latter case cannot occur if N >= 6/2/1, respectively. */
300/* Similar to wctomb(), except that s must not be NULL, and the argument n
301 must be specified. */
302
dd7d0148 303#if GNULIB_UNISTR_U8_UCTOMB || HAVE_LIBUNISTRING
24d56127
LC
304/* Auxiliary function, also used by u8_chr, u8_strchr, u8_strrchr. */
305extern int
306 u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n);
307# if !HAVE_INLINE
308extern int
309 u8_uctomb (uint8_t *s, ucs4_t uc, int n);
310# else
311static inline int
312u8_uctomb (uint8_t *s, ucs4_t uc, int n)
313{
314 if (uc < 0x80 && n > 0)
315 {
316 s[0] = uc;
317 return 1;
318 }
319 else
320 return u8_uctomb_aux (s, uc, n);
321}
322# endif
323#endif
324
dd7d0148 325#if GNULIB_UNISTR_U16_UCTOMB || HAVE_LIBUNISTRING
24d56127
LC
326/* Auxiliary function, also used by u16_chr, u16_strchr, u16_strrchr. */
327extern int
328 u16_uctomb_aux (uint16_t *s, ucs4_t uc, int n);
329# if !HAVE_INLINE
330extern int
331 u16_uctomb (uint16_t *s, ucs4_t uc, int n);
332# else
333static inline int
334u16_uctomb (uint16_t *s, ucs4_t uc, int n)
335{
336 if (uc < 0xd800 && n > 0)
337 {
338 s[0] = uc;
339 return 1;
340 }
341 else
342 return u16_uctomb_aux (s, uc, n);
343}
344# endif
345#endif
346
dd7d0148 347#if GNULIB_UNISTR_U32_UCTOMB || HAVE_LIBUNISTRING
24d56127
LC
348# if !HAVE_INLINE
349extern int
350 u32_uctomb (uint32_t *s, ucs4_t uc, int n);
351# else
352static inline int
353u32_uctomb (uint32_t *s, ucs4_t uc, int n)
354{
355 if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000))
356 {
357 if (n > 0)
1cd4fffc
LC
358 {
359 *s = uc;
360 return 1;
361 }
24d56127 362 else
1cd4fffc 363 return -2;
24d56127
LC
364 }
365 else
366 return -1;
367}
368# endif
369#endif
370
371/* Copy N units from SRC to DEST. */
372/* Similar to memcpy(). */
373extern uint8_t *
374 u8_cpy (uint8_t *dest, const uint8_t *src, size_t n);
375extern uint16_t *
376 u16_cpy (uint16_t *dest, const uint16_t *src, size_t n);
377extern uint32_t *
378 u32_cpy (uint32_t *dest, const uint32_t *src, size_t n);
379
380/* Copy N units from SRC to DEST, guaranteeing correct behavior for
381 overlapping memory areas. */
382/* Similar to memmove(). */
383extern uint8_t *
384 u8_move (uint8_t *dest, const uint8_t *src, size_t n);
385extern uint16_t *
386 u16_move (uint16_t *dest, const uint16_t *src, size_t n);
387extern uint32_t *
388 u32_move (uint32_t *dest, const uint32_t *src, size_t n);
389
390/* Set the first N characters of S to UC. UC should be a character that
391 occupies only 1 unit. */
392/* Similar to memset(). */
393extern uint8_t *
394 u8_set (uint8_t *s, ucs4_t uc, size_t n);
395extern uint16_t *
396 u16_set (uint16_t *s, ucs4_t uc, size_t n);
397extern uint32_t *
398 u32_set (uint32_t *s, ucs4_t uc, size_t n);
399
400/* Compare S1 and S2, each of length N. */
401/* Similar to memcmp(). */
402extern int
403 u8_cmp (const uint8_t *s1, const uint8_t *s2, size_t n);
404extern int
405 u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n);
406extern int
407 u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n);
408
409/* Compare S1 and S2. */
410/* Similar to the gnulib function memcmp2(). */
411extern int
412 u8_cmp2 (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2);
413extern int
414 u16_cmp2 (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2);
415extern int
416 u32_cmp2 (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2);
417
418/* Search the string at S for UC. */
419/* Similar to memchr(). */
420extern uint8_t *
421 u8_chr (const uint8_t *s, size_t n, ucs4_t uc);
422extern uint16_t *
423 u16_chr (const uint16_t *s, size_t n, ucs4_t uc);
424extern uint32_t *
425 u32_chr (const uint32_t *s, size_t n, ucs4_t uc);
426
427/* Count the number of Unicode characters in the N units from S. */
428/* Similar to mbsnlen(). */
429extern size_t
430 u8_mbsnlen (const uint8_t *s, size_t n);
431extern size_t
432 u16_mbsnlen (const uint16_t *s, size_t n);
433extern size_t
434 u32_mbsnlen (const uint32_t *s, size_t n);
435
436/* Elementary string functions with memory allocation. */
437
438/* Make a freshly allocated copy of S, of length N. */
439extern uint8_t *
440 u8_cpy_alloc (const uint8_t *s, size_t n);
441extern uint16_t *
442 u16_cpy_alloc (const uint16_t *s, size_t n);
443extern uint32_t *
444 u32_cpy_alloc (const uint32_t *s, size_t n);
445
446/* Elementary string functions on NUL terminated strings. */
447
448/* Return the length (number of units) of the first character in S.
449 Return 0 if it is the NUL character. Return -1 upon failure. */
450extern int
451 u8_strmblen (const uint8_t *s);
452extern int
453 u16_strmblen (const uint16_t *s);
454extern int
455 u32_strmblen (const uint32_t *s);
456
457/* Return the length (number of units) of the first character in S, putting
458 its 'ucs4_t' representation in *PUC. Return 0 if it is the NUL
459 character. Return -1 upon failure. */
460extern int
461 u8_strmbtouc (ucs4_t *puc, const uint8_t *s);
462extern int
463 u16_strmbtouc (ucs4_t *puc, const uint16_t *s);
464extern int
465 u32_strmbtouc (ucs4_t *puc, const uint32_t *s);
466
467/* Forward iteration step. Advances the pointer past the next character,
468 or returns NULL if the end of the string has been reached. Puts the
469 character's 'ucs4_t' representation in *PUC. */
470extern const uint8_t *
471 u8_next (ucs4_t *puc, const uint8_t *s);
472extern const uint16_t *
473 u16_next (ucs4_t *puc, const uint16_t *s);
474extern const uint32_t *
475 u32_next (ucs4_t *puc, const uint32_t *s);
476
477/* Backward iteration step. Advances the pointer to point to the previous
478 character, or returns NULL if the beginning of the string had been reached.
479 Puts the character's 'ucs4_t' representation in *PUC. */
480extern const uint8_t *
481 u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start);
482extern const uint16_t *
483 u16_prev (ucs4_t *puc, const uint16_t *s, const uint16_t *start);
484extern const uint32_t *
485 u32_prev (ucs4_t *puc, const uint32_t *s, const uint32_t *start);
486
487/* Return the number of units in S. */
488/* Similar to strlen(), wcslen(). */
489extern size_t
490 u8_strlen (const uint8_t *s);
491extern size_t
492 u16_strlen (const uint16_t *s);
493extern size_t
494 u32_strlen (const uint32_t *s);
495
496/* Return the number of units in S, but at most MAXLEN. */
497/* Similar to strnlen(), wcsnlen(). */
498extern size_t
499 u8_strnlen (const uint8_t *s, size_t maxlen);
500extern size_t
501 u16_strnlen (const uint16_t *s, size_t maxlen);
502extern size_t
503 u32_strnlen (const uint32_t *s, size_t maxlen);
504
505/* Copy SRC to DEST. */
506/* Similar to strcpy(), wcscpy(). */
507extern uint8_t *
508 u8_strcpy (uint8_t *dest, const uint8_t *src);
509extern uint16_t *
510 u16_strcpy (uint16_t *dest, const uint16_t *src);
511extern uint32_t *
512 u32_strcpy (uint32_t *dest, const uint32_t *src);
513
514/* Copy SRC to DEST, returning the address of the terminating NUL in DEST. */
515/* Similar to stpcpy(). */
516extern uint8_t *
517 u8_stpcpy (uint8_t *dest, const uint8_t *src);
518extern uint16_t *
519 u16_stpcpy (uint16_t *dest, const uint16_t *src);
520extern uint32_t *
521 u32_stpcpy (uint32_t *dest, const uint32_t *src);
522
523/* Copy no more than N units of SRC to DEST. */
524/* Similar to strncpy(), wcsncpy(). */
525extern uint8_t *
526 u8_strncpy (uint8_t *dest, const uint8_t *src, size_t n);
527extern uint16_t *
528 u16_strncpy (uint16_t *dest, const uint16_t *src, size_t n);
529extern uint32_t *
530 u32_strncpy (uint32_t *dest, const uint32_t *src, size_t n);
531
61cd9dc9
LC
532/* Copy no more than N units of SRC to DEST. Return a pointer past the last
533 non-NUL unit written into DEST. */
24d56127
LC
534/* Similar to stpncpy(). */
535extern uint8_t *
536 u8_stpncpy (uint8_t *dest, const uint8_t *src, size_t n);
537extern uint16_t *
538 u16_stpncpy (uint16_t *dest, const uint16_t *src, size_t n);
539extern uint32_t *
540 u32_stpncpy (uint32_t *dest, const uint32_t *src, size_t n);
541
542/* Append SRC onto DEST. */
543/* Similar to strcat(), wcscat(). */
544extern uint8_t *
545 u8_strcat (uint8_t *dest, const uint8_t *src);
546extern uint16_t *
547 u16_strcat (uint16_t *dest, const uint16_t *src);
548extern uint32_t *
549 u32_strcat (uint32_t *dest, const uint32_t *src);
550
551/* Append no more than N units of SRC onto DEST. */
552/* Similar to strncat(), wcsncat(). */
553extern uint8_t *
554 u8_strncat (uint8_t *dest, const uint8_t *src, size_t n);
555extern uint16_t *
556 u16_strncat (uint16_t *dest, const uint16_t *src, size_t n);
557extern uint32_t *
558 u32_strncat (uint32_t *dest, const uint32_t *src, size_t n);
559
560/* Compare S1 and S2. */
561/* Similar to strcmp(), wcscmp(). */
0f00f2c3
LC
562#ifdef __sun
563/* Avoid a collision with the u8_strcmp() function in Solaris 11 libc. */
564extern int
565 u8_strcmp_gnu (const uint8_t *s1, const uint8_t *s2);
566# define u8_strcmp u8_strcmp_gnu
567#else
24d56127
LC
568extern int
569 u8_strcmp (const uint8_t *s1, const uint8_t *s2);
0f00f2c3 570#endif
24d56127
LC
571extern int
572 u16_strcmp (const uint16_t *s1, const uint16_t *s2);
573extern int
574 u32_strcmp (const uint32_t *s1, const uint32_t *s2);
575
576/* Compare S1 and S2 using the collation rules of the current locale.
577 Return -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2.
578 Upon failure, set errno and return any value. */
579/* Similar to strcoll(), wcscoll(). */
580extern int
581 u8_strcoll (const uint8_t *s1, const uint8_t *s2);
582extern int
583 u16_strcoll (const uint16_t *s1, const uint16_t *s2);
584extern int
585 u32_strcoll (const uint32_t *s1, const uint32_t *s2);
586
587/* Compare no more than N units of S1 and S2. */
588/* Similar to strncmp(), wcsncmp(). */
589extern int
590 u8_strncmp (const uint8_t *s1, const uint8_t *s2, size_t n);
591extern int
592 u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n);
593extern int
594 u32_strncmp (const uint32_t *s1, const uint32_t *s2, size_t n);
595
596/* Duplicate S, returning an identical malloc'd string. */
597/* Similar to strdup(), wcsdup(). */
598extern uint8_t *
599 u8_strdup (const uint8_t *s);
600extern uint16_t *
601 u16_strdup (const uint16_t *s);
602extern uint32_t *
603 u32_strdup (const uint32_t *s);
604
605/* Find the first occurrence of UC in STR. */
606/* Similar to strchr(), wcschr(). */
607extern uint8_t *
608 u8_strchr (const uint8_t *str, ucs4_t uc);
609extern uint16_t *
610 u16_strchr (const uint16_t *str, ucs4_t uc);
611extern uint32_t *
612 u32_strchr (const uint32_t *str, ucs4_t uc);
613
614/* Find the last occurrence of UC in STR. */
615/* Similar to strrchr(), wcsrchr(). */
616extern uint8_t *
617 u8_strrchr (const uint8_t *str, ucs4_t uc);
618extern uint16_t *
619 u16_strrchr (const uint16_t *str, ucs4_t uc);
620extern uint32_t *
621 u32_strrchr (const uint32_t *str, ucs4_t uc);
622
623/* Return the length of the initial segment of STR which consists entirely
624 of Unicode characters not in REJECT. */
625/* Similar to strcspn(), wcscspn(). */
626extern size_t
627 u8_strcspn (const uint8_t *str, const uint8_t *reject);
628extern size_t
629 u16_strcspn (const uint16_t *str, const uint16_t *reject);
630extern size_t
631 u32_strcspn (const uint32_t *str, const uint32_t *reject);
632
633/* Return the length of the initial segment of STR which consists entirely
634 of Unicode characters in ACCEPT. */
635/* Similar to strspn(), wcsspn(). */
636extern size_t
637 u8_strspn (const uint8_t *str, const uint8_t *accept);
638extern size_t
639 u16_strspn (const uint16_t *str, const uint16_t *accept);
640extern size_t
641 u32_strspn (const uint32_t *str, const uint32_t *accept);
642
643/* Find the first occurrence in STR of any character in ACCEPT. */
644/* Similar to strpbrk(), wcspbrk(). */
645extern uint8_t *
646 u8_strpbrk (const uint8_t *str, const uint8_t *accept);
647extern uint16_t *
648 u16_strpbrk (const uint16_t *str, const uint16_t *accept);
649extern uint32_t *
650 u32_strpbrk (const uint32_t *str, const uint32_t *accept);
651
652/* Find the first occurrence of NEEDLE in HAYSTACK. */
653/* Similar to strstr(), wcsstr(). */
654extern uint8_t *
655 u8_strstr (const uint8_t *haystack, const uint8_t *needle);
656extern uint16_t *
657 u16_strstr (const uint16_t *haystack, const uint16_t *needle);
658extern uint32_t *
659 u32_strstr (const uint32_t *haystack, const uint32_t *needle);
660
661/* Test whether STR starts with PREFIX. */
662extern bool
663 u8_startswith (const uint8_t *str, const uint8_t *prefix);
664extern bool
665 u16_startswith (const uint16_t *str, const uint16_t *prefix);
666extern bool
667 u32_startswith (const uint32_t *str, const uint32_t *prefix);
668
669/* Test whether STR ends with SUFFIX. */
670extern bool
671 u8_endswith (const uint8_t *str, const uint8_t *suffix);
672extern bool
673 u16_endswith (const uint16_t *str, const uint16_t *suffix);
674extern bool
675 u32_endswith (const uint32_t *str, const uint32_t *suffix);
676
677/* Divide STR into tokens separated by characters in DELIM.
678 This interface is actually more similar to wcstok than to strtok. */
679/* Similar to strtok_r(), wcstok(). */
680extern uint8_t *
681 u8_strtok (uint8_t *str, const uint8_t *delim, uint8_t **ptr);
682extern uint16_t *
683 u16_strtok (uint16_t *str, const uint16_t *delim, uint16_t **ptr);
684extern uint32_t *
685 u32_strtok (uint32_t *str, const uint32_t *delim, uint32_t **ptr);
686
687
688#ifdef __cplusplus
689}
690#endif
691
692#endif /* _UNISTR_H */