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