Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:30:29

0001 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
0002 /* Elementary Unicode string functions.
0003    Copyright (C) 2001-2002, 2005-2022 Free Software Foundation, Inc.
0004 
0005    This file is free software: you can redistribute it and/or modify
0006    it under the terms of the GNU Lesser General Public License as
0007    published by the Free Software Foundation; either version 2.1 of the
0008    License, or (at your option) any later version.
0009 
0010    This file is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013    GNU Lesser General Public License for more details.
0014 
0015    You should have received a copy of the GNU Lesser General Public License
0016    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
0017 
0018 #ifndef _UNISTR_H
0019 #define _UNISTR_H
0020 
0021 #include "unitypes.h"
0022 
0023 /* Get common macros for C.  */
0024 #include <unistring/cdefs.h>
0025 
0026 /* Get inline if available.  */
0027 #include <unistring/inline.h>
0028 
0029 /* Get bool.  */
0030 #include <unistring/stdbool.h>
0031 
0032 /* Get size_t, ptrdiff_t.  */
0033 #include <stddef.h>
0034 
0035 /* Get free().  */
0036 #include <stdlib.h>
0037 
0038 #ifdef __cplusplus
0039 extern "C" {
0040 #endif
0041 
0042 
0043 /* Conventions:
0044 
0045    All functions prefixed with u8_ operate on UTF-8 encoded strings.
0046    Their unit is an uint8_t (1 byte).
0047 
0048    All functions prefixed with u16_ operate on UTF-16 encoded strings.
0049    Their unit is an uint16_t (a 2-byte word).
0050 
0051    All functions prefixed with u32_ operate on UCS-4 encoded strings.
0052    Their unit is an uint32_t (a 4-byte word).
0053 
0054    All argument pairs (s, n) denote a Unicode string s[0..n-1] with exactly
0055    n units.
0056 
0057    All arguments starting with "str" and the arguments of functions starting
0058    with u8_str/u16_str/u32_str denote a NUL terminated string, i.e. a string
0059    which terminates at the first NUL unit.  This termination unit is
0060    considered part of the string for all memory allocation purposes, but
0061    is not considered part of the string for all other logical purposes.
0062 
0063    Functions returning a string result take a (resultbuf, lengthp) argument
0064    pair.  If resultbuf is not NULL and the result fits into *lengthp units,
0065    it is put in resultbuf, and resultbuf is returned.  Otherwise, a freshly
0066    allocated string is returned.  In both cases, *lengthp is set to the
0067    length (number of units) of the returned string.  In case of error,
0068    NULL is returned and errno is set.  */
0069 
0070 
0071 /* Elementary string checks.  */
0072 
0073 /* Check whether an UTF-8 string is well-formed.
0074    Return NULL if valid, or a pointer to the first invalid unit otherwise.  */
0075 extern const uint8_t *
0076        u8_check (const uint8_t *s, size_t n)
0077        _UC_ATTRIBUTE_PURE;
0078 
0079 /* Check whether an UTF-16 string is well-formed.
0080    Return NULL if valid, or a pointer to the first invalid unit otherwise.  */
0081 extern const uint16_t *
0082        u16_check (const uint16_t *s, size_t n)
0083        _UC_ATTRIBUTE_PURE;
0084 
0085 /* Check whether an UCS-4 string is well-formed.
0086    Return NULL if valid, or a pointer to the first invalid unit otherwise.  */
0087 extern const uint32_t *
0088        u32_check (const uint32_t *s, size_t n)
0089        _UC_ATTRIBUTE_PURE;
0090 
0091 
0092 /* Elementary string conversions.  */
0093 
0094 /* Convert an UTF-8 string to an UTF-16 string.  */
0095 extern uint16_t *
0096        u8_to_u16 (const uint8_t *s, size_t n, uint16_t *resultbuf,
0097                   size_t *lengthp);
0098 
0099 /* Convert an UTF-8 string to an UCS-4 string.  */
0100 extern uint32_t *
0101        u8_to_u32 (const uint8_t *s, size_t n, uint32_t *resultbuf,
0102                   size_t *lengthp);
0103 
0104 /* Convert an UTF-16 string to an UTF-8 string.  */
0105 extern uint8_t *
0106        u16_to_u8 (const uint16_t *s, size_t n, uint8_t *resultbuf,
0107                   size_t *lengthp);
0108 
0109 /* Convert an UTF-16 string to an UCS-4 string.  */
0110 extern uint32_t *
0111        u16_to_u32 (const uint16_t *s, size_t n, uint32_t *resultbuf,
0112                    size_t *lengthp);
0113 
0114 /* Convert an UCS-4 string to an UTF-8 string.  */
0115 extern uint8_t *
0116        u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf,
0117                   size_t *lengthp);
0118 
0119 /* Convert an UCS-4 string to an UTF-16 string.  */
0120 extern uint16_t *
0121        u32_to_u16 (const uint32_t *s, size_t n, uint16_t *resultbuf,
0122                    size_t *lengthp);
0123 
0124 
0125 /* Elementary string functions.  */
0126 
0127 /* Return the length (number of units) of the first character in S, which is
0128    no longer than N.  Return 0 if it is the NUL character.  Return -1 upon
0129    failure.  */
0130 /* Similar to mblen(), except that s must not be NULL.  */
0131 extern int
0132        u8_mblen (const uint8_t *s, size_t n)
0133        _UC_ATTRIBUTE_PURE;
0134 extern int
0135        u16_mblen (const uint16_t *s, size_t n)
0136        _UC_ATTRIBUTE_PURE;
0137 extern int
0138        u32_mblen (const uint32_t *s, size_t n)
0139        _UC_ATTRIBUTE_PURE;
0140 
0141 /* Return the length (number of units) of the first character in S, putting
0142    its 'ucs4_t' representation in *PUC.  Upon failure, *PUC is set to 0xfffd,
0143    and an appropriate number of units is returned.
0144    The number of available units, N, must be > 0.  */
0145 /* Similar to mbtowc(), except that puc and s must not be NULL, n must be > 0,
0146    and the NUL character is not treated specially.  */
0147 /* The variants with _unsafe suffix are for backward compatibility with
0148    libunistring versions < 0.9.7.  */
0149 
0150 #if 1
0151 # if !UNISTRING_HAVE_INLINE
0152 extern int
0153        u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n);
0154 # else
0155 extern int
0156        u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n);
0157 static inline int
0158 u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n)
0159 {
0160   uint8_t c = *s;
0161 
0162   if (c < 0x80)
0163     {
0164       *puc = c;
0165       return 1;
0166     }
0167   else
0168     return u8_mbtouc_unsafe_aux (puc, s, n);
0169 }
0170 # endif
0171 #endif
0172 
0173 #if 1
0174 # if !UNISTRING_HAVE_INLINE
0175 extern int
0176        u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n);
0177 # else
0178 extern int
0179        u16_mbtouc_unsafe_aux (ucs4_t *puc, const uint16_t *s, size_t n);
0180 static inline int
0181 u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n)
0182 {
0183   uint16_t c = *s;
0184 
0185   if (c < 0xd800 || c >= 0xe000)
0186     {
0187       *puc = c;
0188       return 1;
0189     }
0190   else
0191     return u16_mbtouc_unsafe_aux (puc, s, n);
0192 }
0193 # endif
0194 #endif
0195 
0196 #if 1
0197 # if !UNISTRING_HAVE_INLINE
0198 extern int
0199        u32_mbtouc_unsafe (ucs4_t *puc, const uint32_t *s, size_t n);
0200 # else
0201 static inline int
0202 u32_mbtouc_unsafe (ucs4_t *puc,
0203                    const uint32_t *s, _GL_ATTRIBUTE_MAYBE_UNUSED size_t n)
0204 {
0205   uint32_t c = *s;
0206 
0207   if (c < 0xd800 || (c >= 0xe000 && c < 0x110000))
0208     *puc = c;
0209   else
0210     /* invalid multibyte character */
0211     *puc = 0xfffd;
0212   return 1;
0213 }
0214 # endif
0215 #endif
0216 
0217 #if 1
0218 # if !UNISTRING_HAVE_INLINE
0219 extern int
0220        u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n);
0221 # else
0222 extern int
0223        u8_mbtouc_aux (ucs4_t *puc, const uint8_t *s, size_t n);
0224 static inline int
0225 u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n)
0226 {
0227   uint8_t c = *s;
0228 
0229   if (c < 0x80)
0230     {
0231       *puc = c;
0232       return 1;
0233     }
0234   else
0235     return u8_mbtouc_aux (puc, s, n);
0236 }
0237 # endif
0238 #endif
0239 
0240 #if 1
0241 # if !UNISTRING_HAVE_INLINE
0242 extern int
0243        u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n);
0244 # else
0245 extern int
0246        u16_mbtouc_aux (ucs4_t *puc, const uint16_t *s, size_t n);
0247 static inline int
0248 u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n)
0249 {
0250   uint16_t c = *s;
0251 
0252   if (c < 0xd800 || c >= 0xe000)
0253     {
0254       *puc = c;
0255       return 1;
0256     }
0257   else
0258     return u16_mbtouc_aux (puc, s, n);
0259 }
0260 # endif
0261 #endif
0262 
0263 #if 1
0264 # if !UNISTRING_HAVE_INLINE
0265 extern int
0266        u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n);
0267 # else
0268 static inline int
0269 u32_mbtouc (ucs4_t *puc, const uint32_t *s,
0270             _GL_ATTRIBUTE_MAYBE_UNUSED size_t n)
0271 {
0272   uint32_t c = *s;
0273 
0274   if (c < 0xd800 || (c >= 0xe000 && c < 0x110000))
0275     *puc = c;
0276   else
0277     /* invalid multibyte character */
0278     *puc = 0xfffd;
0279   return 1;
0280 }
0281 # endif
0282 #endif
0283 
0284 /* Return the length (number of units) of the first character in S, putting
0285    its 'ucs4_t' representation in *PUC.  Upon failure, *PUC is set to 0xfffd,
0286    and -1 is returned for an invalid sequence of units, -2 is returned for an
0287    incomplete sequence of units.
0288    The number of available units, N, must be > 0.  */
0289 /* Similar to u*_mbtouc(), except that the return value gives more details
0290    about the failure, similar to mbrtowc().  */
0291 
0292 #if 1
0293 extern int
0294        u8_mbtoucr (ucs4_t *puc, const uint8_t *s, size_t n);
0295 #endif
0296 
0297 #if 1
0298 extern int
0299        u16_mbtoucr (ucs4_t *puc, const uint16_t *s, size_t n);
0300 #endif
0301 
0302 #if 1
0303 extern int
0304        u32_mbtoucr (ucs4_t *puc, const uint32_t *s, size_t n);
0305 #endif
0306 
0307 /* Put the multibyte character represented by UC in S, returning its
0308    length.  Return -1 upon failure, -2 if the number of available units, N,
0309    is too small.  The latter case cannot occur if N >= 6/2/1, respectively.  */
0310 /* Similar to wctomb(), except that s must not be NULL, and the argument n
0311    must be specified.  */
0312 
0313 #if 1
0314 /* Auxiliary function, also used by u8_chr, u8_strchr, u8_strrchr.  */
0315 extern int
0316        u8_uctomb_aux (uint8_t *s, ucs4_t uc, ptrdiff_t n);
0317 # if !UNISTRING_HAVE_INLINE
0318 extern int
0319        u8_uctomb (uint8_t *s, ucs4_t uc, ptrdiff_t n);
0320 # else
0321 static inline int
0322 u8_uctomb (uint8_t *s, ucs4_t uc, ptrdiff_t n)
0323 {
0324   if (uc < 0x80 && n > 0)
0325     {
0326       s[0] = uc;
0327       return 1;
0328     }
0329   else
0330     return u8_uctomb_aux (s, uc, n);
0331 }
0332 # endif
0333 #endif
0334 
0335 #if 1
0336 /* Auxiliary function, also used by u16_chr, u16_strchr, u16_strrchr.  */
0337 extern int
0338        u16_uctomb_aux (uint16_t *s, ucs4_t uc, ptrdiff_t n);
0339 # if !UNISTRING_HAVE_INLINE
0340 extern int
0341        u16_uctomb (uint16_t *s, ucs4_t uc, ptrdiff_t n);
0342 # else
0343 static inline int
0344 u16_uctomb (uint16_t *s, ucs4_t uc, ptrdiff_t n)
0345 {
0346   if (uc < 0xd800 && n > 0)
0347     {
0348       s[0] = uc;
0349       return 1;
0350     }
0351   else
0352     return u16_uctomb_aux (s, uc, n);
0353 }
0354 # endif
0355 #endif
0356 
0357 #if 1
0358 # if !UNISTRING_HAVE_INLINE
0359 extern int
0360        u32_uctomb (uint32_t *s, ucs4_t uc, ptrdiff_t n);
0361 # else
0362 static inline int
0363 u32_uctomb (uint32_t *s, ucs4_t uc, ptrdiff_t n)
0364 {
0365   if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000))
0366     {
0367       if (n > 0)
0368         {
0369           *s = uc;
0370           return 1;
0371         }
0372       else
0373         return -2;
0374     }
0375   else
0376     return -1;
0377 }
0378 # endif
0379 #endif
0380 
0381 /* Copy N units from SRC to DEST.  */
0382 /* Similar to memcpy().  */
0383 extern uint8_t *
0384        u8_cpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src, size_t n);
0385 extern uint16_t *
0386        u16_cpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src, size_t n);
0387 extern uint32_t *
0388        u32_cpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src, size_t n);
0389 
0390 /* Copy N units from SRC to DEST, guaranteeing correct behavior for
0391    overlapping memory areas.  */
0392 /* Similar to memmove().  */
0393 extern uint8_t *
0394        u8_move (uint8_t *dest, const uint8_t *src, size_t n);
0395 extern uint16_t *
0396        u16_move (uint16_t *dest, const uint16_t *src, size_t n);
0397 extern uint32_t *
0398        u32_move (uint32_t *dest, const uint32_t *src, size_t n);
0399 
0400 /* Set the first N characters of S to UC.  UC should be a character that
0401    occupies only 1 unit.  */
0402 /* Similar to memset().  */
0403 extern uint8_t *
0404        u8_set (uint8_t *s, ucs4_t uc, size_t n);
0405 extern uint16_t *
0406        u16_set (uint16_t *s, ucs4_t uc, size_t n);
0407 extern uint32_t *
0408        u32_set (uint32_t *s, ucs4_t uc, size_t n);
0409 
0410 /* Compare S1 and S2, each of length N.  */
0411 /* Similar to memcmp().  */
0412 extern int
0413        u8_cmp (const uint8_t *s1, const uint8_t *s2, size_t n)
0414        _UC_ATTRIBUTE_PURE;
0415 extern int
0416        u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n)
0417        _UC_ATTRIBUTE_PURE;
0418 extern int
0419        u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n)
0420        _UC_ATTRIBUTE_PURE;
0421 
0422 /* Compare S1 and S2.  */
0423 /* Similar to the gnulib function memcmp2().  */
0424 extern int
0425        u8_cmp2 (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2)
0426        _UC_ATTRIBUTE_PURE;
0427 extern int
0428        u16_cmp2 (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2)
0429        _UC_ATTRIBUTE_PURE;
0430 extern int
0431        u32_cmp2 (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2)
0432        _UC_ATTRIBUTE_PURE;
0433 
0434 /* Search the string at S for UC.  */
0435 /* Similar to memchr().  */
0436 extern uint8_t *
0437        u8_chr (const uint8_t *s, size_t n, ucs4_t uc)
0438        _UC_ATTRIBUTE_PURE;
0439 extern uint16_t *
0440        u16_chr (const uint16_t *s, size_t n, ucs4_t uc)
0441        _UC_ATTRIBUTE_PURE;
0442 extern uint32_t *
0443        u32_chr (const uint32_t *s, size_t n, ucs4_t uc)
0444        _UC_ATTRIBUTE_PURE;
0445 
0446 /* Count the number of Unicode characters in the N units from S.  */
0447 /* Similar to mbsnlen().  */
0448 extern size_t
0449        u8_mbsnlen (const uint8_t *s, size_t n)
0450        _UC_ATTRIBUTE_PURE;
0451 extern size_t
0452        u16_mbsnlen (const uint16_t *s, size_t n)
0453        _UC_ATTRIBUTE_PURE;
0454 extern size_t
0455        u32_mbsnlen (const uint32_t *s, size_t n)
0456        _UC_ATTRIBUTE_PURE;
0457 
0458 /* Elementary string functions with memory allocation.  */
0459 
0460 /* Make a freshly allocated copy of S, of length N.  */
0461 extern uint8_t *
0462        u8_cpy_alloc (const uint8_t *s, size_t n);
0463 extern uint16_t *
0464        u16_cpy_alloc (const uint16_t *s, size_t n);
0465 extern uint32_t *
0466        u32_cpy_alloc (const uint32_t *s, size_t n);
0467 
0468 /* Elementary string functions on NUL terminated strings.  */
0469 
0470 /* Return the length (number of units) of the first character in S.
0471    Return 0 if it is the NUL character.  Return -1 upon failure.  */
0472 extern int
0473        u8_strmblen (const uint8_t *s)
0474        _UC_ATTRIBUTE_PURE;
0475 extern int
0476        u16_strmblen (const uint16_t *s)
0477        _UC_ATTRIBUTE_PURE;
0478 extern int
0479        u32_strmblen (const uint32_t *s)
0480        _UC_ATTRIBUTE_PURE;
0481 
0482 /* Return the length (number of units) of the first character in S, putting
0483    its 'ucs4_t' representation in *PUC.  Return 0 if it is the NUL
0484    character.  Return -1 upon failure.  */
0485 extern int
0486        u8_strmbtouc (ucs4_t *puc, const uint8_t *s);
0487 extern int
0488        u16_strmbtouc (ucs4_t *puc, const uint16_t *s);
0489 extern int
0490        u32_strmbtouc (ucs4_t *puc, const uint32_t *s);
0491 
0492 /* Forward iteration step.  Advances the pointer past the next character,
0493    or returns NULL if the end of the string has been reached.  Puts the
0494    character's 'ucs4_t' representation in *PUC.  */
0495 extern const uint8_t *
0496        u8_next (ucs4_t *puc, const uint8_t *s);
0497 extern const uint16_t *
0498        u16_next (ucs4_t *puc, const uint16_t *s);
0499 extern const uint32_t *
0500        u32_next (ucs4_t *puc, const uint32_t *s);
0501 
0502 /* Backward iteration step.  Advances the pointer to point to the previous
0503    character, or returns NULL if the beginning of the string had been reached.
0504    Puts the character's 'ucs4_t' representation in *PUC.  */
0505 extern const uint8_t *
0506        u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start);
0507 extern const uint16_t *
0508        u16_prev (ucs4_t *puc, const uint16_t *s, const uint16_t *start);
0509 extern const uint32_t *
0510        u32_prev (ucs4_t *puc, const uint32_t *s, const uint32_t *start);
0511 
0512 /* Return the number of units in S.  */
0513 /* Similar to strlen(), wcslen().  */
0514 extern size_t
0515        u8_strlen (const uint8_t *s)
0516        _UC_ATTRIBUTE_PURE;
0517 extern size_t
0518        u16_strlen (const uint16_t *s)
0519        _UC_ATTRIBUTE_PURE;
0520 extern size_t
0521        u32_strlen (const uint32_t *s)
0522        _UC_ATTRIBUTE_PURE;
0523 
0524 /* Return the number of units in S, but at most MAXLEN.  */
0525 /* Similar to strnlen(), wcsnlen().  */
0526 extern size_t
0527        u8_strnlen (const uint8_t *s, size_t maxlen)
0528        _UC_ATTRIBUTE_PURE;
0529 extern size_t
0530        u16_strnlen (const uint16_t *s, size_t maxlen)
0531        _UC_ATTRIBUTE_PURE;
0532 extern size_t
0533        u32_strnlen (const uint32_t *s, size_t maxlen)
0534        _UC_ATTRIBUTE_PURE;
0535 
0536 /* Copy SRC to DEST.  */
0537 /* Similar to strcpy(), wcscpy().  */
0538 extern uint8_t *
0539        u8_strcpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src);
0540 extern uint16_t *
0541        u16_strcpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src);
0542 extern uint32_t *
0543        u32_strcpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src);
0544 
0545 /* Copy SRC to DEST, returning the address of the terminating NUL in DEST.  */
0546 /* Similar to stpcpy().  */
0547 extern uint8_t *
0548        u8_stpcpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src);
0549 extern uint16_t *
0550        u16_stpcpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src);
0551 extern uint32_t *
0552        u32_stpcpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src);
0553 
0554 /* Copy no more than N units of SRC to DEST.  */
0555 /* Similar to strncpy(), wcsncpy().  */
0556 extern uint8_t *
0557        u8_strncpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src, size_t n);
0558 extern uint16_t *
0559        u16_strncpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src, size_t n);
0560 extern uint32_t *
0561        u32_strncpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src, size_t n);
0562 
0563 /* Copy no more than N units of SRC to DEST.  Return a pointer past the last
0564    non-NUL unit written into DEST.  */
0565 /* Similar to stpncpy().  */
0566 extern uint8_t *
0567        u8_stpncpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src, size_t n);
0568 extern uint16_t *
0569        u16_stpncpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src, size_t n);
0570 extern uint32_t *
0571        u32_stpncpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src, size_t n);
0572 
0573 /* Append SRC onto DEST.  */
0574 /* Similar to strcat(), wcscat().  */
0575 extern uint8_t *
0576        u8_strcat (uint8_t *_UC_RESTRICT dest, const uint8_t *src);
0577 extern uint16_t *
0578        u16_strcat (uint16_t *_UC_RESTRICT dest, const uint16_t *src);
0579 extern uint32_t *
0580        u32_strcat (uint32_t *_UC_RESTRICT dest, const uint32_t *src);
0581 
0582 /* Append no more than N units of SRC onto DEST.  */
0583 /* Similar to strncat(), wcsncat().  */
0584 extern uint8_t *
0585        u8_strncat (uint8_t *_UC_RESTRICT dest, const uint8_t *src, size_t n);
0586 extern uint16_t *
0587        u16_strncat (uint16_t *_UC_RESTRICT dest, const uint16_t *src, size_t n);
0588 extern uint32_t *
0589        u32_strncat (uint32_t *_UC_RESTRICT dest, const uint32_t *src, size_t n);
0590 
0591 /* Compare S1 and S2.  */
0592 /* Similar to strcmp(), wcscmp().  */
0593 #ifdef __sun
0594 /* Avoid a collision with the u8_strcmp() function in Solaris 11 libc.  */
0595 extern int
0596        u8_strcmp_gnu (const uint8_t *s1, const uint8_t *s2)
0597        _UC_ATTRIBUTE_PURE;
0598 # define u8_strcmp u8_strcmp_gnu
0599 #else
0600 extern int
0601        u8_strcmp (const uint8_t *s1, const uint8_t *s2)
0602        _UC_ATTRIBUTE_PURE;
0603 #endif
0604 extern int
0605        u16_strcmp (const uint16_t *s1, const uint16_t *s2)
0606        _UC_ATTRIBUTE_PURE;
0607 extern int
0608        u32_strcmp (const uint32_t *s1, const uint32_t *s2)
0609        _UC_ATTRIBUTE_PURE;
0610 
0611 /* Compare S1 and S2 using the collation rules of the current locale.
0612    Return -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2.
0613    Upon failure, set errno and return any value.  */
0614 /* Similar to strcoll(), wcscoll().  */
0615 extern int
0616        u8_strcoll (const uint8_t *s1, const uint8_t *s2);
0617 extern int
0618        u16_strcoll (const uint16_t *s1, const uint16_t *s2);
0619 extern int
0620        u32_strcoll (const uint32_t *s1, const uint32_t *s2);
0621 
0622 /* Compare no more than N units of S1 and S2.  */
0623 /* Similar to strncmp(), wcsncmp().  */
0624 extern int
0625        u8_strncmp (const uint8_t *s1, const uint8_t *s2, size_t n)
0626        _UC_ATTRIBUTE_PURE;
0627 extern int
0628        u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n)
0629        _UC_ATTRIBUTE_PURE;
0630 extern int
0631        u32_strncmp (const uint32_t *s1, const uint32_t *s2, size_t n)
0632        _UC_ATTRIBUTE_PURE;
0633 
0634 /* Duplicate S, returning an identical malloc'd string.  */
0635 /* Similar to strdup(), wcsdup().  */
0636 extern uint8_t *
0637        u8_strdup (const uint8_t *s)
0638        _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
0639 extern uint16_t *
0640        u16_strdup (const uint16_t *s)
0641        _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
0642 extern uint32_t *
0643        u32_strdup (const uint32_t *s)
0644        _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
0645 
0646 /* Find the first occurrence of UC in STR.  */
0647 /* Similar to strchr(), wcschr().  */
0648 extern uint8_t *
0649        u8_strchr (const uint8_t *str, ucs4_t uc)
0650        _UC_ATTRIBUTE_PURE;
0651 extern uint16_t *
0652        u16_strchr (const uint16_t *str, ucs4_t uc)
0653        _UC_ATTRIBUTE_PURE;
0654 extern uint32_t *
0655        u32_strchr (const uint32_t *str, ucs4_t uc)
0656        _UC_ATTRIBUTE_PURE;
0657 
0658 /* Find the last occurrence of UC in STR.  */
0659 /* Similar to strrchr(), wcsrchr().  */
0660 extern uint8_t *
0661        u8_strrchr (const uint8_t *str, ucs4_t uc)
0662        _UC_ATTRIBUTE_PURE;
0663 extern uint16_t *
0664        u16_strrchr (const uint16_t *str, ucs4_t uc)
0665        _UC_ATTRIBUTE_PURE;
0666 extern uint32_t *
0667        u32_strrchr (const uint32_t *str, ucs4_t uc)
0668        _UC_ATTRIBUTE_PURE;
0669 
0670 /* Return the length of the initial segment of STR which consists entirely
0671    of Unicode characters not in REJECT.  */
0672 /* Similar to strcspn(), wcscspn().  */
0673 extern size_t
0674        u8_strcspn (const uint8_t *str, const uint8_t *reject)
0675        _UC_ATTRIBUTE_PURE;
0676 extern size_t
0677        u16_strcspn (const uint16_t *str, const uint16_t *reject)
0678        _UC_ATTRIBUTE_PURE;
0679 extern size_t
0680        u32_strcspn (const uint32_t *str, const uint32_t *reject)
0681        _UC_ATTRIBUTE_PURE;
0682 
0683 /* Return the length of the initial segment of STR which consists entirely
0684    of Unicode characters in ACCEPT.  */
0685 /* Similar to strspn(), wcsspn().  */
0686 extern size_t
0687        u8_strspn (const uint8_t *str, const uint8_t *accept)
0688        _UC_ATTRIBUTE_PURE;
0689 extern size_t
0690        u16_strspn (const uint16_t *str, const uint16_t *accept)
0691        _UC_ATTRIBUTE_PURE;
0692 extern size_t
0693        u32_strspn (const uint32_t *str, const uint32_t *accept)
0694        _UC_ATTRIBUTE_PURE;
0695 
0696 /* Find the first occurrence in STR of any character in ACCEPT.  */
0697 /* Similar to strpbrk(), wcspbrk().  */
0698 extern uint8_t *
0699        u8_strpbrk (const uint8_t *str, const uint8_t *accept)
0700        _UC_ATTRIBUTE_PURE;
0701 extern uint16_t *
0702        u16_strpbrk (const uint16_t *str, const uint16_t *accept)
0703        _UC_ATTRIBUTE_PURE;
0704 extern uint32_t *
0705        u32_strpbrk (const uint32_t *str, const uint32_t *accept)
0706        _UC_ATTRIBUTE_PURE;
0707 
0708 /* Find the first occurrence of NEEDLE in HAYSTACK.  */
0709 /* Similar to strstr(), wcsstr().  */
0710 extern uint8_t *
0711        u8_strstr (const uint8_t *haystack, const uint8_t *needle)
0712        _UC_ATTRIBUTE_PURE;
0713 extern uint16_t *
0714        u16_strstr (const uint16_t *haystack, const uint16_t *needle)
0715        _UC_ATTRIBUTE_PURE;
0716 extern uint32_t *
0717        u32_strstr (const uint32_t *haystack, const uint32_t *needle)
0718        _UC_ATTRIBUTE_PURE;
0719 
0720 /* Test whether STR starts with PREFIX.  */
0721 extern bool
0722        u8_startswith (const uint8_t *str, const uint8_t *prefix)
0723        _UC_ATTRIBUTE_PURE;
0724 extern bool
0725        u16_startswith (const uint16_t *str, const uint16_t *prefix)
0726        _UC_ATTRIBUTE_PURE;
0727 extern bool
0728        u32_startswith (const uint32_t *str, const uint32_t *prefix)
0729        _UC_ATTRIBUTE_PURE;
0730 
0731 /* Test whether STR ends with SUFFIX.  */
0732 extern bool
0733        u8_endswith (const uint8_t *str, const uint8_t *suffix)
0734        _UC_ATTRIBUTE_PURE;
0735 extern bool
0736        u16_endswith (const uint16_t *str, const uint16_t *suffix)
0737        _UC_ATTRIBUTE_PURE;
0738 extern bool
0739        u32_endswith (const uint32_t *str, const uint32_t *suffix)
0740        _UC_ATTRIBUTE_PURE;
0741 
0742 /* Divide STR into tokens separated by characters in DELIM.
0743    This interface is actually more similar to wcstok than to strtok.  */
0744 /* Similar to strtok_r(), wcstok().  */
0745 extern uint8_t *
0746        u8_strtok (uint8_t *_UC_RESTRICT str, const uint8_t *delim,
0747                   uint8_t **ptr);
0748 extern uint16_t *
0749        u16_strtok (uint16_t *_UC_RESTRICT str, const uint16_t *delim,
0750                    uint16_t **ptr);
0751 extern uint32_t *
0752        u32_strtok (uint32_t *_UC_RESTRICT str, const uint32_t *delim,
0753                    uint32_t **ptr);
0754 
0755 
0756 #ifdef __cplusplus
0757 }
0758 #endif
0759 
0760 #endif /* _UNISTR_H */