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