Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-17 09:56:14

0001 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
0002 /* Elementary Unicode string functions.
0003    Copyright (C) 2001-2002, 2005-2024 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, returning pointer after last written unit.  */
0391 /* Similar to mempcpy().  */
0392 extern uint8_t *
0393        u8_pcpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src, size_t n);
0394 extern uint16_t *
0395        u16_pcpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src, size_t n);
0396 extern uint32_t *
0397        u32_pcpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src, size_t n);
0398 
0399 /* Copy N units from SRC to DEST, guaranteeing correct behavior for
0400    overlapping memory areas.  */
0401 /* Similar to memmove().  */
0402 extern uint8_t *
0403        u8_move (uint8_t *dest, const uint8_t *src, size_t n);
0404 extern uint16_t *
0405        u16_move (uint16_t *dest, const uint16_t *src, size_t n);
0406 extern uint32_t *
0407        u32_move (uint32_t *dest, const uint32_t *src, size_t n);
0408 
0409 /* Set the first N characters of S to UC.  UC should be a character that
0410    occupies only 1 unit.  */
0411 /* Similar to memset().  */
0412 extern uint8_t *
0413        u8_set (uint8_t *s, ucs4_t uc, size_t n);
0414 extern uint16_t *
0415        u16_set (uint16_t *s, ucs4_t uc, size_t n);
0416 extern uint32_t *
0417        u32_set (uint32_t *s, ucs4_t uc, size_t n);
0418 
0419 /* Compare S1 and S2, each of length N.  */
0420 /* Similar to memcmp().  */
0421 extern int
0422        u8_cmp (const uint8_t *s1, const uint8_t *s2, size_t n)
0423        _UC_ATTRIBUTE_PURE;
0424 extern int
0425        u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n)
0426        _UC_ATTRIBUTE_PURE;
0427 extern int
0428        u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n)
0429        _UC_ATTRIBUTE_PURE;
0430 
0431 /* Compare S1 and S2.  */
0432 /* Similar to the gnulib function memcmp2().  */
0433 extern int
0434        u8_cmp2 (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2)
0435        _UC_ATTRIBUTE_PURE;
0436 extern int
0437        u16_cmp2 (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2)
0438        _UC_ATTRIBUTE_PURE;
0439 extern int
0440        u32_cmp2 (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2)
0441        _UC_ATTRIBUTE_PURE;
0442 
0443 /* Search the string at S for UC.  */
0444 /* Similar to memchr().  */
0445 extern uint8_t *
0446        u8_chr (const uint8_t *s, size_t n, ucs4_t uc)
0447        _UC_ATTRIBUTE_PURE;
0448 extern uint16_t *
0449        u16_chr (const uint16_t *s, size_t n, ucs4_t uc)
0450        _UC_ATTRIBUTE_PURE;
0451 extern uint32_t *
0452        u32_chr (const uint32_t *s, size_t n, ucs4_t uc)
0453        _UC_ATTRIBUTE_PURE;
0454 
0455 /* Count the number of Unicode characters in the N units from S.  */
0456 /* Similar to mbsnlen().  */
0457 extern size_t
0458        u8_mbsnlen (const uint8_t *s, size_t n)
0459        _UC_ATTRIBUTE_PURE;
0460 extern size_t
0461        u16_mbsnlen (const uint16_t *s, size_t n)
0462        _UC_ATTRIBUTE_PURE;
0463 extern size_t
0464        u32_mbsnlen (const uint32_t *s, size_t n)
0465        _UC_ATTRIBUTE_PURE;
0466 
0467 /* Elementary string functions with memory allocation.  */
0468 
0469 /* Make a freshly allocated copy of S, of length N.  */
0470 extern uint8_t *
0471        u8_cpy_alloc (const uint8_t *s, size_t n);
0472 extern uint16_t *
0473        u16_cpy_alloc (const uint16_t *s, size_t n);
0474 extern uint32_t *
0475        u32_cpy_alloc (const uint32_t *s, size_t n);
0476 
0477 /* Elementary string functions on NUL terminated strings.  */
0478 
0479 /* Return the length (number of units) of the first character in S.
0480    Return 0 if it is the NUL character.  Return -1 upon failure.  */
0481 extern int
0482        u8_strmblen (const uint8_t *s)
0483        _UC_ATTRIBUTE_PURE;
0484 extern int
0485        u16_strmblen (const uint16_t *s)
0486        _UC_ATTRIBUTE_PURE;
0487 extern int
0488        u32_strmblen (const uint32_t *s)
0489        _UC_ATTRIBUTE_PURE;
0490 
0491 /* Return the length (number of units) of the first character in S, putting
0492    its 'ucs4_t' representation in *PUC.  Return 0 if it is the NUL
0493    character.  Return -1 upon failure.  */
0494 extern int
0495        u8_strmbtouc (ucs4_t *puc, const uint8_t *s);
0496 extern int
0497        u16_strmbtouc (ucs4_t *puc, const uint16_t *s);
0498 extern int
0499        u32_strmbtouc (ucs4_t *puc, const uint32_t *s);
0500 
0501 /* Forward iteration step.  Advances the pointer past the next character,
0502    or returns NULL if the end of the string has been reached.  Puts the
0503    character's 'ucs4_t' representation in *PUC.  */
0504 extern const uint8_t *
0505        u8_next (ucs4_t *puc, const uint8_t *s);
0506 extern const uint16_t *
0507        u16_next (ucs4_t *puc, const uint16_t *s);
0508 extern const uint32_t *
0509        u32_next (ucs4_t *puc, const uint32_t *s);
0510 
0511 /* Backward iteration step.  Advances the pointer to point to the previous
0512    character, or returns NULL if the beginning of the string had been reached.
0513    Puts the character's 'ucs4_t' representation in *PUC.  */
0514 extern const uint8_t *
0515        u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start);
0516 extern const uint16_t *
0517        u16_prev (ucs4_t *puc, const uint16_t *s, const uint16_t *start);
0518 extern const uint32_t *
0519        u32_prev (ucs4_t *puc, const uint32_t *s, const uint32_t *start);
0520 
0521 /* Return the number of units in S.  */
0522 /* Similar to strlen(), wcslen().  */
0523 extern size_t
0524        u8_strlen (const uint8_t *s)
0525        _UC_ATTRIBUTE_PURE;
0526 extern size_t
0527        u16_strlen (const uint16_t *s)
0528        _UC_ATTRIBUTE_PURE;
0529 extern size_t
0530        u32_strlen (const uint32_t *s)
0531        _UC_ATTRIBUTE_PURE;
0532 
0533 /* Return the number of units in S, but at most MAXLEN.  */
0534 /* Similar to strnlen(), wcsnlen().  */
0535 extern size_t
0536        u8_strnlen (const uint8_t *s, size_t maxlen)
0537        _UC_ATTRIBUTE_PURE;
0538 extern size_t
0539        u16_strnlen (const uint16_t *s, size_t maxlen)
0540        _UC_ATTRIBUTE_PURE;
0541 extern size_t
0542        u32_strnlen (const uint32_t *s, size_t maxlen)
0543        _UC_ATTRIBUTE_PURE;
0544 
0545 /* Copy SRC to DEST.  */
0546 /* Similar to strcpy(), wcscpy().  */
0547 extern uint8_t *
0548        u8_strcpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src);
0549 extern uint16_t *
0550        u16_strcpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src);
0551 extern uint32_t *
0552        u32_strcpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src);
0553 
0554 /* Copy SRC to DEST, returning the address of the terminating NUL in DEST.  */
0555 /* Similar to stpcpy().  */
0556 extern uint8_t *
0557        u8_stpcpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src);
0558 extern uint16_t *
0559        u16_stpcpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src);
0560 extern uint32_t *
0561        u32_stpcpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src);
0562 
0563 /* Copy no more than N units of SRC to DEST.  */
0564 /* Similar to strncpy(), wcsncpy().  */
0565 extern uint8_t *
0566        u8_strncpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src, size_t n);
0567 extern uint16_t *
0568        u16_strncpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src, size_t n);
0569 extern uint32_t *
0570        u32_strncpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src, size_t n);
0571 
0572 /* Copy no more than N units of SRC to DEST.  Return a pointer past the last
0573    non-NUL unit written into DEST.  */
0574 /* Similar to stpncpy().  */
0575 extern uint8_t *
0576        u8_stpncpy (uint8_t *_UC_RESTRICT dest, const uint8_t *src, size_t n);
0577 extern uint16_t *
0578        u16_stpncpy (uint16_t *_UC_RESTRICT dest, const uint16_t *src, size_t n);
0579 extern uint32_t *
0580        u32_stpncpy (uint32_t *_UC_RESTRICT dest, const uint32_t *src, size_t n);
0581 
0582 /* Append SRC onto DEST.  */
0583 /* Similar to strcat(), wcscat().  */
0584 extern uint8_t *
0585        u8_strcat (uint8_t *_UC_RESTRICT dest, const uint8_t *src);
0586 extern uint16_t *
0587        u16_strcat (uint16_t *_UC_RESTRICT dest, const uint16_t *src);
0588 extern uint32_t *
0589        u32_strcat (uint32_t *_UC_RESTRICT dest, const uint32_t *src);
0590 
0591 /* Append no more than N units of SRC onto DEST.  */
0592 /* Similar to strncat(), wcsncat().  */
0593 extern uint8_t *
0594        u8_strncat (uint8_t *_UC_RESTRICT dest, const uint8_t *src, size_t n);
0595 extern uint16_t *
0596        u16_strncat (uint16_t *_UC_RESTRICT dest, const uint16_t *src, size_t n);
0597 extern uint32_t *
0598        u32_strncat (uint32_t *_UC_RESTRICT dest, const uint32_t *src, size_t n);
0599 
0600 /* Compare S1 and S2.  */
0601 /* Similar to strcmp(), wcscmp().  */
0602 #ifdef __sun
0603 /* Avoid a collision with the u8_strcmp() function in Solaris 11 libc.  */
0604 extern int
0605        u8_strcmp_gnu (const uint8_t *s1, const uint8_t *s2)
0606        _UC_ATTRIBUTE_PURE;
0607 # define u8_strcmp u8_strcmp_gnu
0608 #else
0609 extern int
0610        u8_strcmp (const uint8_t *s1, const uint8_t *s2)
0611        _UC_ATTRIBUTE_PURE;
0612 #endif
0613 extern int
0614        u16_strcmp (const uint16_t *s1, const uint16_t *s2)
0615        _UC_ATTRIBUTE_PURE;
0616 extern int
0617        u32_strcmp (const uint32_t *s1, const uint32_t *s2)
0618        _UC_ATTRIBUTE_PURE;
0619 
0620 /* Compare S1 and S2 using the collation rules of the current locale.
0621    Return -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2.
0622    Upon failure, set errno and return any value.  */
0623 /* Similar to strcoll(), wcscoll().  */
0624 extern int
0625        u8_strcoll (const uint8_t *s1, const uint8_t *s2);
0626 extern int
0627        u16_strcoll (const uint16_t *s1, const uint16_t *s2);
0628 extern int
0629        u32_strcoll (const uint32_t *s1, const uint32_t *s2);
0630 
0631 /* Compare no more than N units of S1 and S2.  */
0632 /* Similar to strncmp(), wcsncmp().  */
0633 extern int
0634        u8_strncmp (const uint8_t *s1, const uint8_t *s2, size_t n)
0635        _UC_ATTRIBUTE_PURE;
0636 extern int
0637        u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n)
0638        _UC_ATTRIBUTE_PURE;
0639 extern int
0640        u32_strncmp (const uint32_t *s1, const uint32_t *s2, size_t n)
0641        _UC_ATTRIBUTE_PURE;
0642 
0643 /* Duplicate S, returning an identical malloc'd string.  */
0644 /* Similar to strdup(), wcsdup().  */
0645 extern uint8_t *
0646        u8_strdup (const uint8_t *s)
0647        _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
0648 extern uint16_t *
0649        u16_strdup (const uint16_t *s)
0650        _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
0651 extern uint32_t *
0652        u32_strdup (const uint32_t *s)
0653        _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
0654 
0655 /* Find the first occurrence of UC in STR.  */
0656 /* Similar to strchr(), wcschr().  */
0657 extern uint8_t *
0658        u8_strchr (const uint8_t *str, ucs4_t uc)
0659        _UC_ATTRIBUTE_PURE;
0660 extern uint16_t *
0661        u16_strchr (const uint16_t *str, ucs4_t uc)
0662        _UC_ATTRIBUTE_PURE;
0663 extern uint32_t *
0664        u32_strchr (const uint32_t *str, ucs4_t uc)
0665        _UC_ATTRIBUTE_PURE;
0666 
0667 /* Find the last occurrence of UC in STR.  */
0668 /* Similar to strrchr(), wcsrchr().  */
0669 extern uint8_t *
0670        u8_strrchr (const uint8_t *str, ucs4_t uc)
0671        _UC_ATTRIBUTE_PURE;
0672 extern uint16_t *
0673        u16_strrchr (const uint16_t *str, ucs4_t uc)
0674        _UC_ATTRIBUTE_PURE;
0675 extern uint32_t *
0676        u32_strrchr (const uint32_t *str, ucs4_t uc)
0677        _UC_ATTRIBUTE_PURE;
0678 
0679 /* Return the length of the initial segment of STR which consists entirely
0680    of Unicode characters not in REJECT.  */
0681 /* Similar to strcspn(), wcscspn().  */
0682 extern size_t
0683        u8_strcspn (const uint8_t *str, const uint8_t *reject)
0684        _UC_ATTRIBUTE_PURE;
0685 extern size_t
0686        u16_strcspn (const uint16_t *str, const uint16_t *reject)
0687        _UC_ATTRIBUTE_PURE;
0688 extern size_t
0689        u32_strcspn (const uint32_t *str, const uint32_t *reject)
0690        _UC_ATTRIBUTE_PURE;
0691 
0692 /* Return the length of the initial segment of STR which consists entirely
0693    of Unicode characters in ACCEPT.  */
0694 /* Similar to strspn(), wcsspn().  */
0695 extern size_t
0696        u8_strspn (const uint8_t *str, const uint8_t *accept)
0697        _UC_ATTRIBUTE_PURE;
0698 extern size_t
0699        u16_strspn (const uint16_t *str, const uint16_t *accept)
0700        _UC_ATTRIBUTE_PURE;
0701 extern size_t
0702        u32_strspn (const uint32_t *str, const uint32_t *accept)
0703        _UC_ATTRIBUTE_PURE;
0704 
0705 /* Find the first occurrence in STR of any character in ACCEPT.  */
0706 /* Similar to strpbrk(), wcspbrk().  */
0707 extern uint8_t *
0708        u8_strpbrk (const uint8_t *str, const uint8_t *accept)
0709        _UC_ATTRIBUTE_PURE;
0710 extern uint16_t *
0711        u16_strpbrk (const uint16_t *str, const uint16_t *accept)
0712        _UC_ATTRIBUTE_PURE;
0713 extern uint32_t *
0714        u32_strpbrk (const uint32_t *str, const uint32_t *accept)
0715        _UC_ATTRIBUTE_PURE;
0716 
0717 /* Find the first occurrence of NEEDLE in HAYSTACK.  */
0718 /* Similar to strstr(), wcsstr().  */
0719 extern uint8_t *
0720        u8_strstr (const uint8_t *haystack, const uint8_t *needle)
0721        _UC_ATTRIBUTE_PURE;
0722 extern uint16_t *
0723        u16_strstr (const uint16_t *haystack, const uint16_t *needle)
0724        _UC_ATTRIBUTE_PURE;
0725 extern uint32_t *
0726        u32_strstr (const uint32_t *haystack, const uint32_t *needle)
0727        _UC_ATTRIBUTE_PURE;
0728 
0729 /* Test whether STR starts with PREFIX.  */
0730 extern bool
0731        u8_startswith (const uint8_t *str, const uint8_t *prefix)
0732        _UC_ATTRIBUTE_PURE;
0733 extern bool
0734        u16_startswith (const uint16_t *str, const uint16_t *prefix)
0735        _UC_ATTRIBUTE_PURE;
0736 extern bool
0737        u32_startswith (const uint32_t *str, const uint32_t *prefix)
0738        _UC_ATTRIBUTE_PURE;
0739 
0740 /* Test whether STR ends with SUFFIX.  */
0741 extern bool
0742        u8_endswith (const uint8_t *str, const uint8_t *suffix)
0743        _UC_ATTRIBUTE_PURE;
0744 extern bool
0745        u16_endswith (const uint16_t *str, const uint16_t *suffix)
0746        _UC_ATTRIBUTE_PURE;
0747 extern bool
0748        u32_endswith (const uint32_t *str, const uint32_t *suffix)
0749        _UC_ATTRIBUTE_PURE;
0750 
0751 /* Divide STR into tokens separated by characters in DELIM.
0752    This interface is actually more similar to wcstok than to strtok.  */
0753 /* Similar to strtok_r(), wcstok().  */
0754 extern uint8_t *
0755        u8_strtok (uint8_t *_UC_RESTRICT str, const uint8_t *delim,
0756                   uint8_t **ptr);
0757 extern uint16_t *
0758        u16_strtok (uint16_t *_UC_RESTRICT str, const uint16_t *delim,
0759                    uint16_t **ptr);
0760 extern uint32_t *
0761        u32_strtok (uint32_t *_UC_RESTRICT str, const uint32_t *delim,
0762                    uint32_t **ptr);
0763 
0764 
0765 #ifdef __cplusplus
0766 }
0767 #endif
0768 
0769 #endif /* _UNISTR_H */