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