1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
|
@node unistr.h
@chapter Elementary Unicode string functions @code{<unistr.h>}
This include file declares elementary functions for Unicode strings. It is
essentially the equivalent of what @code{<string.h>} is for C strings.
@menu
* Elementary string checks::
* Elementary string conversions::
* Elementary string functions::
* Elementary string functions with memory allocation::
* Elementary string functions on NUL terminated strings::
@end menu
@node Elementary string checks
@section Elementary string checks
@cindex validity
@cindex verification
@cindex well-formed
The following function is available to verify the integrity of a Unicode string.
@deftypefun {const uint8_t *} u8_check (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx {const uint16_t *} u16_check (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx {const uint32_t *} u32_check (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n})
This function checks whether a Unicode string is well-formed.
It returns NULL if valid, or a pointer to the first invalid unit otherwise.
@end deftypefun
@node Elementary string conversions
@section Elementary string conversions
@cindex converting
The following functions perform conversions between the different forms of Unicode strings.
@deftypefun {uint16_t *} u8_to_u16 (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n}, uint16_t@tie{}*@var{resultbuf}, size_t@tie{}*@var{lengthp})
Converts an UTF-8 string to an UTF-16 string.
The @var{resultbuf} and @var{lengthp} arguments are as described in
chapter @ref{Conventions}.
@end deftypefun
@deftypefun {uint32_t *} u8_to_u32 (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n}, uint32_t@tie{}*@var{resultbuf}, size_t@tie{}*@var{lengthp})
Converts an UTF-8 string to an UTF-32 string.
The @var{resultbuf} and @var{lengthp} arguments are as described in
chapter @ref{Conventions}.
@end deftypefun
@deftypefun {uint8_t *} u16_to_u8 (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n}, uint8_t@tie{}*@var{resultbuf}, size_t@tie{}*@var{lengthp})
Converts an UTF-16 string to an UTF-8 string.
The @var{resultbuf} and @var{lengthp} arguments are as described in
chapter @ref{Conventions}.
@end deftypefun
@deftypefun {uint32_t *} u16_to_u32 (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n}, uint32_t@tie{}*@var{resultbuf}, size_t@tie{}*@var{lengthp})
Converts an UTF-16 string to an UTF-32 string.
The @var{resultbuf} and @var{lengthp} arguments are as described in
chapter @ref{Conventions}.
@end deftypefun
@deftypefun {uint8_t *} u32_to_u8 (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n}, uint8_t@tie{}*@var{resultbuf}, size_t@tie{}*@var{lengthp})
Converts an UTF-32 string to an UTF-8 string.
The @var{resultbuf} and @var{lengthp} arguments are as described in
chapter @ref{Conventions}.
@end deftypefun
@deftypefun {uint16_t *} u32_to_u16 (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n}, uint16_t@tie{}*@var{resultbuf}, size_t@tie{}*@var{lengthp})
Converts an UTF-32 string to an UTF-16 string.
The @var{resultbuf} and @var{lengthp} arguments are as described in
chapter @ref{Conventions}.
@end deftypefun
@node Elementary string functions
@section Elementary string functions
@menu
* Iterating::
* Creating Unicode strings::
* Copying Unicode strings::
* Comparing Unicode strings::
* Searching for a character::
* Counting characters::
@end menu
@node Iterating
@subsection Iterating over a Unicode string
@cindex iterating
The following functions inspect and return details about the first character
in a Unicode string.
@deftypefun int u8_mblen (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx int u16_mblen (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx int u32_mblen (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n})
Returns the length (number of units) of the first character in @var{s}, which
is no longer than @var{n}. Returns 0 if it is the NUL character. Returns -1
upon failure.
This function is similar to @posixfunc{mblen}, except that it operates on a
Unicode string and that @var{s} must not be NULL.
@end deftypefun
@deftypefun int u8_mbtouc (ucs4_t@tie{}*@var{puc}, const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx int u16_mbtouc (ucs4_t@tie{}*@var{puc}, const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx int u32_mbtouc (ucs4_t@tie{}*@var{puc}, const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n})
Returns the length (number of units) of the first character in @var{s},
putting its @code{ucs4_t} representation in @code{*@var{puc}}. Upon failure,
@code{*@var{puc}} is set to @code{0xfffd}, and an appropriate number of units
is returned.
The number of available units, @var{n}, must be > 0.
This function fails if an invalid sequence of units is encountered at the
beginning of @var{s}, or if additional units (after the @var{n} provided units)
would be needed to form a character.
This function is similar to @posixfunc{mbtowc}, except that it operates on a
Unicode string, @var{puc} and @var{s} must not be NULL, @var{n} must be > 0,
and the NUL character is not treated specially.
@end deftypefun
@deftypefun int u8_mbtouc_unsafe (ucs4_t@tie{}*@var{puc}, const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx int u16_mbtouc_unsafe (ucs4_t@tie{}*@var{puc}, const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx int u32_mbtouc_unsafe (ucs4_t@tie{}*@var{puc}, const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n})
This function is identical to @code{u8_mbtouc}/@code{u16_mbtouc}/@code{u32_mbtouc}.
Earlier versions of this function performed fewer range-checks on the sequence
of units.
@end deftypefun
@deftypefun int u8_mbtoucr (ucs4_t@tie{}*@var{puc}, const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx int u16_mbtoucr (ucs4_t@tie{}*@var{puc}, const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx int u32_mbtoucr (ucs4_t@tie{}*@var{puc}, const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n})
Returns the length (number of units) of the first character in @var{s},
putting its @code{ucs4_t} representation in @code{*@var{puc}}. Upon failure,
@code{*@var{puc}} is set to @code{0xfffd}, and -1 is returned for an invalid
sequence of units, -2 is returned for an incomplete sequence of units.
The number of available units, @var{n}, must be > 0.
This function is similar to @code{u8_mbtouc}, except that the return value
gives more details about the failure, similar to @posixfunc{mbrtowc}.
@end deftypefun
@node Creating Unicode strings
@subsection Creating Unicode strings one character at a time
The following function stores a Unicode character as a Unicode string in
memory.
@deftypefun int u8_uctomb (uint8_t@tie{}*@var{s}, ucs4_t@tie{}@var{uc}, ptrdiff_t@tie{}@var{n})
@deftypefunx int u16_uctomb (uint16_t@tie{}*@var{s}, ucs4_t@tie{}@var{uc}, ptrdiff_t@tie{}@var{n})
@deftypefunx int u32_uctomb (uint32_t@tie{}*@var{s}, ucs4_t@tie{}@var{uc}, ptrdiff_t@tie{}@var{n})
Puts the multibyte character represented by @var{uc} in @var{s}, returning its
length. Returns -1 upon failure, -2 if the number of available units, @var{n},
is too small. The latter case cannot occur if @var{n} >= 6/2/1, respectively.
This function is similar to @posixfunc{wctomb}, except that it operates on a
Unicode strings, @var{s} must not be NULL, and the argument @var{n} must be
specified.
@end deftypefun
@node Copying Unicode strings
@subsection Copying Unicode strings
@cindex copying
The following functions copy Unicode strings in memory.
@deftypefun {uint8_t *} u8_cpy (uint8_t@tie{}*@var{dest}, const@tie{}uint8_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint16_t *} u16_cpy (uint16_t@tie{}*@var{dest}, const@tie{}uint16_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint32_t *} u32_cpy (uint32_t@tie{}*@var{dest}, const@tie{}uint32_t@tie{}*@var{src}, size_t@tie{}@var{n})
Copies @var{n} units from @var{src} to @var{dest}.
This function is similar to @posixfunc{memcpy}, except that it operates on
Unicode strings.
@end deftypefun
@deftypefun {uint8_t *} u8_pcpy (uint8_t@tie{}*@var{dest}, const@tie{}uint8_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint16_t *} u16_pcpy (uint16_t@tie{}*@var{dest}, const@tie{}uint16_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint32_t *} u32_pcpy (uint32_t@tie{}*@var{dest}, const@tie{}uint32_t@tie{}*@var{src}, size_t@tie{}@var{n})
Copies @var{n} units from @var{src} to @var{dest}, returning a pointer
after the last written unit.
This function is similar to @func{mempcpy}, except that it operates on
Unicode strings.
@end deftypefun
@deftypefun {uint8_t *} u8_move (uint8_t@tie{}*@var{dest}, const@tie{}uint8_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint16_t *} u16_move (uint16_t@tie{}*@var{dest}, const@tie{}uint16_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint32_t *} u32_move (uint32_t@tie{}*@var{dest}, const@tie{}uint32_t@tie{}*@var{src}, size_t@tie{}@var{n})
Copies @var{n} units from @var{src} to @var{dest}, guaranteeing correct
behavior for overlapping memory areas.
This function is similar to @posixfunc{memmove}, except that it operates on
Unicode strings.
@end deftypefun
The following function fills a Unicode string.
@deftypefun {uint8_t *} u8_set (uint8_t@tie{}*@var{s}, ucs4_t@tie{}@var{uc}, size_t@tie{}@var{n})
@deftypefunx {uint16_t *} u16_set (uint16_t@tie{}*@var{s}, ucs4_t@tie{}@var{uc}, size_t@tie{}@var{n})
@deftypefunx {uint32_t *} u32_set (uint32_t@tie{}*@var{s}, ucs4_t@tie{}@var{uc}, size_t@tie{}@var{n})
Sets the first @var{n} characters of @var{s} to @var{uc}. @var{uc} should be
a character that occupies only 1 unit.
This function is similar to @posixfunc{memset}, except that it operates on
Unicode strings.
@end deftypefun
@node Comparing Unicode strings
@subsection Comparing Unicode strings
@cindex comparing
The following function compares two Unicode strings of the same length.
@deftypefun int u8_cmp (const@tie{}uint8_t@tie{}*@var{s1}, const@tie{}uint8_t@tie{}*@var{s2}, size_t@tie{}@var{n})
@deftypefunx int u16_cmp (const@tie{}uint16_t@tie{}*@var{s1}, const@tie{}uint16_t@tie{}*@var{s2}, size_t@tie{}@var{n})
@deftypefunx int u32_cmp (const@tie{}uint32_t@tie{}*@var{s1}, const@tie{}uint32_t@tie{}*@var{s2}, size_t@tie{}@var{n})
Compares @var{s1} and @var{s2}, each of length @var{n}, lexicographically.
Returns a negative value if @var{s1} compares smaller than @var{s2},
a positive value if @var{s1} compares larger than @var{s2}, or 0 if
they compare equal.
This function is similar to @posixfunc{memcmp}, except that it operates on
Unicode strings.
@end deftypefun
The following function compares two Unicode strings of possibly different
lengths.
@deftypefun int u8_cmp2 (const@tie{}uint8_t@tie{}*@var{s1}, size_t@tie{}@var{n1}, const@tie{}uint8_t@tie{}*@var{s2}, size_t@tie{}@var{n2})
@deftypefunx int u16_cmp2 (const@tie{}uint16_t@tie{}*@var{s1}, size_t@tie{}@var{n1}, const@tie{}uint16_t@tie{}*@var{s2}, size_t@tie{}@var{n2})
@deftypefunx int u32_cmp2 (const@tie{}uint32_t@tie{}*@var{s1}, size_t@tie{}@var{n1}, const@tie{}uint32_t@tie{}*@var{s2}, size_t@tie{}@var{n2})
Compares @var{s1} and @var{s2}, lexicographically.
Returns a negative value if @var{s1} compares smaller than @var{s2},
a positive value if @var{s1} compares larger than @var{s2}, or 0 if
they compare equal.
This function is similar to the gnulib function @func{memcmp2}, except that it
operates on Unicode strings.
@end deftypefun
@node Searching for a character
@subsection Searching for a character in a Unicode string
@cindex searching, for a character
The following function searches for a given Unicode character.
@deftypefun {uint8_t *} u8_chr (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n}, ucs4_t@tie{}@var{uc})
@deftypefunx {uint16_t *} u16_chr (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n}, ucs4_t@tie{}@var{uc})
@deftypefunx {uint32_t *} u32_chr (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n}, ucs4_t@tie{}@var{uc})
Searches the string at @var{s} for @var{uc}. Returns a pointer to the first
occurrence of @var{uc} in @var{s}, or NULL if @var{uc} does not occur in
@var{s}.
This function is similar to @posixfunc{memchr}, except that it operates on
Unicode strings.
@end deftypefun
@node Counting characters
@subsection Counting the characters in a Unicode string
@cindex counting
The following function counts the number of Unicode characters.
@deftypefun size_t u8_mbsnlen (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx size_t u16_mbsnlen (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx size_t u32_mbsnlen (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n})
Counts and returns the number of Unicode characters in the @var{n} units
from @var{s}.
This function is similar to the gnulib function @func{mbsnlen}, except that
it operates on Unicode strings.
@end deftypefun
@node Elementary string functions with memory allocation
@section Elementary string functions with memory allocation
@cindex duplicating
The following function copies a Unicode string.
@deftypefun {uint8_t *} u8_cpy_alloc (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx {uint16_t *} u16_cpy_alloc (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{n})
@deftypefunx {uint32_t *} u32_cpy_alloc (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{n})
Makes a freshly allocated copy of @var{s}, of length @var{n}.
@end deftypefun
@node Elementary string functions on NUL terminated strings
@section Elementary string functions on NUL terminated strings
@menu
* Iterating over a NUL terminated Unicode string::
* Length::
* Copying a NUL terminated Unicode string::
* Comparing NUL terminated Unicode strings::
* Duplicating a NUL terminated Unicode string::
* Searching for a character in a NUL terminated Unicode string::
* Searching for a substring::
* Tokenizing::
@end menu
@node Iterating over a NUL terminated Unicode string
@subsection Iterating over a NUL terminated Unicode string
The following functions inspect and return details about the first character
in a Unicode string.
@deftypefun int u8_strmblen (const@tie{}uint8_t@tie{}*@var{s})
@deftypefunx int u16_strmblen (const@tie{}uint16_t@tie{}*@var{s})
@deftypefunx int u32_strmblen (const@tie{}uint32_t@tie{}*@var{s})
Returns the length (number of units) of the first character in @var{s}.
Returns 0 if it is the NUL character. Returns -1 upon failure.
@end deftypefun
@cindex iterating
@deftypefun int u8_strmbtouc (ucs4_t@tie{}*@var{puc}, const@tie{}uint8_t@tie{}*@var{s})
@deftypefunx int u16_strmbtouc (ucs4_t@tie{}*@var{puc}, const@tie{}uint16_t@tie{}*@var{s})
@deftypefunx int u32_strmbtouc (ucs4_t@tie{}*@var{puc}, const@tie{}uint32_t@tie{}*@var{s})
Returns the length (number of units) of the first character in @var{s},
putting its @code{ucs4_t} representation in @code{*@var{puc}}. Returns 0
if it is the NUL character. Returns -1 upon failure.
@end deftypefun
@deftypefun {const uint8_t *} u8_next (ucs4_t@tie{}*@var{puc}, const@tie{}uint8_t@tie{}*@var{s})
@deftypefunx {const uint16_t *} u16_next (ucs4_t@tie{}*@var{puc}, const@tie{}uint16_t@tie{}*@var{s})
@deftypefunx {const uint32_t *} u32_next (ucs4_t@tie{}*@var{puc}, const@tie{}uint32_t@tie{}*@var{s})
Forward iteration step. Advances the pointer past the next character,
or returns NULL if the end of the string has been reached. Puts the
character's @code{ucs4_t} representation in @code{*@var{puc}}.
@end deftypefun
The following function inspects and returns details about the previous
character in a Unicode string.
@deftypefun {const uint8_t *} u8_prev (ucs4_t@tie{}*@var{puc}, const@tie{}uint8_t@tie{}*@var{s}, const@tie{}uint8_t@tie{}*@var{start})
@deftypefunx {const uint16_t *} u16_prev (ucs4_t@tie{}*@var{puc}, const@tie{}uint16_t@tie{}*@var{s}, const@tie{}uint16_t@tie{}*@var{start})
@deftypefunx {const uint32_t *} u32_prev (ucs4_t@tie{}*@var{puc}, const@tie{}uint32_t@tie{}*@var{s}, const@tie{}uint32_t@tie{}*@var{start})
Backward iteration step. Advances the pointer to point to the previous
character (the one that ends at @code{@var{s}}), or returns NULL if the
beginning of the string (specified by @code{@var{start}}) had been reached.
Puts the character's @code{ucs4_t} representation in @code{*@var{puc}}.
Note that this function works only on well-formed Unicode strings.
@end deftypefun
@node Length
@subsection Length of a NUL terminated Unicode string
The following functions determine the length of a Unicode string.
@deftypefun size_t u8_strlen (const@tie{}uint8_t@tie{}*@var{s})
@deftypefunx size_t u16_strlen (const@tie{}uint16_t@tie{}*@var{s})
@deftypefunx size_t u32_strlen (const@tie{}uint32_t@tie{}*@var{s})
Returns the number of units in @var{s}.
This function is similar to @posixfunc{strlen} and @posixfunc{wcslen}, except
that it operates on Unicode strings.
@end deftypefun
@deftypefun size_t u8_strnlen (const@tie{}uint8_t@tie{}*@var{s}, size_t@tie{}@var{maxlen})
@deftypefunx size_t u16_strnlen (const@tie{}uint16_t@tie{}*@var{s}, size_t@tie{}@var{maxlen})
@deftypefunx size_t u32_strnlen (const@tie{}uint32_t@tie{}*@var{s}, size_t@tie{}@var{maxlen})
Returns the number of units in @var{s}, but at most @var{maxlen}.
This function is similar to @posixfunc{strnlen} and @posixfunc{wcsnlen}, except
that it operates on Unicode strings.
@end deftypefun
@node Copying a NUL terminated Unicode string
@subsection Copying a NUL terminated Unicode string
@cindex copying
The following functions copy portions of Unicode strings in memory.
@deftypefun {uint8_t *} u8_strcpy (uint8_t@tie{}*@var{dest}, const@tie{}uint8_t@tie{}*@var{src})
@deftypefunx {uint16_t *} u16_strcpy (uint16_t@tie{}*@var{dest}, const@tie{}uint16_t@tie{}*@var{src})
@deftypefunx {uint32_t *} u32_strcpy (uint32_t@tie{}*@var{dest}, const@tie{}uint32_t@tie{}*@var{src})
Copies @var{src} to @var{dest}.
This function is similar to @posixfunc{strcpy} and @posixfunc{wcscpy}, except
that it operates on Unicode strings.
@end deftypefun
@deftypefun {uint8_t *} u8_stpcpy (uint8_t@tie{}*@var{dest}, const@tie{}uint8_t@tie{}*@var{src})
@deftypefunx {uint16_t *} u16_stpcpy (uint16_t@tie{}*@var{dest}, const@tie{}uint16_t@tie{}*@var{src})
@deftypefunx {uint32_t *} u32_stpcpy (uint32_t@tie{}*@var{dest}, const@tie{}uint32_t@tie{}*@var{src})
Copies @var{src} to @var{dest}, returning the address of the terminating NUL
in @var{dest}.
This function is similar to @posixfunc{stpcpy}, except that it operates on
Unicode strings.
@end deftypefun
@deftypefun {uint8_t *} u8_strncpy (uint8_t@tie{}*@var{dest}, const@tie{}uint8_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint16_t *} u16_strncpy (uint16_t@tie{}*@var{dest}, const@tie{}uint16_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint32_t *} u32_strncpy (uint32_t@tie{}*@var{dest}, const@tie{}uint32_t@tie{}*@var{src}, size_t@tie{}@var{n})
Copies no more than @var{n} units of @var{src} to @var{dest}.
This function is similar to @posixfunc{strncpy} and @posixfunc{wcsncpy}, except
that it operates on Unicode strings.
@end deftypefun
@deftypefun {uint8_t *} u8_stpncpy (uint8_t@tie{}*@var{dest}, const@tie{}uint8_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint16_t *} u16_stpncpy (uint16_t@tie{}*@var{dest}, const@tie{}uint16_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint32_t *} u32_stpncpy (uint32_t@tie{}*@var{dest}, const@tie{}uint32_t@tie{}*@var{src}, size_t@tie{}@var{n})
Copies no more than @var{n} units of @var{src} to @var{dest}. Returns a
pointer past the last non-NUL unit written into @var{dest}. In other words,
if the units written into @var{dest} include a NUL, the return value is the
address of the first such NUL unit, otherwise it is
@code{@var{dest} + @var{n}}.
This function is similar to @posixfunc{stpncpy}, except that it operates on
Unicode strings.
@end deftypefun
@deftypefun {uint8_t *} u8_strcat (uint8_t@tie{}*@var{dest}, const@tie{}uint8_t@tie{}*@var{src})
@deftypefunx {uint16_t *} u16_strcat (uint16_t@tie{}*@var{dest}, const@tie{}uint16_t@tie{}*@var{src})
@deftypefunx {uint32_t *} u32_strcat (uint32_t@tie{}*@var{dest}, const@tie{}uint32_t@tie{}*@var{src})
Appends @var{src} onto @var{dest}.
This function is similar to @posixfunc{strcat} and @posixfunc{wcscat}, except
that it operates on Unicode strings.
@end deftypefun
@deftypefun {uint8_t *} u8_strncat (uint8_t@tie{}*@var{dest}, const@tie{}uint8_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint16_t *} u16_strncat (uint16_t@tie{}*@var{dest}, const@tie{}uint16_t@tie{}*@var{src}, size_t@tie{}@var{n})
@deftypefunx {uint32_t *} u32_strncat (uint32_t@tie{}*@var{dest}, const@tie{}uint32_t@tie{}*@var{src}, size_t@tie{}@var{n})
Appends no more than @var{n} units of @var{src} onto @var{dest}.
This function is similar to @posixfunc{strncat} and @posixfunc{wcsncat}, except
that it operates on Unicode strings.
@end deftypefun
@node Comparing NUL terminated Unicode strings
@subsection Comparing NUL terminated Unicode strings
@cindex comparing
The following functions compare two Unicode strings.
They ignore locale-dependent collation rules.
@deftypefun int u8_strcmp (const@tie{}uint8_t@tie{}*@var{s1}, const@tie{}uint8_t@tie{}*@var{s2})
@deftypefunx int u16_strcmp (const@tie{}uint16_t@tie{}*@var{s1}, const@tie{}uint16_t@tie{}*@var{s2})
@deftypefunx int u32_strcmp (const@tie{}uint32_t@tie{}*@var{s1}, const@tie{}uint32_t@tie{}*@var{s2})
Compares @var{s1} and @var{s2}, lexicographically.
Returns a negative value if @var{s1} compares smaller than @var{s2},
a positive value if @var{s1} compares larger than @var{s2}, or 0 if
they compare equal.
This function is similar to @posixfunc{strcmp} and @posixfunc{wcscmp}, except
that it operates on Unicode strings.
@end deftypefun
@cindex comparing, with collation rules
@deftypefun int u8_strcoll (const@tie{}uint8_t@tie{}*@var{s1}, const@tie{}uint8_t@tie{}*@var{s2})
@deftypefunx int u16_strcoll (const@tie{}uint16_t@tie{}*@var{s1}, const@tie{}uint16_t@tie{}*@var{s2})
@deftypefunx int u32_strcoll (const@tie{}uint32_t@tie{}*@var{s1}, const@tie{}uint32_t@tie{}*@var{s2})
Compares @var{s1} and @var{s2} using the collation rules of the current
locale.
Returns -1 if @var{s1} < @var{s2}, 0 if @var{s1} = @var{s2}, 1 if
@var{s1} > @var{s2}. Upon failure, sets @code{errno} and returns any value.
This function is similar to @posixfunc{strcoll} and @posixfunc{wcscoll}, except
that it operates on Unicode strings.
Note that this function may consider different canonical normalizations
of the same string as having a large distance. It is therefore better to
use the function @code{u8_normcoll} instead of this one; see @ref{uninorm.h}.
@end deftypefun
@deftypefun int u8_strncmp (const@tie{}uint8_t@tie{}*@var{s1}, const@tie{}uint8_t@tie{}*@var{s2}, size_t@tie{}@var{n})
@deftypefunx int u16_strncmp (const@tie{}uint16_t@tie{}*@var{s1}, const@tie{}uint16_t@tie{}*@var{s2}, size_t@tie{}@var{n})
@deftypefunx int u32_strncmp (const@tie{}uint32_t@tie{}*@var{s1}, const@tie{}uint32_t@tie{}*@var{s2}, size_t@tie{}@var{n})
Compares no more than @var{n} units of @var{s1} and @var{s2}.
This function is similar to @posixfunc{strncmp} and @posixfunc{wcsncmp}, except
that it operates on Unicode strings.
@end deftypefun
@node Duplicating a NUL terminated Unicode string
@subsection Duplicating a NUL terminated Unicode string
@cindex duplicating
The following function allocates a duplicate of a Unicode string.
@deftypefun {uint8_t *} u8_strdup (const@tie{}uint8_t@tie{}*@var{s})
@deftypefunx {uint16_t *} u16_strdup (const@tie{}uint16_t@tie{}*@var{s})
@deftypefunx {uint32_t *} u32_strdup (const@tie{}uint32_t@tie{}*@var{s})
Duplicates @var{s}, returning an identical malloc'd string.
This function is similar to @posixfunc{strdup} and @posixfunc{wcsdup}, except
that it operates on Unicode strings.
@end deftypefun
@node Searching for a character in a NUL terminated Unicode string
@subsection Searching for a character in a NUL terminated Unicode string
@cindex searching, for a character
The following functions search for a given Unicode character.
@deftypefun {uint8_t *} u8_strchr (const@tie{}uint8_t@tie{}*@var{str}, ucs4_t@tie{}@var{uc})
@deftypefunx {uint16_t *} u16_strchr (const@tie{}uint16_t@tie{}*@var{str}, ucs4_t@tie{}@var{uc})
@deftypefunx {uint32_t *} u32_strchr (const@tie{}uint32_t@tie{}*@var{str}, ucs4_t@tie{}@var{uc})
Finds the first occurrence of @var{uc} in @var{str}.
This function is similar to @posixfunc{strchr} and @posixfunc{wcschr}, except
that it operates on Unicode strings.
@end deftypefun
@deftypefun {uint8_t *} u8_strrchr (const@tie{}uint8_t@tie{}*@var{str}, ucs4_t@tie{}@var{uc})
@deftypefunx {uint16_t *} u16_strrchr (const@tie{}uint16_t@tie{}*@var{str}, ucs4_t@tie{}@var{uc})
@deftypefunx {uint32_t *} u32_strrchr (const@tie{}uint32_t@tie{}*@var{str}, ucs4_t@tie{}@var{uc})
Finds the last occurrence of @var{uc} in @var{str}.
This function is similar to @posixfunc{strrchr} and @posixfunc{wcsrchr}, except
that it operates on Unicode strings.
@end deftypefun
The following functions search for the first occurrence of some Unicode
character in or outside a given set of Unicode characters.
@deftypefun size_t u8_strcspn (const@tie{}uint8_t@tie{}*@var{str}, const@tie{}uint8_t@tie{}*@var{reject})
@deftypefunx size_t u16_strcspn (const@tie{}uint16_t@tie{}*@var{str}, const@tie{}uint16_t@tie{}*@var{reject})
@deftypefunx size_t u32_strcspn (const@tie{}uint32_t@tie{}*@var{str}, const@tie{}uint32_t@tie{}*@var{reject})
Returns the length of the initial segment of @var{str} which consists entirely
of Unicode characters not in @var{reject}.
This function is similar to @posixfunc{strcspn} and @posixfunc{wcscspn}, except
that it operates on Unicode strings.
@end deftypefun
@deftypefun size_t u8_strspn (const@tie{}uint8_t@tie{}*@var{str}, const@tie{}uint8_t@tie{}*@var{accept})
@deftypefunx size_t u16_strspn (const@tie{}uint16_t@tie{}*@var{str}, const@tie{}uint16_t@tie{}*@var{accept})
@deftypefunx size_t u32_strspn (const@tie{}uint32_t@tie{}*@var{str}, const@tie{}uint32_t@tie{}*@var{accept})
Returns the length of the initial segment of @var{str} which consists entirely
of Unicode characters in @var{accept}.
This function is similar to @posixfunc{strspn} and @posixfunc{wcsspn}, except
that it operates on Unicode strings.
@end deftypefun
@deftypefun {uint8_t *} u8_strpbrk (const@tie{}uint8_t@tie{}*@var{str}, const@tie{}uint8_t@tie{}*@var{accept})
@deftypefunx {uint16_t *} u16_strpbrk (const@tie{}uint16_t@tie{}*@var{str}, const@tie{}uint16_t@tie{}*@var{accept})
@deftypefunx {uint32_t *} u32_strpbrk (const@tie{}uint32_t@tie{}*@var{str}, const@tie{}uint32_t@tie{}*@var{accept})
Finds the first occurrence in @var{str} of any character in @var{accept}.
This function is similar to @posixfunc{strpbrk} and @posixfunc{wcspbrk}, except
that it operates on Unicode strings.
@end deftypefun
@node Searching for a substring
@subsection Searching for a substring in a NUL terminated Unicode string
@cindex searching, for a substring
The following functions search whether a given Unicode string is a substring
of another Unicode string.
@deftypefun {uint8_t *} u8_strstr (const@tie{}uint8_t@tie{}*@var{haystack}, const@tie{}uint8_t@tie{}*@var{needle})
@deftypefunx {uint16_t *} u16_strstr (const@tie{}uint16_t@tie{}*@var{haystack}, const@tie{}uint16_t@tie{}*@var{needle})
@deftypefunx {uint32_t *} u32_strstr (const@tie{}uint32_t@tie{}*@var{haystack}, const@tie{}uint32_t@tie{}*@var{needle})
Finds the first occurrence of @var{needle} in @var{haystack}.
This function is similar to @posixfunc{strstr} and @posixfunc{wcsstr}, except
that it operates on Unicode strings.
@end deftypefun
@deftypefun bool u8_startswith (const@tie{}uint8_t@tie{}*@var{str}, const@tie{}uint8_t@tie{}*@var{prefix})
@deftypefunx bool u16_startswith (const@tie{}uint16_t@tie{}*@var{str}, const@tie{}uint16_t@tie{}*@var{prefix})
@deftypefunx bool u32_startswith (const@tie{}uint32_t@tie{}*@var{str}, const@tie{}uint32_t@tie{}*@var{prefix})
Tests whether @var{str} starts with @var{prefix}.
@end deftypefun
@deftypefun bool u8_endswith (const@tie{}uint8_t@tie{}*@var{str}, const@tie{}uint8_t@tie{}*@var{suffix})
@deftypefunx bool u16_endswith (const@tie{}uint16_t@tie{}*@var{str}, const@tie{}uint16_t@tie{}*@var{suffix})
@deftypefunx bool u32_endswith (const@tie{}uint32_t@tie{}*@var{str}, const@tie{}uint32_t@tie{}*@var{suffix})
Tests whether @var{str} ends with @var{suffix}.
@end deftypefun
@node Tokenizing
@subsection Tokenizing a NUL terminated Unicode string
The following function does one step in tokenizing a Unicode string.
@deftypefun {uint8_t *} u8_strtok (uint8_t@tie{}*@var{str}, const@tie{}uint8_t@tie{}*@var{delim}, uint8_t@tie{}**@var{ptr})
@deftypefunx {uint16_t *} u16_strtok (uint16_t@tie{}*@var{str}, const@tie{}uint16_t@tie{}*@var{delim}, uint16_t@tie{}**@var{ptr})
@deftypefunx {uint32_t *} u32_strtok (uint32_t@tie{}*@var{str}, const@tie{}uint32_t@tie{}*@var{delim}, uint32_t@tie{}**@var{ptr})
Divides @var{str} into tokens separated by characters in @var{delim}.
This function is similar to @posixfunc{strtok_r} and @posixfunc{wcstok}, except
that it operates on Unicode strings. Its interface is actually more similar to
@code{wcstok} than to @code{strtok}.
@end deftypefun
|