File indexing completed on 2024-05-18 08:30:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef _UNISTR_H
0019 #define _UNISTR_H
0020
0021 #include "unitypes.h"
0022
0023
0024 #include <unistring/cdefs.h>
0025
0026
0027 #include <unistring/inline.h>
0028
0029
0030 #include <unistring/stdbool.h>
0031
0032
0033 #include <stddef.h>
0034
0035
0036 #include <stdlib.h>
0037
0038 #ifdef __cplusplus
0039 extern "C" {
0040 #endif
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 extern const uint8_t *
0076 u8_check (const uint8_t *s, size_t n)
0077 _UC_ATTRIBUTE_PURE;
0078
0079
0080
0081 extern const uint16_t *
0082 u16_check (const uint16_t *s, size_t n)
0083 _UC_ATTRIBUTE_PURE;
0084
0085
0086
0087 extern const uint32_t *
0088 u32_check (const uint32_t *s, size_t n)
0089 _UC_ATTRIBUTE_PURE;
0090
0091
0092
0093
0094
0095 extern uint16_t *
0096 u8_to_u16 (const uint8_t *s, size_t n, uint16_t *resultbuf,
0097 size_t *lengthp);
0098
0099
0100 extern uint32_t *
0101 u8_to_u32 (const uint8_t *s, size_t n, uint32_t *resultbuf,
0102 size_t *lengthp);
0103
0104
0105 extern uint8_t *
0106 u16_to_u8 (const uint16_t *s, size_t n, uint8_t *resultbuf,
0107 size_t *lengthp);
0108
0109
0110 extern uint32_t *
0111 u16_to_u32 (const uint16_t *s, size_t n, uint32_t *resultbuf,
0112 size_t *lengthp);
0113
0114
0115 extern uint8_t *
0116 u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf,
0117 size_t *lengthp);
0118
0119
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
0126
0127
0128
0129
0130
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
0142
0143
0144
0145
0146
0147
0148
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
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
0278 *puc = 0xfffd;
0279 return 1;
0280 }
0281 # endif
0282 #endif
0283
0284
0285
0286
0287
0288
0289
0290
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
0308
0309
0310
0311
0312
0313 #if 1
0314
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
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
0382
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
0391
0392
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
0401
0402
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
0411
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
0423
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
0435
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
0447
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
0459
0460
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
0469
0470
0471
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
0483
0484
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
0493
0494
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
0503
0504
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
0513
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
0525
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
0537
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
0546
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
0555
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
0564
0565
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
0574
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
0583
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
0592
0593 #ifdef __sun
0594
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
0612
0613
0614
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
0623
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
0635
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
0647
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
0659
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
0671
0672
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
0684
0685
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
0697
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
0709
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
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
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
0743
0744
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