VirtualBox

source: vbox/trunk/include/iprt/string.h@ 81025

Last change on this file since 81025 was 80764, checked in by vboxsync, 5 years ago

IPRT: Optimized RTEnvPutEx. bugref:9341

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 139.5 KB
Line 
1/** @file
2 * IPRT - String Manipulation.
3 */
4
5/*
6 * Copyright (C) 2006-2019 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_string_h
27#define IPRT_INCLUDED_string_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/cdefs.h>
33#include <iprt/types.h>
34#include <iprt/assert.h>
35#include <iprt/stdarg.h>
36#include <iprt/errcore.h> /* for VINF_SUCCESS */
37#if defined(RT_OS_LINUX) && defined(__KERNEL__)
38 /* no C++ hacks ('new' etc) here anymore! */
39# include <linux/string.h>
40
41#elif defined(IN_XF86_MODULE) && !defined(NO_ANSIC)
42 RT_C_DECLS_BEGIN
43# include "xf86_ansic.h"
44 RT_C_DECLS_END
45
46#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
47 RT_C_DECLS_BEGIN
48# include <sys/libkern.h>
49 RT_C_DECLS_END
50
51#elif defined(RT_OS_NETBSD) && defined(_KERNEL)
52 RT_C_DECLS_BEGIN
53# include <lib/libkern/libkern.h>
54 RT_C_DECLS_END
55
56#elif defined(RT_OS_SOLARIS) && defined(_KERNEL)
57 /*
58 * Same case as with FreeBSD kernel:
59 * The string.h stuff clashes with sys/system.h
60 * ffs = find first set bit.
61 */
62# define ffs ffs_string_h
63# include <string.h>
64# undef ffs
65# undef strpbrk
66
67#else
68# include <string.h>
69#endif
70
71/*
72 * Supply prototypes for standard string functions provided by
73 * IPRT instead of the operating environment.
74 */
75#if defined(RT_OS_DARWIN) && defined(KERNEL)
76RT_C_DECLS_BEGIN
77void *memchr(const void *pv, int ch, size_t cb);
78char *strpbrk(const char *pszStr, const char *pszChars);
79RT_C_DECLS_END
80#endif
81
82#if defined(RT_OS_FREEBSD) && defined(_KERNEL)
83RT_C_DECLS_BEGIN
84char *strpbrk(const char *pszStr, const char *pszChars);
85RT_C_DECLS_END
86#endif
87
88#if defined(RT_OS_NETBSD) && defined(_KERNEL)
89RT_C_DECLS_BEGIN
90char *strpbrk(const char *pszStr, const char *pszChars);
91RT_C_DECLS_END
92#endif
93
94#if (!defined(RT_OS_LINUX) || !defined(_GNU_SOURCE)) \
95 && (!defined(RT_OS_OS2) || !defined(_GNU_SOURCE)) \
96 && !defined(RT_OS_FREEBSD) \
97 && !defined(RT_OS_NETBSD)
98RT_C_DECLS_BEGIN
99void *memrchr(const void *pv, int ch, size_t cb);
100RT_C_DECLS_END
101#endif
102
103
104/** @def RT_USE_RTC_3629
105 * When defined the UTF-8 range will stop at 0x10ffff. If not defined, the
106 * range stops at 0x7fffffff.
107 * @remarks Must be defined both when building and using the IPRT. */
108#ifdef DOXYGEN_RUNNING
109# define RT_USE_RTC_3629
110#endif
111
112
113/**
114 * Byte zero the specified object.
115 *
116 * This will use sizeof(Obj) to figure the size and will call memset, bzero
117 * or some compiler intrinsic to perform the actual zeroing.
118 *
119 * @param Obj The object to zero. Make sure to dereference pointers.
120 *
121 * @remarks Because the macro may use memset it has been placed in string.h
122 * instead of cdefs.h to avoid build issues because someone forgot
123 * to include this header.
124 *
125 * @ingroup grp_rt_cdefs
126 */
127#define RT_ZERO(Obj) RT_BZERO(&(Obj), sizeof(Obj))
128
129/**
130 * Byte zero the specified memory area.
131 *
132 * This will call memset, bzero or some compiler intrinsic to clear the
133 * specified bytes of memory.
134 *
135 * @param pv Pointer to the memory.
136 * @param cb The number of bytes to clear. Please, don't pass 0.
137 *
138 * @remarks Because the macro may use memset it has been placed in string.h
139 * instead of cdefs.h to avoid build issues because someone forgot
140 * to include this header.
141 *
142 * @ingroup grp_rt_cdefs
143 */
144#define RT_BZERO(pv, cb) do { memset((pv), 0, cb); } while (0)
145
146
147/**
148 * For copying a volatile variable to a non-volatile one.
149 * @param a_Dst The non-volatile destination variable.
150 * @param a_VolatileSrc The volatile source variable / dereferenced pointer.
151 */
152#define RT_COPY_VOLATILE(a_Dst, a_VolatileSrc) \
153 do { \
154 void const volatile *a_pvVolatileSrc_BCopy_Volatile = &(a_VolatileSrc); \
155 AssertCompile(sizeof(a_Dst) == sizeof(a_VolatileSrc)); \
156 memcpy(&(a_Dst), (void const *)a_pvVolatileSrc_BCopy_Volatile, sizeof(a_Dst)); \
157 } while (0)
158
159/**
160 * For copy a number of bytes from a volatile buffer to a non-volatile one.
161 *
162 * @param a_pDst Pointer to the destination buffer.
163 * @param a_pVolatileSrc Pointer to the volatile source buffer.
164 * @param a_cbToCopy Number of bytes to copy.
165 */
166#define RT_BCOPY_VOLATILE(a_pDst, a_pVolatileSrc, a_cbToCopy) \
167 do { \
168 void const volatile *a_pvVolatileSrc_BCopy_Volatile = (a_pVolatileSrc); \
169 memcpy((a_pDst), (void const *)a_pvVolatileSrc_BCopy_Volatile, (a_cbToCopy)); \
170 } while (0)
171
172
173/** @defgroup grp_rt_str RTStr - String Manipulation
174 * Mostly UTF-8 related helpers where the standard string functions won't do.
175 * @ingroup grp_rt
176 * @{
177 */
178
179RT_C_DECLS_BEGIN
180
181
182/**
183 * The maximum string length.
184 */
185#define RTSTR_MAX (~(size_t)0)
186
187
188/** @def RTSTR_TAG
189 * The default allocation tag used by the RTStr allocation APIs.
190 *
191 * When not defined before the inclusion of iprt/string.h, this will default to
192 * the pointer to the current file name. The string API will make of use of
193 * this as pointer to a volatile but read-only string.
194 */
195#if !defined(RTSTR_TAG) || defined(DOXYGEN_RUNNING)
196# define RTSTR_TAG (__FILE__)
197#endif
198
199
200#ifdef IN_RING3
201
202/**
203 * Allocates tmp buffer with default tag, translates pszString from UTF8 to
204 * current codepage.
205 *
206 * @returns iprt status code.
207 * @param ppszString Receives pointer of allocated native CP string.
208 * The returned pointer must be freed using RTStrFree().
209 * @param pszString UTF-8 string to convert.
210 */
211#define RTStrUtf8ToCurrentCP(ppszString, pszString) RTStrUtf8ToCurrentCPTag((ppszString), (pszString), RTSTR_TAG)
212
213/**
214 * Allocates tmp buffer with custom tag, translates pszString from UTF-8 to
215 * current codepage.
216 *
217 * @returns iprt status code.
218 * @param ppszString Receives pointer of allocated native CP string.
219 * The returned pointer must be freed using
220 * RTStrFree()., const char *pszTag
221 * @param pszString UTF-8 string to convert.
222 * @param pszTag Allocation tag used for statistics and such.
223 */
224RTR3DECL(int) RTStrUtf8ToCurrentCPTag(char **ppszString, const char *pszString, const char *pszTag);
225
226/**
227 * Allocates tmp buffer with default tag, translates pszString from UTF-8 to
228 * current codepage, extended version.
229 *
230 * @returns iprt status code.
231 * @param ppszString Receives pointer of allocated native CP string.
232 * The returned pointer must be freed using RTStrFree().
233 * @param pszString UTF-8 string to convert.
234 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
235 * when it reaches cchString or the string terminator ('\\0').
236 * Use RTSTR_MAX to translate the entire string.
237 */
238#define RTStrUtf8ToCurrentCPEx(ppszString, pszString, cchString) \
239 RTStrUtf8ToCurrentCPExTag((ppszString), (pszString), (cchString), RTSTR_TAG)
240
241/**
242 * Allocates tmp buffer with custom tag, translates pszString from UTF8 to
243 * current codepage.
244 *
245 * @returns iprt status code.
246 * @param ppszString Receives pointer of allocated native CP string.
247 * The returned pointer must be freed using
248 * RTStrFree()., const char *pszTag
249 * @param pszString UTF-8 string to convert.
250 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
251 * when it reaches cchString or the string terminator ('\\0').
252 * Use RTSTR_MAX to translate the entire string.
253 * @param pszTag Allocation tag used for statistics and such.
254 */
255RTR3DECL(int) RTStrUtf8ToCurrentCPExTag(char **ppszString, const char *pszString, size_t cchString, const char *pszTag);
256
257/**
258 * Allocates tmp buffer, translates pszString from current codepage to UTF-8.
259 *
260 * @returns iprt status code.
261 * @param ppszString Receives pointer of allocated UTF-8 string.
262 * The returned pointer must be freed using RTStrFree().
263 * @param pszString Native string to convert.
264 */
265#define RTStrCurrentCPToUtf8(ppszString, pszString) RTStrCurrentCPToUtf8Tag((ppszString), (pszString), RTSTR_TAG)
266
267/**
268 * Allocates tmp buffer, translates pszString from current codepage to UTF-8.
269 *
270 * @returns iprt status code.
271 * @param ppszString Receives pointer of allocated UTF-8 string.
272 * The returned pointer must be freed using RTStrFree().
273 * @param pszString Native string to convert.
274 * @param pszTag Allocation tag used for statistics and such.
275 */
276RTR3DECL(int) RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag);
277
278#endif /* IN_RING3 */
279
280/**
281 * Free string allocated by any of the non-UCS-2 string functions.
282 *
283 * @returns iprt status code.
284 * @param pszString Pointer to buffer with string to free.
285 * NULL is accepted.
286 */
287RTDECL(void) RTStrFree(char *pszString);
288
289/**
290 * Allocates a new copy of the given UTF-8 string (default tag).
291 *
292 * @returns Pointer to the allocated UTF-8 string.
293 * @param pszString UTF-8 string to duplicate.
294 */
295#define RTStrDup(pszString) RTStrDupTag((pszString), RTSTR_TAG)
296
297/**
298 * Allocates a new copy of the given UTF-8 string (custom tag).
299 *
300 * @returns Pointer to the allocated UTF-8 string.
301 * @param pszString UTF-8 string to duplicate.
302 * @param pszTag Allocation tag used for statistics and such.
303 */
304RTDECL(char *) RTStrDupTag(const char *pszString, const char *pszTag);
305
306/**
307 * Allocates a new copy of the given UTF-8 string (default tag).
308 *
309 * @returns iprt status code.
310 * @param ppszString Receives pointer of the allocated UTF-8 string.
311 * The returned pointer must be freed using RTStrFree().
312 * @param pszString UTF-8 string to duplicate.
313 */
314#define RTStrDupEx(ppszString, pszString) RTStrDupExTag((ppszString), (pszString), RTSTR_TAG)
315
316/**
317 * Allocates a new copy of the given UTF-8 string (custom tag).
318 *
319 * @returns iprt status code.
320 * @param ppszString Receives pointer of the allocated UTF-8 string.
321 * The returned pointer must be freed using RTStrFree().
322 * @param pszString UTF-8 string to duplicate.
323 * @param pszTag Allocation tag used for statistics and such.
324 */
325RTDECL(int) RTStrDupExTag(char **ppszString, const char *pszString, const char *pszTag);
326
327/**
328 * Allocates a new copy of the given UTF-8 substring (default tag).
329 *
330 * @returns Pointer to the allocated UTF-8 substring.
331 * @param pszString UTF-8 string to duplicate.
332 * @param cchMax The max number of chars to duplicate, not counting
333 * the terminator.
334 */
335#define RTStrDupN(pszString, cchMax) RTStrDupNTag((pszString), (cchMax), RTSTR_TAG)
336
337/**
338 * Allocates a new copy of the given UTF-8 substring (custom tag).
339 *
340 * @returns Pointer to the allocated UTF-8 substring.
341 * @param pszString UTF-8 string to duplicate.
342 * @param cchMax The max number of chars to duplicate, not counting
343 * the terminator.
344 * @param pszTag Allocation tag used for statistics and such.
345 */
346RTDECL(char *) RTStrDupNTag(const char *pszString, size_t cchMax, const char *pszTag);
347
348/**
349 * Appends a string onto an existing IPRT allocated string (default tag).
350 *
351 * @retval VINF_SUCCESS
352 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
353 * remains unchanged.
354 *
355 * @param ppsz Pointer to the string pointer. The string
356 * pointer must either be NULL or point to a string
357 * returned by an IPRT string API. (In/Out)
358 * @param pszAppend The string to append. NULL and empty strings
359 * are quietly ignored.
360 */
361#define RTStrAAppend(ppsz, pszAppend) RTStrAAppendTag((ppsz), (pszAppend), RTSTR_TAG)
362
363/**
364 * Appends a string onto an existing IPRT allocated string (custom tag).
365 *
366 * @retval VINF_SUCCESS
367 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
368 * remains unchanged.
369 *
370 * @param ppsz Pointer to the string pointer. The string
371 * pointer must either be NULL or point to a string
372 * returned by an IPRT string API. (In/Out)
373 * @param pszAppend The string to append. NULL and empty strings
374 * are quietly ignored.
375 * @param pszTag Allocation tag used for statistics and such.
376 */
377RTDECL(int) RTStrAAppendTag(char **ppsz, const char *pszAppend, const char *pszTag);
378
379/**
380 * Appends N bytes from a strings onto an existing IPRT allocated string
381 * (default tag).
382 *
383 * @retval VINF_SUCCESS
384 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
385 * remains unchanged.
386 *
387 * @param ppsz Pointer to the string pointer. The string
388 * pointer must either be NULL or point to a string
389 * returned by an IPRT string API. (In/Out)
390 * @param pszAppend The string to append. Can be NULL if cchAppend
391 * is NULL.
392 * @param cchAppend The number of chars (not code points) to append
393 * from pszAppend. Must not be more than
394 * @a pszAppend contains, except for the special
395 * value RTSTR_MAX that can be used to indicate all
396 * of @a pszAppend without having to strlen it.
397 */
398#define RTStrAAppendN(ppsz, pszAppend, cchAppend) RTStrAAppendNTag((ppsz), (pszAppend), (cchAppend), RTSTR_TAG)
399
400/**
401 * Appends N bytes from a strings onto an existing IPRT allocated string (custom
402 * tag).
403 *
404 * @retval VINF_SUCCESS
405 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
406 * remains unchanged.
407 *
408 * @param ppsz Pointer to the string pointer. The string
409 * pointer must either be NULL or point to a string
410 * returned by an IPRT string API. (In/Out)
411 * @param pszAppend The string to append. Can be NULL if cchAppend
412 * is NULL.
413 * @param cchAppend The number of chars (not code points) to append
414 * from pszAppend. Must not be more than
415 * @a pszAppend contains, except for the special
416 * value RTSTR_MAX that can be used to indicate all
417 * of @a pszAppend without having to strlen it.
418 * @param pszTag Allocation tag used for statistics and such.
419 */
420RTDECL(int) RTStrAAppendNTag(char **ppsz, const char *pszAppend, size_t cchAppend, const char *pszTag);
421
422/**
423 * Appends one or more strings onto an existing IPRT allocated string.
424 *
425 * This is a very flexible and efficient alternative to using RTStrAPrintf to
426 * combine several strings together.
427 *
428 * @retval VINF_SUCCESS
429 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
430 * remains unchanged.
431 *
432 * @param ppsz Pointer to the string pointer. The string
433 * pointer must either be NULL or point to a string
434 * returned by an IPRT string API. (In/Out)
435 * @param cPairs The number of string / length pairs in the
436 * @a va.
437 * @param va List of string (const char *) and length
438 * (size_t) pairs. The strings will be appended to
439 * the string in the first argument.
440 */
441#define RTStrAAppendExNV(ppsz, cPairs, va) RTStrAAppendExNVTag((ppsz), (cPairs), (va), RTSTR_TAG)
442
443/**
444 * Appends one or more strings onto an existing IPRT allocated string.
445 *
446 * This is a very flexible and efficient alternative to using RTStrAPrintf to
447 * combine several strings together.
448 *
449 * @retval VINF_SUCCESS
450 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
451 * remains unchanged.
452 *
453 * @param ppsz Pointer to the string pointer. The string
454 * pointer must either be NULL or point to a string
455 * returned by an IPRT string API. (In/Out)
456 * @param cPairs The number of string / length pairs in the
457 * @a va.
458 * @param va List of string (const char *) and length
459 * (size_t) pairs. The strings will be appended to
460 * the string in the first argument.
461 * @param pszTag Allocation tag used for statistics and such.
462 */
463RTDECL(int) RTStrAAppendExNVTag(char **ppsz, size_t cPairs, va_list va, const char *pszTag);
464
465/**
466 * Appends one or more strings onto an existing IPRT allocated string
467 * (untagged).
468 *
469 * This is a very flexible and efficient alternative to using RTStrAPrintf to
470 * combine several strings together.
471 *
472 * @retval VINF_SUCCESS
473 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
474 * remains unchanged.
475 *
476 * @param ppsz Pointer to the string pointer. The string
477 * pointer must either be NULL or point to a string
478 * returned by an IPRT string API. (In/Out)
479 * @param cPairs The number of string / length pairs in the
480 * ellipsis.
481 * @param ... List of string (const char *) and length
482 * (size_t) pairs. The strings will be appended to
483 * the string in the first argument.
484 */
485DECLINLINE(int) RTStrAAppendExN(char **ppsz, size_t cPairs, ...)
486{
487 int rc;
488 va_list va;
489 va_start(va, cPairs);
490 rc = RTStrAAppendExNVTag(ppsz, cPairs, va, RTSTR_TAG);
491 va_end(va);
492 return rc;
493}
494
495/**
496 * Appends one or more strings onto an existing IPRT allocated string (custom
497 * tag).
498 *
499 * This is a very flexible and efficient alternative to using RTStrAPrintf to
500 * combine several strings together.
501 *
502 * @retval VINF_SUCCESS
503 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
504 * remains unchanged.
505 *
506 * @param ppsz Pointer to the string pointer. The string
507 * pointer must either be NULL or point to a string
508 * returned by an IPRT string API. (In/Out)
509 * @param pszTag Allocation tag used for statistics and such.
510 * @param cPairs The number of string / length pairs in the
511 * ellipsis.
512 * @param ... List of string (const char *) and length
513 * (size_t) pairs. The strings will be appended to
514 * the string in the first argument.
515 */
516DECLINLINE(int) RTStrAAppendExNTag(char **ppsz, const char *pszTag, size_t cPairs, ...)
517{
518 int rc;
519 va_list va;
520 va_start(va, cPairs);
521 rc = RTStrAAppendExNVTag(ppsz, cPairs, va, pszTag);
522 va_end(va);
523 return rc;
524}
525
526/**
527 * Truncates an IPRT allocated string (default tag).
528 *
529 * @retval VINF_SUCCESS.
530 * @retval VERR_OUT_OF_RANGE if cchNew is too long. Nothing is done.
531 *
532 * @param ppsz Pointer to the string pointer. The string
533 * pointer can be NULL if @a cchNew is 0, no change
534 * is made then. If we actually reallocate the
535 * string, the string pointer might be changed by
536 * this call. (In/Out)
537 * @param cchNew The new string length (excluding the
538 * terminator). The string must be at least this
539 * long or we'll return VERR_OUT_OF_RANGE and
540 * assert on you.
541 */
542#define RTStrATruncate(ppsz, cchNew) RTStrATruncateTag((ppsz), (cchNew), RTSTR_TAG)
543
544/**
545 * Truncates an IPRT allocated string.
546 *
547 * @retval VINF_SUCCESS.
548 * @retval VERR_OUT_OF_RANGE if cchNew is too long. Nothing is done.
549 *
550 * @param ppsz Pointer to the string pointer. The string
551 * pointer can be NULL if @a cchNew is 0, no change
552 * is made then. If we actually reallocate the
553 * string, the string pointer might be changed by
554 * this call. (In/Out)
555 * @param cchNew The new string length (excluding the
556 * terminator). The string must be at least this
557 * long or we'll return VERR_OUT_OF_RANGE and
558 * assert on you.
559 * @param pszTag Allocation tag used for statistics and such.
560 */
561RTDECL(int) RTStrATruncateTag(char **ppsz, size_t cchNew, const char *pszTag);
562
563/**
564 * Allocates memory for string storage (default tag).
565 *
566 * You should normally not use this function, except if there is some very
567 * custom string handling you need doing that isn't covered by any of the other
568 * APIs.
569 *
570 * @returns Pointer to the allocated string. The first byte is always set
571 * to the string terminator char, the contents of the remainder of the
572 * memory is undefined. The string must be freed by calling RTStrFree.
573 *
574 * NULL is returned if the allocation failed. Please translate this to
575 * VERR_NO_STR_MEMORY and not VERR_NO_MEMORY. Also consider
576 * RTStrAllocEx if an IPRT status code is required.
577 *
578 * @param cb How many bytes to allocate. If this is zero, we
579 * will allocate a terminator byte anyway.
580 */
581#define RTStrAlloc(cb) RTStrAllocTag((cb), RTSTR_TAG)
582
583/**
584 * Allocates memory for string storage (custom tag).
585 *
586 * You should normally not use this function, except if there is some very
587 * custom string handling you need doing that isn't covered by any of the other
588 * APIs.
589 *
590 * @returns Pointer to the allocated string. The first byte is always set
591 * to the string terminator char, the contents of the remainder of the
592 * memory is undefined. The string must be freed by calling RTStrFree.
593 *
594 * NULL is returned if the allocation failed. Please translate this to
595 * VERR_NO_STR_MEMORY and not VERR_NO_MEMORY. Also consider
596 * RTStrAllocEx if an IPRT status code is required.
597 *
598 * @param cb How many bytes to allocate. If this is zero, we
599 * will allocate a terminator byte anyway.
600 * @param pszTag Allocation tag used for statistics and such.
601 */
602RTDECL(char *) RTStrAllocTag(size_t cb, const char *pszTag);
603
604/**
605 * Allocates memory for string storage, with status code (default tag).
606 *
607 * You should normally not use this function, except if there is some very
608 * custom string handling you need doing that isn't covered by any of the other
609 * APIs.
610 *
611 * @retval VINF_SUCCESS
612 * @retval VERR_NO_STR_MEMORY
613 *
614 * @param ppsz Where to return the allocated string. This will
615 * be set to NULL on failure. On success, the
616 * returned memory will always start with a
617 * terminator char so that it is considered a valid
618 * C string, the contents of rest of the memory is
619 * undefined.
620 * @param cb How many bytes to allocate. If this is zero, we
621 * will allocate a terminator byte anyway.
622 */
623#define RTStrAllocEx(ppsz, cb) RTStrAllocExTag((ppsz), (cb), RTSTR_TAG)
624
625/**
626 * Allocates memory for string storage, with status code (custom tag).
627 *
628 * You should normally not use this function, except if there is some very
629 * custom string handling you need doing that isn't covered by any of the other
630 * APIs.
631 *
632 * @retval VINF_SUCCESS
633 * @retval VERR_NO_STR_MEMORY
634 *
635 * @param ppsz Where to return the allocated string. This will
636 * be set to NULL on failure. On success, the
637 * returned memory will always start with a
638 * terminator char so that it is considered a valid
639 * C string, the contents of rest of the memory is
640 * undefined.
641 * @param cb How many bytes to allocate. If this is zero, we
642 * will allocate a terminator byte anyway.
643 * @param pszTag Allocation tag used for statistics and such.
644 */
645RTDECL(int) RTStrAllocExTag(char **ppsz, size_t cb, const char *pszTag);
646
647/**
648 * Reallocates the specified string (default tag).
649 *
650 * You should normally not have use this function, except perhaps to truncate a
651 * really long string you've got from some IPRT string API, but then you should
652 * use RTStrATruncate.
653 *
654 * @returns VINF_SUCCESS.
655 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
656 * remains unchanged.
657 *
658 * @param ppsz Pointer to the string variable containing the
659 * input and output string.
660 *
661 * When not freeing the string, the result will
662 * always have the last byte set to the terminator
663 * character so that when used for string
664 * truncation the result will be a valid C string
665 * (your job to keep it a valid UTF-8 string).
666 *
667 * When the input string is NULL and we're supposed
668 * to reallocate, the returned string will also
669 * have the first byte set to the terminator char
670 * so it will be a valid C string.
671 *
672 * @param cbNew When @a cbNew is zero, we'll behave like
673 * RTStrFree and @a *ppsz will be set to NULL.
674 *
675 * When not zero, this will be the new size of the
676 * memory backing the string, i.e. it includes the
677 * terminator char.
678 */
679#define RTStrRealloc(ppsz, cbNew) RTStrReallocTag((ppsz), (cbNew), RTSTR_TAG)
680
681/**
682 * Reallocates the specified string (custom tag).
683 *
684 * You should normally not have use this function, except perhaps to truncate a
685 * really long string you've got from some IPRT string API, but then you should
686 * use RTStrATruncate.
687 *
688 * @returns VINF_SUCCESS.
689 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
690 * remains unchanged.
691 *
692 * @param ppsz Pointer to the string variable containing the
693 * input and output string.
694 *
695 * When not freeing the string, the result will
696 * always have the last byte set to the terminator
697 * character so that when used for string
698 * truncation the result will be a valid C string
699 * (your job to keep it a valid UTF-8 string).
700 *
701 * When the input string is NULL and we're supposed
702 * to reallocate, the returned string will also
703 * have the first byte set to the terminator char
704 * so it will be a valid C string.
705 *
706 * @param cbNew When @a cbNew is zero, we'll behave like
707 * RTStrFree and @a *ppsz will be set to NULL.
708 *
709 * When not zero, this will be the new size of the
710 * memory backing the string, i.e. it includes the
711 * terminator char.
712 * @param pszTag Allocation tag used for statistics and such.
713 */
714RTDECL(int) RTStrReallocTag(char **ppsz, size_t cbNew, const char *pszTag);
715
716/**
717 * Validates the UTF-8 encoding of the string.
718 *
719 * @returns iprt status code.
720 * @param psz The string.
721 */
722RTDECL(int) RTStrValidateEncoding(const char *psz);
723
724/** @name Flags for RTStrValidateEncodingEx and RTUtf16ValidateEncodingEx
725 * @{
726 */
727/** Check that the string is zero terminated within the given size.
728 * VERR_BUFFER_OVERFLOW will be returned if the check fails. */
729#define RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED RT_BIT_32(0)
730/** Check that the string is exactly the given length.
731 * If it terminates early, VERR_BUFFER_UNDERFLOW will be returned. When used
732 * together with RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED, the given length must
733 * include the terminator or VERR_BUFFER_OVERFLOW will be returned. */
734#define RTSTR_VALIDATE_ENCODING_EXACT_LENGTH RT_BIT_32(1)
735/** @} */
736
737/**
738 * Validates the UTF-8 encoding of the string.
739 *
740 * @returns iprt status code.
741 * @param psz The string.
742 * @param cch The max string length (/ size). Use RTSTR_MAX to
743 * process the entire string.
744 * @param fFlags Combination of RTSTR_VALIDATE_ENCODING_XXX flags.
745 */
746RTDECL(int) RTStrValidateEncodingEx(const char *psz, size_t cch, uint32_t fFlags);
747
748/**
749 * Checks if the UTF-8 encoding is valid.
750 *
751 * @returns true / false.
752 * @param psz The string.
753 */
754RTDECL(bool) RTStrIsValidEncoding(const char *psz);
755
756/**
757 * Purge all bad UTF-8 encoding in the string, replacing it with '?'.
758 *
759 * @returns The number of bad characters (0 if nothing was done).
760 * @param psz The string to purge.
761 */
762RTDECL(size_t) RTStrPurgeEncoding(char *psz);
763
764/**
765 * Sanitizes a (valid) UTF-8 string by replacing all characters outside a white
766 * list in-place by an ASCII replacement character.
767 *
768 * Multi-byte characters will be replaced byte by byte.
769 *
770 * @returns The number of code points replaced. In the case of an incorrectly
771 * encoded string -1 will be returned, and the string is not completely
772 * processed. In the case of puszValidPairs having an odd number of
773 * code points, -1 will be also return but without any modification to
774 * the string.
775 * @param psz The string to sanitise.
776 * @param puszValidPairs A zero-terminated array of pairs of Unicode points.
777 * Each pair is the start and end point of a range,
778 * and the union of these ranges forms the white list.
779 * @param chReplacement The ASCII replacement character.
780 */
781RTDECL(ssize_t) RTStrPurgeComplementSet(char *psz, PCRTUNICP puszValidPairs, char chReplacement);
782
783/**
784 * Gets the number of code points the string is made up of, excluding
785 * the terminator.
786 *
787 *
788 * @returns Number of code points (RTUNICP).
789 * @returns 0 if the string was incorrectly encoded.
790 * @param psz The string.
791 */
792RTDECL(size_t) RTStrUniLen(const char *psz);
793
794/**
795 * Gets the number of code points the string is made up of, excluding
796 * the terminator.
797 *
798 * This function will validate the string, and incorrectly encoded UTF-8
799 * strings will be rejected.
800 *
801 * @returns iprt status code.
802 * @param psz The string.
803 * @param cch The max string length. Use RTSTR_MAX to process the entire string.
804 * @param pcuc Where to store the code point count.
805 * This is undefined on failure.
806 */
807RTDECL(int) RTStrUniLenEx(const char *psz, size_t cch, size_t *pcuc);
808
809/**
810 * Translate a UTF-8 string into an unicode string (i.e. RTUNICPs), allocating the string buffer.
811 *
812 * @returns iprt status code.
813 * @param pszString UTF-8 string to convert.
814 * @param ppUniString Receives pointer to the allocated unicode string.
815 * The returned string must be freed using RTUniFree().
816 */
817RTDECL(int) RTStrToUni(const char *pszString, PRTUNICP *ppUniString);
818
819/**
820 * Translates pszString from UTF-8 to an array of code points, allocating the result
821 * array if requested.
822 *
823 * @returns iprt status code.
824 * @param pszString UTF-8 string to convert.
825 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
826 * when it reaches cchString or the string terminator ('\\0').
827 * Use RTSTR_MAX to translate the entire string.
828 * @param ppaCps If cCps is non-zero, this must either be pointing to pointer to
829 * a buffer of the specified size, or pointer to a NULL pointer.
830 * If *ppusz is NULL or cCps is zero a buffer of at least cCps items
831 * will be allocated to hold the translated string.
832 * If a buffer was requested it must be freed using RTUtf16Free().
833 * @param cCps The number of code points in the unicode string. This includes the terminator.
834 * @param pcCps Where to store the length of the translated string,
835 * excluding the terminator. (Optional)
836 *
837 * This may be set under some error conditions,
838 * however, only for VERR_BUFFER_OVERFLOW and
839 * VERR_NO_STR_MEMORY will it contain a valid string
840 * length that can be used to resize the buffer.
841 */
842RTDECL(int) RTStrToUniEx(const char *pszString, size_t cchString, PRTUNICP *ppaCps, size_t cCps, size_t *pcCps);
843
844/**
845 * Calculates the length of the string in RTUTF16 items.
846 *
847 * This function will validate the string, and incorrectly encoded UTF-8
848 * strings will be rejected. The primary purpose of this function is to
849 * help allocate buffers for RTStrToUtf16Ex of the correct size. For most
850 * other purposes RTStrCalcUtf16LenEx() should be used.
851 *
852 * @returns Number of RTUTF16 items.
853 * @returns 0 if the string was incorrectly encoded.
854 * @param psz The string.
855 */
856RTDECL(size_t) RTStrCalcUtf16Len(const char *psz);
857
858/**
859 * Calculates the length of the string in RTUTF16 items.
860 *
861 * This function will validate the string, and incorrectly encoded UTF-8
862 * strings will be rejected.
863 *
864 * @returns iprt status code.
865 * @param psz The string.
866 * @param cch The max string length. Use RTSTR_MAX to process the entire string.
867 * @param pcwc Where to store the string length. Optional.
868 * This is undefined on failure.
869 */
870RTDECL(int) RTStrCalcUtf16LenEx(const char *psz, size_t cch, size_t *pcwc);
871
872/**
873 * Translate a UTF-8 string into a UTF-16 allocating the result buffer (default
874 * tag).
875 *
876 * @returns iprt status code.
877 * @param pszString UTF-8 string to convert.
878 * @param ppwszString Receives pointer to the allocated UTF-16 string.
879 * The returned string must be freed using RTUtf16Free().
880 */
881#define RTStrToUtf16(pszString, ppwszString) RTStrToUtf16Tag((pszString), (ppwszString), RTSTR_TAG)
882
883/**
884 * Translate a UTF-8 string into a UTF-16 allocating the result buffer (custom
885 * tag).
886 *
887 * This differs from RTStrToUtf16 in that it always produces a
888 * big-endian string.
889 *
890 * @returns iprt status code.
891 * @param pszString UTF-8 string to convert.
892 * @param ppwszString Receives pointer to the allocated UTF-16 string.
893 * The returned string must be freed using RTUtf16Free().
894 * @param pszTag Allocation tag used for statistics and such.
895 */
896RTDECL(int) RTStrToUtf16Tag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag);
897
898/**
899 * Translate a UTF-8 string into a UTF-16BE allocating the result buffer
900 * (default tag).
901 *
902 * This differs from RTStrToUtf16Tag in that it always produces a
903 * big-endian string.
904 *
905 * @returns iprt status code.
906 * @param pszString UTF-8 string to convert.
907 * @param ppwszString Receives pointer to the allocated UTF-16BE string.
908 * The returned string must be freed using RTUtf16Free().
909 */
910#define RTStrToUtf16Big(pszString, ppwszString) RTStrToUtf16BigTag((pszString), (ppwszString), RTSTR_TAG)
911
912/**
913 * Translate a UTF-8 string into a UTF-16BE allocating the result buffer (custom
914 * tag).
915 *
916 * @returns iprt status code.
917 * @param pszString UTF-8 string to convert.
918 * @param ppwszString Receives pointer to the allocated UTF-16BE string.
919 * The returned string must be freed using RTUtf16Free().
920 * @param pszTag Allocation tag used for statistics and such.
921 */
922RTDECL(int) RTStrToUtf16BigTag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag);
923
924/**
925 * Translates pszString from UTF-8 to UTF-16, allocating the result buffer if requested.
926 *
927 * @returns iprt status code.
928 * @param pszString UTF-8 string to convert.
929 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
930 * when it reaches cchString or the string terminator ('\\0').
931 * Use RTSTR_MAX to translate the entire string.
932 * @param ppwsz If cwc is non-zero, this must either be pointing to pointer to
933 * a buffer of the specified size, or pointer to a NULL pointer.
934 * If *ppwsz is NULL or cwc is zero a buffer of at least cwc items
935 * will be allocated to hold the translated string.
936 * If a buffer was requested it must be freed using RTUtf16Free().
937 * @param cwc The buffer size in RTUTF16s. This includes the terminator.
938 * @param pcwc Where to store the length of the translated string,
939 * excluding the terminator. (Optional)
940 *
941 * This may be set under some error conditions,
942 * however, only for VERR_BUFFER_OVERFLOW and
943 * VERR_NO_STR_MEMORY will it contain a valid string
944 * length that can be used to resize the buffer.
945 */
946#define RTStrToUtf16Ex(pszString, cchString, ppwsz, cwc, pcwc) \
947 RTStrToUtf16ExTag((pszString), (cchString), (ppwsz), (cwc), (pcwc), RTSTR_TAG)
948
949/**
950 * Translates pszString from UTF-8 to UTF-16, allocating the result buffer if
951 * requested (custom tag).
952 *
953 * @returns iprt status code.
954 * @param pszString UTF-8 string to convert.
955 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
956 * when it reaches cchString or the string terminator ('\\0').
957 * Use RTSTR_MAX to translate the entire string.
958 * @param ppwsz If cwc is non-zero, this must either be pointing to pointer to
959 * a buffer of the specified size, or pointer to a NULL pointer.
960 * If *ppwsz is NULL or cwc is zero a buffer of at least cwc items
961 * will be allocated to hold the translated string.
962 * If a buffer was requested it must be freed using RTUtf16Free().
963 * @param cwc The buffer size in RTUTF16s. This includes the terminator.
964 * @param pcwc Where to store the length of the translated string,
965 * excluding the terminator. (Optional)
966 *
967 * This may be set under some error conditions,
968 * however, only for VERR_BUFFER_OVERFLOW and
969 * VERR_NO_STR_MEMORY will it contain a valid string
970 * length that can be used to resize the buffer.
971 * @param pszTag Allocation tag used for statistics and such.
972 */
973RTDECL(int) RTStrToUtf16ExTag(const char *pszString, size_t cchString,
974 PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag);
975
976
977/**
978 * Translates pszString from UTF-8 to UTF-16BE, allocating the result buffer if requested.
979 *
980 * This differs from RTStrToUtf16Ex in that it always produces a
981 * big-endian string.
982 *
983 * @returns iprt status code.
984 * @param pszString UTF-8 string to convert.
985 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
986 * when it reaches cchString or the string terminator ('\\0').
987 * Use RTSTR_MAX to translate the entire string.
988 * @param ppwsz If cwc is non-zero, this must either be pointing to pointer to
989 * a buffer of the specified size, or pointer to a NULL pointer.
990 * If *ppwsz is NULL or cwc is zero a buffer of at least cwc items
991 * will be allocated to hold the translated string.
992 * If a buffer was requested it must be freed using RTUtf16Free().
993 * @param cwc The buffer size in RTUTF16s. This includes the terminator.
994 * @param pcwc Where to store the length of the translated string,
995 * excluding the terminator. (Optional)
996 *
997 * This may be set under some error conditions,
998 * however, only for VERR_BUFFER_OVERFLOW and
999 * VERR_NO_STR_MEMORY will it contain a valid string
1000 * length that can be used to resize the buffer.
1001 */
1002#define RTStrToUtf16BigEx(pszString, cchString, ppwsz, cwc, pcwc) \
1003 RTStrToUtf16BigExTag((pszString), (cchString), (ppwsz), (cwc), (pcwc), RTSTR_TAG)
1004
1005/**
1006 * Translates pszString from UTF-8 to UTF-16BE, allocating the result buffer if
1007 * requested (custom tag).
1008 *
1009 * This differs from RTStrToUtf16ExTag in that it always produces a
1010 * big-endian string.
1011 *
1012 * @returns iprt status code.
1013 * @param pszString UTF-8 string to convert.
1014 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
1015 * when it reaches cchString or the string terminator ('\\0').
1016 * Use RTSTR_MAX to translate the entire string.
1017 * @param ppwsz If cwc is non-zero, this must either be pointing to pointer to
1018 * a buffer of the specified size, or pointer to a NULL pointer.
1019 * If *ppwsz is NULL or cwc is zero a buffer of at least cwc items
1020 * will be allocated to hold the translated string.
1021 * If a buffer was requested it must be freed using RTUtf16Free().
1022 * @param cwc The buffer size in RTUTF16s. This includes the terminator.
1023 * @param pcwc Where to store the length of the translated string,
1024 * excluding the terminator. (Optional)
1025 *
1026 * This may be set under some error conditions,
1027 * however, only for VERR_BUFFER_OVERFLOW and
1028 * VERR_NO_STR_MEMORY will it contain a valid string
1029 * length that can be used to resize the buffer.
1030 * @param pszTag Allocation tag used for statistics and such.
1031 */
1032RTDECL(int) RTStrToUtf16BigExTag(const char *pszString, size_t cchString,
1033 PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag);
1034
1035
1036/**
1037 * Calculates the length of the string in Latin-1 characters.
1038 *
1039 * This function will validate the string, and incorrectly encoded UTF-8
1040 * strings as well as string with codepoints outside the latin-1 range will be
1041 * rejected. The primary purpose of this function is to help allocate buffers
1042 * for RTStrToLatin1Ex of the correct size. For most other purposes
1043 * RTStrCalcLatin1LenEx() should be used.
1044 *
1045 * @returns Number of Latin-1 characters.
1046 * @returns 0 if the string was incorrectly encoded.
1047 * @param psz The string.
1048 */
1049RTDECL(size_t) RTStrCalcLatin1Len(const char *psz);
1050
1051/**
1052 * Calculates the length of the string in Latin-1 characters.
1053 *
1054 * This function will validate the string, and incorrectly encoded UTF-8
1055 * strings as well as string with codepoints outside the latin-1 range will be
1056 * rejected.
1057 *
1058 * @returns iprt status code.
1059 * @param psz The string.
1060 * @param cch The max string length. Use RTSTR_MAX to process the
1061 * entire string.
1062 * @param pcch Where to store the string length. Optional.
1063 * This is undefined on failure.
1064 */
1065RTDECL(int) RTStrCalcLatin1LenEx(const char *psz, size_t cch, size_t *pcch);
1066
1067/**
1068 * Translate a UTF-8 string into a Latin-1 allocating the result buffer (default
1069 * tag).
1070 *
1071 * @returns iprt status code.
1072 * @param pszString UTF-8 string to convert.
1073 * @param ppszString Receives pointer to the allocated Latin-1 string.
1074 * The returned string must be freed using RTStrFree().
1075 */
1076#define RTStrToLatin1(pszString, ppszString) RTStrToLatin1Tag((pszString), (ppszString), RTSTR_TAG)
1077
1078/**
1079 * Translate a UTF-8 string into a Latin-1 allocating the result buffer (custom
1080 * tag).
1081 *
1082 * @returns iprt status code.
1083 * @param pszString UTF-8 string to convert.
1084 * @param ppszString Receives pointer to the allocated Latin-1 string.
1085 * The returned string must be freed using RTStrFree().
1086 * @param pszTag Allocation tag used for statistics and such.
1087 */
1088RTDECL(int) RTStrToLatin1Tag(const char *pszString, char **ppszString, const char *pszTag);
1089
1090/**
1091 * Translates pszString from UTF-8 to Latin-1, allocating the result buffer if requested.
1092 *
1093 * @returns iprt status code.
1094 * @param pszString UTF-8 string to convert.
1095 * @param cchString The maximum size in chars (the type) to convert.
1096 * The conversion stop when it reaches cchString or
1097 * the string terminator ('\\0'). Use RTSTR_MAX to
1098 * translate the entire string.
1099 * @param ppsz If cch is non-zero, this must either be pointing to
1100 * pointer to a buffer of the specified size, or
1101 * pointer to a NULL pointer. If *ppsz is NULL or cch
1102 * is zero a buffer of at least cch items will be
1103 * allocated to hold the translated string. If a
1104 * buffer was requested it must be freed using
1105 * RTStrFree().
1106 * @param cch The buffer size in bytes. This includes the
1107 * terminator.
1108 * @param pcch Where to store the length of the translated string,
1109 * excluding the terminator. (Optional)
1110 *
1111 * This may be set under some error conditions,
1112 * however, only for VERR_BUFFER_OVERFLOW and
1113 * VERR_NO_STR_MEMORY will it contain a valid string
1114 * length that can be used to resize the buffer.
1115 */
1116#define RTStrToLatin1Ex(pszString, cchString, ppsz, cch, pcch) \
1117 RTStrToLatin1ExTag((pszString), (cchString), (ppsz), (cch), (pcch), RTSTR_TAG)
1118
1119/**
1120 * Translates pszString from UTF-8 to Latin1, allocating the result buffer if
1121 * requested (custom tag).
1122 *
1123 * @returns iprt status code.
1124 * @param pszString UTF-8 string to convert.
1125 * @param cchString The maximum size in chars (the type) to convert.
1126 * The conversion stop when it reaches cchString or
1127 * the string terminator ('\\0'). Use RTSTR_MAX to
1128 * translate the entire string.
1129 * @param ppsz If cch is non-zero, this must either be pointing to
1130 * pointer to a buffer of the specified size, or
1131 * pointer to a NULL pointer. If *ppsz is NULL or cch
1132 * is zero a buffer of at least cch items will be
1133 * allocated to hold the translated string. If a
1134 * buffer was requested it must be freed using
1135 * RTStrFree().
1136 * @param cch The buffer size in bytes. This includes the
1137 * terminator.
1138 * @param pcch Where to store the length of the translated string,
1139 * excluding the terminator. (Optional)
1140 *
1141 * This may be set under some error conditions,
1142 * however, only for VERR_BUFFER_OVERFLOW and
1143 * VERR_NO_STR_MEMORY will it contain a valid string
1144 * length that can be used to resize the buffer.
1145 * @param pszTag Allocation tag used for statistics and such.
1146 */
1147RTDECL(int) RTStrToLatin1ExTag(const char *pszString, size_t cchString, char **ppsz, size_t cch, size_t *pcch, const char *pszTag);
1148
1149/**
1150 * Get the unicode code point at the given string position.
1151 *
1152 * @returns unicode code point.
1153 * @returns RTUNICP_INVALID if the encoding is invalid.
1154 * @param psz The string.
1155 */
1156RTDECL(RTUNICP) RTStrGetCpInternal(const char *psz);
1157
1158/**
1159 * Get the unicode code point at the given string position.
1160 *
1161 * @returns iprt status code
1162 * @returns VERR_INVALID_UTF8_ENCODING if the encoding is invalid.
1163 * @param ppsz The string cursor.
1164 * This is advanced one character forward on failure.
1165 * @param pCp Where to store the unicode code point.
1166 * Stores RTUNICP_INVALID if the encoding is invalid.
1167 */
1168RTDECL(int) RTStrGetCpExInternal(const char **ppsz, PRTUNICP pCp);
1169
1170/**
1171 * Get the unicode code point at the given string position for a string of a
1172 * given length.
1173 *
1174 * @returns iprt status code
1175 * @retval VERR_INVALID_UTF8_ENCODING if the encoding is invalid.
1176 * @retval VERR_END_OF_STRING if *pcch is 0. *pCp is set to RTUNICP_INVALID.
1177 *
1178 * @param ppsz The string.
1179 * @param pcch Pointer to the length of the string. This will be
1180 * decremented by the size of the code point.
1181 * @param pCp Where to store the unicode code point.
1182 * Stores RTUNICP_INVALID if the encoding is invalid.
1183 */
1184RTDECL(int) RTStrGetCpNExInternal(const char **ppsz, size_t *pcch, PRTUNICP pCp);
1185
1186/**
1187 * Put the unicode code point at the given string position
1188 * and return the pointer to the char following it.
1189 *
1190 * This function will not consider anything at or following the
1191 * buffer area pointed to by psz. It is therefore not suitable for
1192 * inserting code points into a string, only appending/overwriting.
1193 *
1194 * @returns pointer to the char following the written code point.
1195 * @param psz The string.
1196 * @param CodePoint The code point to write.
1197 * This should not be RTUNICP_INVALID or any other
1198 * character out of the UTF-8 range.
1199 *
1200 * @remark This is a worker function for RTStrPutCp().
1201 *
1202 */
1203RTDECL(char *) RTStrPutCpInternal(char *psz, RTUNICP CodePoint);
1204
1205/**
1206 * Get the unicode code point at the given string position.
1207 *
1208 * @returns unicode code point.
1209 * @returns RTUNICP_INVALID if the encoding is invalid.
1210 * @param psz The string.
1211 *
1212 * @remark We optimize this operation by using an inline function for
1213 * the most frequent and simplest sequence, the rest is
1214 * handled by RTStrGetCpInternal().
1215 */
1216DECLINLINE(RTUNICP) RTStrGetCp(const char *psz)
1217{
1218 const unsigned char uch = *(const unsigned char *)psz;
1219 if (!(uch & RT_BIT(7)))
1220 return uch;
1221 return RTStrGetCpInternal(psz);
1222}
1223
1224/**
1225 * Get the unicode code point at the given string position.
1226 *
1227 * @returns iprt status code.
1228 * @param ppsz Pointer to the string pointer. This will be updated to
1229 * point to the char following the current code point.
1230 * This is advanced one character forward on failure.
1231 * @param pCp Where to store the code point.
1232 * RTUNICP_INVALID is stored here on failure.
1233 *
1234 * @remark We optimize this operation by using an inline function for
1235 * the most frequent and simplest sequence, the rest is
1236 * handled by RTStrGetCpExInternal().
1237 */
1238DECLINLINE(int) RTStrGetCpEx(const char **ppsz, PRTUNICP pCp)
1239{
1240 const unsigned char uch = **(const unsigned char **)ppsz;
1241 if (!(uch & RT_BIT(7)))
1242 {
1243 (*ppsz)++;
1244 *pCp = uch;
1245 return VINF_SUCCESS;
1246 }
1247 return RTStrGetCpExInternal(ppsz, pCp);
1248}
1249
1250/**
1251 * Get the unicode code point at the given string position for a string of a
1252 * given maximum length.
1253 *
1254 * @returns iprt status code.
1255 * @retval VERR_INVALID_UTF8_ENCODING if the encoding is invalid.
1256 * @retval VERR_END_OF_STRING if *pcch is 0. *pCp is set to RTUNICP_INVALID.
1257 *
1258 * @param ppsz Pointer to the string pointer. This will be updated to
1259 * point to the char following the current code point.
1260 * @param pcch Pointer to the maximum string length. This will be
1261 * decremented by the size of the code point found.
1262 * @param pCp Where to store the code point.
1263 * RTUNICP_INVALID is stored here on failure.
1264 *
1265 * @remark We optimize this operation by using an inline function for
1266 * the most frequent and simplest sequence, the rest is
1267 * handled by RTStrGetCpNExInternal().
1268 */
1269DECLINLINE(int) RTStrGetCpNEx(const char **ppsz, size_t *pcch, PRTUNICP pCp)
1270{
1271 if (RT_LIKELY(*pcch != 0))
1272 {
1273 const unsigned char uch = **(const unsigned char **)ppsz;
1274 if (!(uch & RT_BIT(7)))
1275 {
1276 (*ppsz)++;
1277 (*pcch)--;
1278 *pCp = uch;
1279 return VINF_SUCCESS;
1280 }
1281 }
1282 return RTStrGetCpNExInternal(ppsz, pcch, pCp);
1283}
1284
1285/**
1286 * Get the UTF-8 size in characters of a given Unicode code point.
1287 *
1288 * The code point is expected to be a valid Unicode one, but not necessarily in
1289 * the range supported by UTF-8.
1290 *
1291 * @returns The number of chars (bytes) required to encode the code point, or
1292 * zero if there is no UTF-8 encoding.
1293 * @param CodePoint The unicode code point.
1294 */
1295DECLINLINE(size_t) RTStrCpSize(RTUNICP CodePoint)
1296{
1297 if (CodePoint < 0x00000080)
1298 return 1;
1299 if (CodePoint < 0x00000800)
1300 return 2;
1301 if (CodePoint < 0x00010000)
1302 return 3;
1303#ifdef RT_USE_RTC_3629
1304 if (CodePoint < 0x00011000)
1305 return 4;
1306#else
1307 if (CodePoint < 0x00200000)
1308 return 4;
1309 if (CodePoint < 0x04000000)
1310 return 5;
1311 if (CodePoint < 0x7fffffff)
1312 return 6;
1313#endif
1314 return 0;
1315}
1316
1317/**
1318 * Put the unicode code point at the given string position
1319 * and return the pointer to the char following it.
1320 *
1321 * This function will not consider anything at or following the
1322 * buffer area pointed to by psz. It is therefore not suitable for
1323 * inserting code points into a string, only appending/overwriting.
1324 *
1325 * @returns pointer to the char following the written code point.
1326 * @param psz The string.
1327 * @param CodePoint The code point to write.
1328 * This should not be RTUNICP_INVALID or any other
1329 * character out of the UTF-8 range.
1330 *
1331 * @remark We optimize this operation by using an inline function for
1332 * the most frequent and simplest sequence, the rest is
1333 * handled by RTStrPutCpInternal().
1334 */
1335DECLINLINE(char *) RTStrPutCp(char *psz, RTUNICP CodePoint)
1336{
1337 if (CodePoint < 0x80)
1338 {
1339 *psz++ = (unsigned char)CodePoint;
1340 return psz;
1341 }
1342 return RTStrPutCpInternal(psz, CodePoint);
1343}
1344
1345/**
1346 * Skips ahead, past the current code point.
1347 *
1348 * @returns Pointer to the char after the current code point.
1349 * @param psz Pointer to the current code point.
1350 * @remark This will not move the next valid code point, only past the current one.
1351 */
1352DECLINLINE(char *) RTStrNextCp(const char *psz)
1353{
1354 RTUNICP Cp;
1355 RTStrGetCpEx(&psz, &Cp);
1356 return (char *)psz;
1357}
1358
1359/**
1360 * Skips back to the previous code point.
1361 *
1362 * @returns Pointer to the char before the current code point.
1363 * @returns pszStart on failure.
1364 * @param pszStart Pointer to the start of the string.
1365 * @param psz Pointer to the current code point.
1366 */
1367RTDECL(char *) RTStrPrevCp(const char *pszStart, const char *psz);
1368
1369
1370/** @page pg_rt_str_format The IPRT Format Strings
1371 *
1372 * IPRT implements most of the commonly used format types and flags with the
1373 * exception of floating point which is completely missing. In addition IPRT
1374 * provides a number of IPRT specific format types for the IPRT typedefs and
1375 * other useful things. Note that several of these extensions are similar to
1376 * \%p and doesn't care much if you try add formating flags/width/precision.
1377 *
1378 *
1379 * Group 0a, The commonly used format types:
1380 * - \%s - Takes a pointer to a zero terminated string (UTF-8) and
1381 * prints it with the optionally adjustment (width, -) and
1382 * length restriction (precision).
1383 * - \%ls - Same as \%s except that the input is UTF-16 (output UTF-8).
1384 * - \%Ls - Same as \%s except that the input is UCS-32 (output UTF-8).
1385 * - \%S - Same as \%s, used to convert to current codeset but this is
1386 * now done by the streams code. Deprecated, use \%s.
1387 * - \%lS - Ditto. Deprecated, use \%ls.
1388 * - \%LS - Ditto. Deprecated, use \%Ls.
1389 * - \%c - Takes a char and prints it.
1390 * - \%d - Takes a signed integer and prints it as decimal. Thousand
1391 * separator (\'), zero padding (0), adjustment (-+), width,
1392 * precision
1393 * - \%i - Same as \%d.
1394 * - \%u - Takes an unsigned integer and prints it as decimal. Thousand
1395 * separator (\'), zero padding (0), adjustment (-+), width,
1396 * precision
1397 * - \%x - Takes an unsigned integer and prints it as lowercased
1398 * hexadecimal. The special hash (\#) flag causes a '0x'
1399 * prefixed to be printed. Zero padding (0), adjustment (-+),
1400 * width, precision.
1401 * - \%X - Same as \%x except that it is uppercased.
1402 * - \%o - Takes an unsigned (?) integer and prints it as octal. Zero
1403 * padding (0), adjustment (-+), width, precision.
1404 * - \%p - Takes a pointer (void technically) and prints it. Zero
1405 * padding (0), adjustment (-+), width, precision.
1406 *
1407 * The \%d, \%i, \%u, \%x, \%X and \%o format types support the following
1408 * argument type specifiers:
1409 * - \%ll - long long (uint64_t).
1410 * - \%L - long long (uint64_t).
1411 * - \%l - long (uint32_t, uint64_t)
1412 * - \%h - short (int16_t).
1413 * - \%hh - char (int8_t).
1414 * - \%H - char (int8_t).
1415 * - \%z - size_t.
1416 * - \%j - intmax_t (int64_t).
1417 * - \%t - ptrdiff_t.
1418 * The type in parentheses is typical sizes, however when printing those types
1419 * you are better off using the special group 2 format types below (\%RX32 and
1420 * such).
1421 *
1422 *
1423 * Group 0b, IPRT format tricks:
1424 * - %M - Replaces the format string, takes a string pointer.
1425 * - %N - Nested formatting, takes a pointer to a format string
1426 * followed by the pointer to a va_list variable. The va_list
1427 * variable will not be modified and the caller must do va_end()
1428 * on it. Make sure the va_list variable is NOT in a parameter
1429 * list or some gcc versions/targets may get it all wrong.
1430 *
1431 *
1432 * Group 1, the basic runtime typedefs (excluding those which obviously are
1433 * pointer):
1434 * - \%RTbool - Takes a bool value and prints 'true', 'false', or '!%d!'.
1435 * - \%RTfile - Takes a #RTFILE value.
1436 * - \%RTfmode - Takes a #RTFMODE value.
1437 * - \%RTfoff - Takes a #RTFOFF value.
1438 * - \%RTfp16 - Takes a #RTFAR16 value.
1439 * - \%RTfp32 - Takes a #RTFAR32 value.
1440 * - \%RTfp64 - Takes a #RTFAR64 value.
1441 * - \%RTgid - Takes a #RTGID value.
1442 * - \%RTino - Takes a #RTINODE value.
1443 * - \%RTint - Takes a #RTINT value.
1444 * - \%RTiop - Takes a #RTIOPORT value.
1445 * - \%RTldrm - Takes a #RTLDRMOD value.
1446 * - \%RTmac - Takes a #PCRTMAC pointer.
1447 * - \%RTnaddr - Takes a #PCRTNETADDR value.
1448 * - \%RTnaipv4 - Takes a #RTNETADDRIPV4 value.
1449 * - \%RTnaipv6 - Takes a #PCRTNETADDRIPV6 value.
1450 * - \%RTnthrd - Takes a #RTNATIVETHREAD value.
1451 * - \%RTnthrd - Takes a #RTNATIVETHREAD value.
1452 * - \%RTproc - Takes a #RTPROCESS value.
1453 * - \%RTptr - Takes a #RTINTPTR or #RTUINTPTR value (but not void *).
1454 * - \%RTreg - Takes a #RTCCUINTREG value.
1455 * - \%RTsel - Takes a #RTSEL value.
1456 * - \%RTsem - Takes a #RTSEMEVENT, #RTSEMEVENTMULTI, #RTSEMMUTEX, #RTSEMFASTMUTEX, or #RTSEMRW value.
1457 * - \%RTsock - Takes a #RTSOCKET value.
1458 * - \%RTthrd - Takes a #RTTHREAD value.
1459 * - \%RTuid - Takes a #RTUID value.
1460 * - \%RTuint - Takes a #RTUINT value.
1461 * - \%RTunicp - Takes a #RTUNICP value.
1462 * - \%RTutf16 - Takes a #RTUTF16 value.
1463 * - \%RTuuid - Takes a #PCRTUUID and will print the UUID as a string.
1464 * - \%RTxuint - Takes a #RTUINT or #RTINT value, formatting it as hex.
1465 * - \%RGi - Takes a #RTGCINT value.
1466 * - \%RGp - Takes a #RTGCPHYS value.
1467 * - \%RGr - Takes a #RTGCUINTREG value.
1468 * - \%RGu - Takes a #RTGCUINT value.
1469 * - \%RGv - Takes a #RTGCPTR, #RTGCINTPTR or #RTGCUINTPTR value.
1470 * - \%RGx - Takes a #RTGCUINT or #RTGCINT value, formatting it as hex.
1471 * - \%RHi - Takes a #RTHCINT value.
1472 * - \%RHp - Takes a #RTHCPHYS value.
1473 * - \%RHr - Takes a #RTHCUINTREG value.
1474 * - \%RHu - Takes a #RTHCUINT value.
1475 * - \%RHv - Takes a #RTHCPTR, #RTHCINTPTR or #RTHCUINTPTR value.
1476 * - \%RHx - Takes a #RTHCUINT or #RTHCINT value, formatting it as hex.
1477 * - \%RRv - Takes a #RTRCPTR, #RTRCINTPTR or #RTRCUINTPTR value.
1478 * - \%RCi - Takes a #RTINT value.
1479 * - \%RCp - Takes a #RTCCPHYS value.
1480 * - \%RCr - Takes a #RTCCUINTREG value.
1481 * - \%RCu - Takes a #RTUINT value.
1482 * - \%RCv - Takes a #uintptr_t, #intptr_t, void * value.
1483 * - \%RCx - Takes a #RTUINT or #RTINT value, formatting it as hex.
1484 *
1485 *
1486 * Group 2, the generic integer types which are prefered over relying on what
1487 * bit-count a 'long', 'short', or 'long long' has on a platform. This are
1488 * highly prefered for the [u]intXX_t kind of types:
1489 * - \%RI[8|16|32|64] - Signed integer value of the specifed bit count.
1490 * - \%RU[8|16|32|64] - Unsigned integer value of the specifed bit count.
1491 * - \%RX[8|16|32|64] - Hexadecimal integer value of the specifed bit count.
1492 *
1493 *
1494 * Group 3, hex dumpers and other complex stuff which requires more than simple
1495 * formatting:
1496 * - \%Rhxd - Takes a pointer to the memory which is to be dumped in typical
1497 * hex format. Use the precision to specify the length, and the width to
1498 * set the number of bytes per line. Default width and precision is 16.
1499 * - \%RhxD - Same as \%Rhxd, except that it skips duplicate lines.
1500 * - \%Rhxs - Takes a pointer to the memory to be displayed as a hex string,
1501 * i.e. a series of space separated bytes formatted as two digit hex value.
1502 * Use the precision to specify the length. Default length is 16 bytes.
1503 * The width, if specified, is ignored.
1504 * - \%RhXd - Same as \%Rhxd, but takes an additional uint64_t
1505 * value with the memory start address/offset after
1506 * the memory pointer.
1507 * - \%RhXD - Same as \%RhxD, but takes an additional uint64_t
1508 * value with the memory start address/offset after
1509 * the memory pointer.
1510 * - \%RhXs - Same as \%Rhxs, but takes an additional uint64_t
1511 * value with the memory start address/offset after
1512 * the memory pointer.
1513 *
1514 * - \%Rhcb - Human readable byte size formatting, using
1515 * binary unit prefixes (GiB, MiB and such). Takes a
1516 * 64-bit unsigned integer as input. Does one
1517 * decimal point by default, can do 0-3 via precision
1518 * field. No rounding when calculating fraction.
1519 * The space flag add a space between the value and
1520 * unit.
1521 * - \%RhcB - Same a \%Rhcb only the 'i' is skipped in the unit.
1522 * - \%Rhci - SI variant of \%Rhcb, fraction is rounded.
1523 * - \%Rhub - Human readable number formatting, using
1524 * binary unit prefixes. Takes a 64-bit unsigned
1525 * integer as input. Does one decimal point by
1526 * default, can do 0-3 via precision field. No
1527 * rounding when calculating fraction. The space
1528 * flag add a space between the value and unit.
1529 * - \%RhuB - Same a \%Rhub only the 'i' is skipped in the unit.
1530 * - \%Rhui - SI variant of \%Rhub, fraction is rounded.
1531 *
1532 * - \%Rrc - Takes an integer iprt status code as argument. Will insert the
1533 * status code define corresponding to the iprt status code.
1534 * - \%Rrs - Takes an integer iprt status code as argument. Will insert the
1535 * short description of the specified status code.
1536 * - \%Rrf - Takes an integer iprt status code as argument. Will insert the
1537 * full description of the specified status code.
1538 * - \%Rra - Takes an integer iprt status code as argument. Will insert the
1539 * status code define + full description.
1540 * - \%Rwc - Takes a long Windows error code as argument. Will insert the status
1541 * code define corresponding to the Windows error code.
1542 * - \%Rwf - Takes a long Windows error code as argument. Will insert the
1543 * full description of the specified status code.
1544 * - \%Rwa - Takes a long Windows error code as argument. Will insert the
1545 * error code define + full description.
1546 *
1547 * - \%Rhrc - Takes a COM/XPCOM status code as argument. Will insert the status
1548 * code define corresponding to the Windows error code.
1549 * - \%Rhrf - Takes a COM/XPCOM status code as argument. Will insert the
1550 * full description of the specified status code.
1551 * - \%Rhra - Takes a COM/XPCOM error code as argument. Will insert the
1552 * error code define + full description.
1553 *
1554 * - \%Rfn - Pretty printing of a function or method. It drops the
1555 * return code and parameter list.
1556 * - \%Rbn - Prints the base name. For dropping the path in
1557 * order to save space when printing a path name.
1558 *
1559 * - \%lRbs - Same as \%ls except inlut is big endian UTF-16.
1560 *
1561 * On other platforms, \%Rw? simply prints the argument in a form of 0xXXXXXXXX.
1562 *
1563 *
1564 * Group 4, structure dumpers:
1565 * - \%RDtimespec - Takes a PCRTTIMESPEC.
1566 *
1567 *
1568 * Group 5, XML / HTML, JSON and URI escapers:
1569 * - \%RMas - Takes a string pointer (const char *) and outputs
1570 * it as an attribute value with the proper escaping.
1571 * This typically ends up in double quotes.
1572 *
1573 * - \%RMes - Takes a string pointer (const char *) and outputs
1574 * it as an element with the necessary escaping.
1575 *
1576 * - \%RMjs - Takes a string pointer (const char *) and outputs
1577 * it in quotes with proper JSON escaping.
1578 *
1579 * - \%RMpa - Takes a string pointer (const char *) and outputs
1580 * it percent-encoded (RFC-3986). All reserved characters
1581 * are encoded.
1582 *
1583 * - \%RMpf - Takes a string pointer (const char *) and outputs
1584 * it percent-encoded (RFC-3986), form style. This
1585 * means '+' is used to escape space (' ') and '%2B'
1586 * is used to escape '+'.
1587 *
1588 * - \%RMpp - Takes a string pointer (const char *) and outputs
1589 * it percent-encoded (RFC-3986), path style. This
1590 * means '/' will not be escaped.
1591 *
1592 * - \%RMpq - Takes a string pointer (const char *) and outputs
1593 * it percent-encoded (RFC-3986), query style. This
1594 * means '+' will not be escaped.
1595 *
1596 *
1597 * Group 6, CPU Architecture Register dumpers:
1598 * - \%RAx86[reg] - Takes a 64-bit register value if the register is
1599 * 64-bit or smaller. Check the code wrt which
1600 * registers are implemented.
1601 *
1602 */
1603
1604#ifndef DECLARED_FNRTSTROUTPUT /* duplicated in iprt/log.h */
1605# define DECLARED_FNRTSTROUTPUT
1606/**
1607 * Output callback.
1608 *
1609 * @returns number of bytes written.
1610 * @param pvArg User argument.
1611 * @param pachChars Pointer to an array of utf-8 characters.
1612 * @param cbChars Number of bytes in the character array pointed to by pachChars.
1613 */
1614typedef DECLCALLBACK(size_t) FNRTSTROUTPUT(void *pvArg, const char *pachChars, size_t cbChars);
1615/** Pointer to callback function. */
1616typedef FNRTSTROUTPUT *PFNRTSTROUTPUT;
1617#endif
1618
1619/** @name Format flag.
1620 * These are used by RTStrFormat extensions and RTStrFormatNumber, mind
1621 * that not all flags makes sense to both of the functions.
1622 * @{ */
1623#define RTSTR_F_CAPITAL 0x0001
1624#define RTSTR_F_LEFT 0x0002
1625#define RTSTR_F_ZEROPAD 0x0004
1626#define RTSTR_F_SPECIAL 0x0008
1627#define RTSTR_F_VALSIGNED 0x0010
1628#define RTSTR_F_PLUS 0x0020
1629#define RTSTR_F_BLANK 0x0040
1630#define RTSTR_F_WIDTH 0x0080
1631#define RTSTR_F_PRECISION 0x0100
1632#define RTSTR_F_THOUSAND_SEP 0x0200
1633#define RTSTR_F_OBFUSCATE_PTR 0x0400
1634
1635#define RTSTR_F_BIT_MASK 0xf800
1636#define RTSTR_F_8BIT 0x0800
1637#define RTSTR_F_16BIT 0x1000
1638#define RTSTR_F_32BIT 0x2000
1639#define RTSTR_F_64BIT 0x4000
1640#define RTSTR_F_128BIT 0x8000
1641/** @} */
1642
1643/** @def RTSTR_GET_BIT_FLAG
1644 * Gets the bit flag for the specified type.
1645 */
1646#define RTSTR_GET_BIT_FLAG(type) \
1647 ( sizeof(type) * 8 == 32 ? RTSTR_F_32BIT \
1648 : sizeof(type) * 8 == 64 ? RTSTR_F_64BIT \
1649 : sizeof(type) * 8 == 16 ? RTSTR_F_16BIT \
1650 : sizeof(type) * 8 == 8 ? RTSTR_F_8BIT \
1651 : sizeof(type) * 8 == 128 ? RTSTR_F_128BIT \
1652 : 0)
1653
1654
1655/**
1656 * Callback to format non-standard format specifiers.
1657 *
1658 * @returns The number of bytes formatted.
1659 * @param pvArg Formatter argument.
1660 * @param pfnOutput Pointer to output function.
1661 * @param pvArgOutput Argument for the output function.
1662 * @param ppszFormat Pointer to the format string pointer. Advance this till the char
1663 * after the format specifier.
1664 * @param pArgs Pointer to the argument list. Use this to fetch the arguments.
1665 * @param cchWidth Format Width. -1 if not specified.
1666 * @param cchPrecision Format Precision. -1 if not specified.
1667 * @param fFlags Flags (RTSTR_NTFS_*).
1668 * @param chArgSize The argument size specifier, 'l' or 'L'.
1669 */
1670typedef DECLCALLBACK(size_t) FNSTRFORMAT(void *pvArg, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
1671 const char **ppszFormat, va_list *pArgs, int cchWidth,
1672 int cchPrecision, unsigned fFlags, char chArgSize);
1673/** Pointer to a FNSTRFORMAT() function. */
1674typedef FNSTRFORMAT *PFNSTRFORMAT;
1675
1676
1677/**
1678 * Partial implementation of a printf like formatter.
1679 * It doesn't do everything correct, and there is no floating point support.
1680 * However, it supports custom formats by the means of a format callback.
1681 *
1682 * @returns number of bytes formatted.
1683 * @param pfnOutput Output worker.
1684 * Called in two ways. Normally with a string and its length.
1685 * For termination, it's called with NULL for string, 0 for length.
1686 * @param pvArgOutput Argument to the output worker.
1687 * @param pfnFormat Custom format worker.
1688 * @param pvArgFormat Argument to the format worker.
1689 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
1690 * @param InArgs Argument list.
1691 */
1692RTDECL(size_t) RTStrFormatV(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, PFNSTRFORMAT pfnFormat, void *pvArgFormat,
1693 const char *pszFormat, va_list InArgs) RT_IPRT_FORMAT_ATTR(5, 0);
1694
1695/**
1696 * Partial implementation of a printf like formatter.
1697 *
1698 * It doesn't do everything correct, and there is no floating point support.
1699 * However, it supports custom formats by the means of a format callback.
1700 *
1701 * @returns number of bytes formatted.
1702 * @param pfnOutput Output worker.
1703 * Called in two ways. Normally with a string and its length.
1704 * For termination, it's called with NULL for string, 0 for length.
1705 * @param pvArgOutput Argument to the output worker.
1706 * @param pfnFormat Custom format worker.
1707 * @param pvArgFormat Argument to the format worker.
1708 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
1709 * @param ... Argument list.
1710 */
1711RTDECL(size_t) RTStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, PFNSTRFORMAT pfnFormat, void *pvArgFormat,
1712 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(5, 6);
1713
1714/**
1715 * Formats an integer number according to the parameters.
1716 *
1717 * @returns Length of the formatted number.
1718 * @param psz Pointer to output string buffer of sufficient size.
1719 * @param u64Value Value to format.
1720 * @param uiBase Number representation base.
1721 * @param cchWidth Width.
1722 * @param cchPrecision Precision.
1723 * @param fFlags Flags, RTSTR_F_XXX.
1724 */
1725RTDECL(int) RTStrFormatNumber(char *psz, uint64_t u64Value, unsigned int uiBase, signed int cchWidth, signed int cchPrecision,
1726 unsigned int fFlags);
1727
1728/**
1729 * Formats an unsigned 8-bit number.
1730 *
1731 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1732 * @param pszBuf The output buffer.
1733 * @param cbBuf The size of the output buffer.
1734 * @param u8Value The value to format.
1735 * @param uiBase Number representation base.
1736 * @param cchWidth Width.
1737 * @param cchPrecision Precision.
1738 * @param fFlags Flags, RTSTR_F_XXX.
1739 */
1740RTDECL(ssize_t) RTStrFormatU8(char *pszBuf, size_t cbBuf, uint8_t u8Value, unsigned int uiBase,
1741 signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
1742
1743/**
1744 * Formats an unsigned 16-bit number.
1745 *
1746 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1747 * @param pszBuf The output buffer.
1748 * @param cbBuf The size of the output buffer.
1749 * @param u16Value The value to format.
1750 * @param uiBase Number representation base.
1751 * @param cchWidth Width.
1752 * @param cchPrecision Precision.
1753 * @param fFlags Flags, RTSTR_F_XXX.
1754 */
1755RTDECL(ssize_t) RTStrFormatU16(char *pszBuf, size_t cbBuf, uint16_t u16Value, unsigned int uiBase,
1756 signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
1757
1758/**
1759 * Formats an unsigned 32-bit number.
1760 *
1761 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1762 * @param pszBuf The output buffer.
1763 * @param cbBuf The size of the output buffer.
1764 * @param u32Value The value to format.
1765 * @param uiBase Number representation base.
1766 * @param cchWidth Width.
1767 * @param cchPrecision Precision.
1768 * @param fFlags Flags, RTSTR_F_XXX.
1769 */
1770RTDECL(ssize_t) RTStrFormatU32(char *pszBuf, size_t cbBuf, uint32_t u32Value, unsigned int uiBase,
1771 signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
1772
1773/**
1774 * Formats an unsigned 64-bit number.
1775 *
1776 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1777 * @param pszBuf The output buffer.
1778 * @param cbBuf The size of the output buffer.
1779 * @param u64Value The value to format.
1780 * @param uiBase Number representation base.
1781 * @param cchWidth Width.
1782 * @param cchPrecision Precision.
1783 * @param fFlags Flags, RTSTR_F_XXX.
1784 */
1785RTDECL(ssize_t) RTStrFormatU64(char *pszBuf, size_t cbBuf, uint64_t u64Value, unsigned int uiBase,
1786 signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
1787
1788/**
1789 * Formats an unsigned 128-bit number.
1790 *
1791 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1792 * @param pszBuf The output buffer.
1793 * @param cbBuf The size of the output buffer.
1794 * @param pu128Value The value to format.
1795 * @param uiBase Number representation base.
1796 * @param cchWidth Width.
1797 * @param cchPrecision Precision.
1798 * @param fFlags Flags, RTSTR_F_XXX.
1799 * @remarks The current implementation is limited to base 16 and doesn't do
1800 * width or precision and probably ignores few flags too.
1801 */
1802RTDECL(ssize_t) RTStrFormatU128(char *pszBuf, size_t cbBuf, PCRTUINT128U pu128Value, unsigned int uiBase,
1803 signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
1804
1805/**
1806 * Formats an unsigned 256-bit number.
1807 *
1808 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1809 * @param pszBuf The output buffer.
1810 * @param cbBuf The size of the output buffer.
1811 * @param pu256Value The value to format.
1812 * @param uiBase Number representation base.
1813 * @param cchWidth Width.
1814 * @param cchPrecision Precision.
1815 * @param fFlags Flags, RTSTR_F_XXX.
1816 * @remarks The current implementation is limited to base 16 and doesn't do
1817 * width or precision and probably ignores few flags too.
1818 */
1819RTDECL(ssize_t) RTStrFormatU256(char *pszBuf, size_t cbBuf, PCRTUINT256U pu256Value, unsigned int uiBase,
1820 signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
1821
1822/**
1823 * Formats an unsigned 512-bit number.
1824 *
1825 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1826 * @param pszBuf The output buffer.
1827 * @param cbBuf The size of the output buffer.
1828 * @param pu512Value The value to format.
1829 * @param uiBase Number representation base.
1830 * @param cchWidth Width.
1831 * @param cchPrecision Precision.
1832 * @param fFlags Flags, RTSTR_F_XXX.
1833 * @remarks The current implementation is limited to base 16 and doesn't do
1834 * width or precision and probably ignores few flags too.
1835 */
1836RTDECL(ssize_t) RTStrFormatU512(char *pszBuf, size_t cbBuf, PCRTUINT512U pu512Value, unsigned int uiBase,
1837 signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
1838
1839
1840/**
1841 * Formats an 80-bit extended floating point number.
1842 *
1843 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1844 * @param pszBuf The output buffer.
1845 * @param cbBuf The size of the output buffer.
1846 * @param pr80Value The value to format.
1847 * @param cchWidth Width.
1848 * @param cchPrecision Precision.
1849 * @param fFlags Flags, RTSTR_F_XXX.
1850 */
1851RTDECL(ssize_t) RTStrFormatR80(char *pszBuf, size_t cbBuf, PCRTFLOAT80U pr80Value, signed int cchWidth,
1852 signed int cchPrecision, uint32_t fFlags);
1853
1854/**
1855 * Formats an 80-bit extended floating point number, version 2.
1856 *
1857 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1858 * @param pszBuf The output buffer.
1859 * @param cbBuf The size of the output buffer.
1860 * @param pr80Value The value to format.
1861 * @param cchWidth Width.
1862 * @param cchPrecision Precision.
1863 * @param fFlags Flags, RTSTR_F_XXX.
1864 */
1865RTDECL(ssize_t) RTStrFormatR80u2(char *pszBuf, size_t cbBuf, PCRTFLOAT80U2 pr80Value, signed int cchWidth,
1866 signed int cchPrecision, uint32_t fFlags);
1867
1868
1869
1870/**
1871 * Callback for formatting a type.
1872 *
1873 * This is registered using the RTStrFormatTypeRegister function and will
1874 * be called during string formatting to handle the specified %R[type].
1875 * The argument for this format type is assumed to be a pointer and it's
1876 * passed in the @a pvValue argument.
1877 *
1878 * @returns Length of the formatted output.
1879 * @param pfnOutput Output worker.
1880 * @param pvArgOutput Argument to the output worker.
1881 * @param pszType The type name.
1882 * @param pvValue The argument value.
1883 * @param cchWidth Width.
1884 * @param cchPrecision Precision.
1885 * @param fFlags Flags (NTFS_*).
1886 * @param pvUser The user argument.
1887 */
1888typedef DECLCALLBACK(size_t) FNRTSTRFORMATTYPE(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
1889 const char *pszType, void const *pvValue,
1890 int cchWidth, int cchPrecision, unsigned fFlags,
1891 void *pvUser);
1892/** Pointer to a FNRTSTRFORMATTYPE. */
1893typedef FNRTSTRFORMATTYPE *PFNRTSTRFORMATTYPE;
1894
1895
1896/**
1897 * Register a format handler for a type.
1898 *
1899 * The format handler is used to handle '%R[type]' format types, where the argument
1900 * in the vector is a pointer value (a bit restrictive, but keeps it simple).
1901 *
1902 * The caller must ensure that no other thread will be making use of any of
1903 * the dynamic formatting type facilities simultaneously with this call.
1904 *
1905 * @returns IPRT status code.
1906 * @retval VINF_SUCCESS on success.
1907 * @retval VERR_ALREADY_EXISTS if the type has already been registered.
1908 * @retval VERR_TOO_MANY_OPEN_FILES if all the type slots has been allocated already.
1909 *
1910 * @param pszType The type name.
1911 * @param pfnHandler The handler address. See FNRTSTRFORMATTYPE for details.
1912 * @param pvUser The user argument to pass to the handler. See RTStrFormatTypeSetUser
1913 * for how to update this later.
1914 */
1915RTDECL(int) RTStrFormatTypeRegister(const char *pszType, PFNRTSTRFORMATTYPE pfnHandler, void *pvUser);
1916
1917/**
1918 * Deregisters a format type.
1919 *
1920 * The caller must ensure that no other thread will be making use of any of
1921 * the dynamic formatting type facilities simultaneously with this call.
1922 *
1923 * @returns IPRT status code.
1924 * @retval VINF_SUCCESS on success.
1925 * @retval VERR_FILE_NOT_FOUND if not found.
1926 *
1927 * @param pszType The type to deregister.
1928 */
1929RTDECL(int) RTStrFormatTypeDeregister(const char *pszType);
1930
1931/**
1932 * Sets the user argument for a type.
1933 *
1934 * This can be used if a user argument needs relocating in GC.
1935 *
1936 * @returns IPRT status code.
1937 * @retval VINF_SUCCESS on success.
1938 * @retval VERR_FILE_NOT_FOUND if not found.
1939 *
1940 * @param pszType The type to update.
1941 * @param pvUser The new user argument value.
1942 */
1943RTDECL(int) RTStrFormatTypeSetUser(const char *pszType, void *pvUser);
1944
1945
1946/**
1947 * String printf.
1948 *
1949 * @returns The length of the returned string (in pszBuffer) excluding the
1950 * terminator.
1951 * @param pszBuffer Output buffer.
1952 * @param cchBuffer Size of the output buffer.
1953 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
1954 * @param args The format argument.
1955 *
1956 * @deprecated Use RTStrPrintf2V! Problematic return value on overflow.
1957 */
1958RTDECL(size_t) RTStrPrintfV(char *pszBuffer, size_t cchBuffer, const char *pszFormat, va_list args) RT_IPRT_FORMAT_ATTR(3, 0);
1959
1960/**
1961 * String printf.
1962 *
1963 * @returns The length of the returned string (in pszBuffer) excluding the
1964 * terminator.
1965 * @param pszBuffer Output buffer.
1966 * @param cchBuffer Size of the output buffer.
1967 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
1968 * @param ... The format argument.
1969 *
1970 * @deprecated Use RTStrPrintf2! Problematic return value on overflow.
1971 */
1972RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
1973
1974/**
1975 * String printf with custom formatting.
1976 *
1977 * @returns The length of the returned string (in pszBuffer) excluding the
1978 * terminator.
1979 * @param pfnFormat Pointer to handler function for the custom formats.
1980 * @param pvArg Argument to the pfnFormat function.
1981 * @param pszBuffer Output buffer.
1982 * @param cchBuffer Size of the output buffer.
1983 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
1984 * @param args The format argument.
1985 *
1986 * @deprecated Use RTStrPrintf2ExV! Problematic return value on overflow.
1987 */
1988RTDECL(size_t) RTStrPrintfExV(PFNSTRFORMAT pfnFormat, void *pvArg, char *pszBuffer, size_t cchBuffer,
1989 const char *pszFormat, va_list args) RT_IPRT_FORMAT_ATTR(5, 0);
1990
1991/**
1992 * String printf with custom formatting.
1993 *
1994 * @returns The length of the returned string (in pszBuffer) excluding the
1995 * terminator.
1996 * @param pfnFormat Pointer to handler function for the custom formats.
1997 * @param pvArg Argument to the pfnFormat function.
1998 * @param pszBuffer Output buffer.
1999 * @param cchBuffer Size of the output buffer.
2000 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2001 * @param ... The format argument.
2002 *
2003 * @deprecated Use RTStrPrintf2Ex! Problematic return value on overflow.
2004 */
2005RTDECL(size_t) RTStrPrintfEx(PFNSTRFORMAT pfnFormat, void *pvArg, char *pszBuffer, size_t cchBuffer,
2006 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(5, 6);
2007
2008/**
2009 * String printf, version 2.
2010 *
2011 * @returns On success, positive count of formatted character excluding the
2012 * terminator. On buffer overflow, negative number giving the required
2013 * buffer size (including terminator char).
2014 *
2015 * @param pszBuffer Output buffer.
2016 * @param cbBuffer Size of the output buffer.
2017 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2018 * @param args The format argument.
2019 */
2020RTDECL(ssize_t) RTStrPrintf2V(char *pszBuffer, size_t cbBuffer, const char *pszFormat, va_list args) RT_IPRT_FORMAT_ATTR(3, 0);
2021
2022/**
2023 * String printf, version 2.
2024 *
2025 * @returns On success, positive count of formatted character excluding the
2026 * terminator. On buffer overflow, negative number giving the required
2027 * buffer size (including terminator char).
2028 *
2029 * @param pszBuffer Output buffer.
2030 * @param cbBuffer Size of the output buffer.
2031 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2032 * @param ... The format argument.
2033 */
2034RTDECL(ssize_t) RTStrPrintf2(char *pszBuffer, size_t cbBuffer, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
2035
2036/**
2037 * String printf with custom formatting, version 2.
2038 *
2039 * @returns On success, positive count of formatted character excluding the
2040 * terminator. On buffer overflow, negative number giving the required
2041 * buffer size (including terminator char).
2042 *
2043 * @param pfnFormat Pointer to handler function for the custom formats.
2044 * @param pvArg Argument to the pfnFormat function.
2045 * @param pszBuffer Output buffer.
2046 * @param cbBuffer Size of the output buffer.
2047 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2048 * @param args The format argument.
2049 */
2050RTDECL(ssize_t) RTStrPrintf2ExV(PFNSTRFORMAT pfnFormat, void *pvArg, char *pszBuffer, size_t cbBuffer,
2051 const char *pszFormat, va_list args) RT_IPRT_FORMAT_ATTR(5, 0);
2052
2053/**
2054 * String printf with custom formatting, version 2.
2055 *
2056 * @returns On success, positive count of formatted character excluding the
2057 * terminator. On buffer overflow, negative number giving the required
2058 * buffer size (including terminator char).
2059 *
2060 * @param pfnFormat Pointer to handler function for the custom formats.
2061 * @param pvArg Argument to the pfnFormat function.
2062 * @param pszBuffer Output buffer.
2063 * @param cbBuffer Size of the output buffer.
2064 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2065 * @param ... The format argument.
2066 */
2067RTDECL(ssize_t) RTStrPrintf2Ex(PFNSTRFORMAT pfnFormat, void *pvArg, char *pszBuffer, size_t cbBuffer,
2068 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(5, 6);
2069
2070/**
2071 * Allocating string printf (default tag).
2072 *
2073 * @returns The length of the string in the returned *ppszBuffer excluding the
2074 * terminator.
2075 * @returns -1 on failure.
2076 * @param ppszBuffer Where to store the pointer to the allocated output buffer.
2077 * The buffer should be freed using RTStrFree().
2078 * On failure *ppszBuffer will be set to NULL.
2079 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2080 * @param args The format argument.
2081 */
2082#define RTStrAPrintfV(ppszBuffer, pszFormat, args) RTStrAPrintfVTag((ppszBuffer), (pszFormat), (args), RTSTR_TAG)
2083
2084/**
2085 * Allocating string printf (custom tag).
2086 *
2087 * @returns The length of the string in the returned *ppszBuffer excluding the
2088 * terminator.
2089 * @returns -1 on failure.
2090 * @param ppszBuffer Where to store the pointer to the allocated output buffer.
2091 * The buffer should be freed using RTStrFree().
2092 * On failure *ppszBuffer will be set to NULL.
2093 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2094 * @param args The format argument.
2095 * @param pszTag Allocation tag used for statistics and such.
2096 */
2097RTDECL(int) RTStrAPrintfVTag(char **ppszBuffer, const char *pszFormat, va_list args, const char *pszTag) RT_IPRT_FORMAT_ATTR(2, 0);
2098
2099/**
2100 * Allocating string printf.
2101 *
2102 * @returns The length of the string in the returned *ppszBuffer excluding the
2103 * terminator.
2104 * @returns -1 on failure.
2105 * @param ppszBuffer Where to store the pointer to the allocated output buffer.
2106 * The buffer should be freed using RTStrFree().
2107 * On failure *ppszBuffer will be set to NULL.
2108 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2109 * @param ... The format argument.
2110 */
2111DECLINLINE(int) RT_IPRT_FORMAT_ATTR(2, 3) RTStrAPrintf(char **ppszBuffer, const char *pszFormat, ...)
2112{
2113 int cbRet;
2114 va_list va;
2115 va_start(va, pszFormat);
2116 cbRet = RTStrAPrintfVTag(ppszBuffer, pszFormat, va, RTSTR_TAG);
2117 va_end(va);
2118 return cbRet;
2119}
2120
2121/**
2122 * Allocating string printf (custom tag).
2123 *
2124 * @returns The length of the string in the returned *ppszBuffer excluding the
2125 * terminator.
2126 * @returns -1 on failure.
2127 * @param ppszBuffer Where to store the pointer to the allocated output buffer.
2128 * The buffer should be freed using RTStrFree().
2129 * On failure *ppszBuffer will be set to NULL.
2130 * @param pszTag Allocation tag used for statistics and such.
2131 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2132 * @param ... The format argument.
2133 */
2134DECLINLINE(int) RT_IPRT_FORMAT_ATTR(3, 4) RTStrAPrintfTag(char **ppszBuffer, const char *pszTag, const char *pszFormat, ...)
2135{
2136 int cbRet;
2137 va_list va;
2138 va_start(va, pszFormat);
2139 cbRet = RTStrAPrintfVTag(ppszBuffer, pszFormat, va, pszTag);
2140 va_end(va);
2141 return cbRet;
2142}
2143
2144/**
2145 * Allocating string printf, version 2.
2146 *
2147 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
2148 * memory.
2149 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2150 * @param args The format argument.
2151 */
2152#define RTStrAPrintf2V(pszFormat, args) RTStrAPrintf2VTag((pszFormat), (args), RTSTR_TAG)
2153
2154/**
2155 * Allocating string printf, version 2.
2156 *
2157 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
2158 * memory.
2159 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2160 * @param args The format argument.
2161 * @param pszTag Allocation tag used for statistics and such.
2162 */
2163RTDECL(char *) RTStrAPrintf2VTag(const char *pszFormat, va_list args, const char *pszTag) RT_IPRT_FORMAT_ATTR(1, 0);
2164
2165/**
2166 * Allocating string printf, version 2 (default tag).
2167 *
2168 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
2169 * memory.
2170 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2171 * @param ... The format argument.
2172 */
2173DECLINLINE(char *) RT_IPRT_FORMAT_ATTR(1, 2) RTStrAPrintf2(const char *pszFormat, ...)
2174{
2175 char *pszRet;
2176 va_list va;
2177 va_start(va, pszFormat);
2178 pszRet = RTStrAPrintf2VTag(pszFormat, va, RTSTR_TAG);
2179 va_end(va);
2180 return pszRet;
2181}
2182
2183/**
2184 * Allocating string printf, version 2 (custom tag).
2185 *
2186 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
2187 * memory.
2188 * @param pszTag Allocation tag used for statistics and such.
2189 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2190 * @param ... The format argument.
2191 */
2192DECLINLINE(char *) RT_IPRT_FORMAT_ATTR(2, 3) RTStrAPrintf2Tag(const char *pszTag, const char *pszFormat, ...)
2193{
2194 char *pszRet;
2195 va_list va;
2196 va_start(va, pszFormat);
2197 pszRet = RTStrAPrintf2VTag(pszFormat, va, pszTag);
2198 va_end(va);
2199 return pszRet;
2200}
2201
2202/**
2203 * Strips blankspaces from both ends of the string.
2204 *
2205 * @returns Pointer to first non-blank char in the string.
2206 * @param psz The string to strip.
2207 */
2208RTDECL(char *) RTStrStrip(char *psz);
2209
2210/**
2211 * Strips blankspaces from the start of the string.
2212 *
2213 * @returns Pointer to first non-blank char in the string.
2214 * @param psz The string to strip.
2215 */
2216RTDECL(char *) RTStrStripL(const char *psz);
2217
2218/**
2219 * Strips blankspaces from the end of the string.
2220 *
2221 * @returns psz.
2222 * @param psz The string to strip.
2223 */
2224RTDECL(char *) RTStrStripR(char *psz);
2225
2226/**
2227 * String copy with overflow handling.
2228 *
2229 * @retval VINF_SUCCESS on success.
2230 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2231 * buffer will contain as much of the string as it can hold, fully
2232 * terminated.
2233 *
2234 * @param pszDst The destination buffer.
2235 * @param cbDst The size of the destination buffer (in bytes).
2236 * @param pszSrc The source string. NULL is not OK.
2237 */
2238RTDECL(int) RTStrCopy(char *pszDst, size_t cbDst, const char *pszSrc);
2239
2240/**
2241 * String copy with overflow handling.
2242 *
2243 * @retval VINF_SUCCESS on success.
2244 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2245 * buffer will contain as much of the string as it can hold, fully
2246 * terminated.
2247 *
2248 * @param pszDst The destination buffer.
2249 * @param cbDst The size of the destination buffer (in bytes).
2250 * @param pszSrc The source string. NULL is not OK.
2251 * @param cchSrcMax The maximum number of chars (not code points) to
2252 * copy from the source string, not counting the
2253 * terminator as usual.
2254 */
2255RTDECL(int) RTStrCopyEx(char *pszDst, size_t cbDst, const char *pszSrc, size_t cchSrcMax);
2256
2257/**
2258 * String copy with overflow handling and buffer advancing.
2259 *
2260 * @retval VINF_SUCCESS on success.
2261 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2262 * buffer will contain as much of the string as it can hold, fully
2263 * terminated.
2264 *
2265 * @param ppszDst Pointer to the destination buffer pointer.
2266 * This will be advanced to the end of the copied
2267 * bytes (points at the terminator). This is also
2268 * updated on overflow.
2269 * @param pcbDst Pointer to the destination buffer size
2270 * variable. This will be updated in accord with
2271 * the buffer pointer.
2272 * @param pszSrc The source string. NULL is not OK.
2273 */
2274RTDECL(int) RTStrCopyP(char **ppszDst, size_t *pcbDst, const char *pszSrc);
2275
2276/**
2277 * String copy with overflow handling.
2278 *
2279 * @retval VINF_SUCCESS on success.
2280 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2281 * buffer will contain as much of the string as it can hold, fully
2282 * terminated.
2283 *
2284 * @param ppszDst Pointer to the destination buffer pointer.
2285 * This will be advanced to the end of the copied
2286 * bytes (points at the terminator). This is also
2287 * updated on overflow.
2288 * @param pcbDst Pointer to the destination buffer size
2289 * variable. This will be updated in accord with
2290 * the buffer pointer.
2291 * @param pszSrc The source string. NULL is not OK.
2292 * @param cchSrcMax The maximum number of chars (not code points) to
2293 * copy from the source string, not counting the
2294 * terminator as usual.
2295 */
2296RTDECL(int) RTStrCopyPEx(char **ppszDst, size_t *pcbDst, const char *pszSrc, size_t cchSrcMax);
2297
2298/**
2299 * String concatenation with overflow handling.
2300 *
2301 * @retval VINF_SUCCESS on success.
2302 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2303 * buffer will contain as much of the string as it can hold, fully
2304 * terminated.
2305 *
2306 * @param pszDst The destination buffer.
2307 * @param cbDst The size of the destination buffer (in bytes).
2308 * @param pszSrc The source string. NULL is not OK.
2309 */
2310RTDECL(int) RTStrCat(char *pszDst, size_t cbDst, const char *pszSrc);
2311
2312/**
2313 * String concatenation with overflow handling.
2314 *
2315 * @retval VINF_SUCCESS on success.
2316 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2317 * buffer will contain as much of the string as it can hold, fully
2318 * terminated.
2319 *
2320 * @param pszDst The destination buffer.
2321 * @param cbDst The size of the destination buffer (in bytes).
2322 * @param pszSrc The source string. NULL is not OK.
2323 * @param cchSrcMax The maximum number of chars (not code points) to
2324 * copy from the source string, not counting the
2325 * terminator as usual.
2326 */
2327RTDECL(int) RTStrCatEx(char *pszDst, size_t cbDst, const char *pszSrc, size_t cchSrcMax);
2328
2329/**
2330 * String concatenation with overflow handling.
2331 *
2332 * @retval VINF_SUCCESS on success.
2333 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2334 * buffer will contain as much of the string as it can hold, fully
2335 * terminated.
2336 *
2337 * @param ppszDst Pointer to the destination buffer pointer.
2338 * This will be advanced to the end of the copied
2339 * bytes (points at the terminator). This is also
2340 * updated on overflow.
2341 * @param pcbDst Pointer to the destination buffer size
2342 * variable. This will be updated in accord with
2343 * the buffer pointer.
2344 * @param pszSrc The source string. NULL is not OK.
2345 */
2346RTDECL(int) RTStrCatP(char **ppszDst, size_t *pcbDst, const char *pszSrc);
2347
2348/**
2349 * String concatenation with overflow handling and buffer advancing.
2350 *
2351 * @retval VINF_SUCCESS on success.
2352 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2353 * buffer will contain as much of the string as it can hold, fully
2354 * terminated.
2355 *
2356 * @param ppszDst Pointer to the destination buffer pointer.
2357 * This will be advanced to the end of the copied
2358 * bytes (points at the terminator). This is also
2359 * updated on overflow.
2360 * @param pcbDst Pointer to the destination buffer size
2361 * variable. This will be updated in accord with
2362 * the buffer pointer.
2363 * @param pszSrc The source string. NULL is not OK.
2364 * @param cchSrcMax The maximum number of chars (not code points) to
2365 * copy from the source string, not counting the
2366 * terminator as usual.
2367 */
2368RTDECL(int) RTStrCatPEx(char **ppszDst, size_t *pcbDst, const char *pszSrc, size_t cchSrcMax);
2369
2370/**
2371 * Performs a case sensitive string compare between two UTF-8 strings.
2372 *
2373 * Encoding errors are ignored by the current implementation. So, the only
2374 * difference between this and the CRT strcmp function is the handling of
2375 * NULL arguments.
2376 *
2377 * @returns < 0 if the first string less than the second string.
2378 * @returns 0 if the first string identical to the second string.
2379 * @returns > 0 if the first string greater than the second string.
2380 * @param psz1 First UTF-8 string. Null is allowed.
2381 * @param psz2 Second UTF-8 string. Null is allowed.
2382 */
2383RTDECL(int) RTStrCmp(const char *psz1, const char *psz2);
2384
2385/**
2386 * Performs a case sensitive string compare between two UTF-8 strings, given
2387 * a maximum string length.
2388 *
2389 * Encoding errors are ignored by the current implementation. So, the only
2390 * difference between this and the CRT strncmp function is the handling of
2391 * NULL arguments.
2392 *
2393 * @returns < 0 if the first string less than the second string.
2394 * @returns 0 if the first string identical to the second string.
2395 * @returns > 0 if the first string greater than the second string.
2396 * @param psz1 First UTF-8 string. Null is allowed.
2397 * @param psz2 Second UTF-8 string. Null is allowed.
2398 * @param cchMax The maximum string length
2399 */
2400RTDECL(int) RTStrNCmp(const char *psz1, const char *psz2, size_t cchMax);
2401
2402/**
2403 * Performs a case insensitive string compare between two UTF-8 strings.
2404 *
2405 * This is a simplified compare, as only the simplified lower/upper case folding
2406 * specified by the unicode specs are used. It does not consider character pairs
2407 * as they are used in some languages, just simple upper & lower case compares.
2408 *
2409 * The result is the difference between the mismatching codepoints after they
2410 * both have been lower cased.
2411 *
2412 * If the string encoding is invalid the function will assert (strict builds)
2413 * and use RTStrCmp for the remainder of the string.
2414 *
2415 * @returns < 0 if the first string less than the second string.
2416 * @returns 0 if the first string identical to the second string.
2417 * @returns > 0 if the first string greater than the second string.
2418 * @param psz1 First UTF-8 string. Null is allowed.
2419 * @param psz2 Second UTF-8 string. Null is allowed.
2420 */
2421RTDECL(int) RTStrICmp(const char *psz1, const char *psz2);
2422
2423/**
2424 * Performs a case insensitive string compare between two UTF-8 strings, given a
2425 * maximum string length.
2426 *
2427 * This is a simplified compare, as only the simplified lower/upper case folding
2428 * specified by the unicode specs are used. It does not consider character pairs
2429 * as they are used in some languages, just simple upper & lower case compares.
2430 *
2431 * The result is the difference between the mismatching codepoints after they
2432 * both have been lower cased.
2433 *
2434 * If the string encoding is invalid the function will assert (strict builds)
2435 * and use RTStrNCmp for the remainder of the string.
2436 *
2437 * @returns < 0 if the first string less than the second string.
2438 * @returns 0 if the first string identical to the second string.
2439 * @returns > 0 if the first string greater than the second string.
2440 * @param psz1 First UTF-8 string. Null is allowed.
2441 * @param psz2 Second UTF-8 string. Null is allowed.
2442 * @param cchMax Maximum string length
2443 */
2444RTDECL(int) RTStrNICmp(const char *psz1, const char *psz2, size_t cchMax);
2445
2446/**
2447 * Performs a case insensitive string compare between a UTF-8 string and a 7-bit
2448 * ASCII string.
2449 *
2450 * This is potentially faster than RTStrICmp and drags in less dependencies. It
2451 * is really handy for hardcoded inputs.
2452 *
2453 * If the string encoding is invalid the function will assert (strict builds)
2454 * and use RTStrCmp for the remainder of the string.
2455 *
2456 * @returns < 0 if the first string less than the second string.
2457 * @returns 0 if the first string identical to the second string.
2458 * @returns > 0 if the first string greater than the second string.
2459 * @param psz1 First UTF-8 string. Null is allowed.
2460 * @param psz2 Second string, 7-bit ASCII. Null is allowed.
2461 * @sa RTStrICmp, RTUtf16ICmpAscii
2462 */
2463RTDECL(int) RTStrICmpAscii(const char *psz1, const char *psz2);
2464
2465/**
2466 * Performs a case insensitive string compare between a UTF-8 string and a 7-bit
2467 * ASCII string, given a maximum string length.
2468 *
2469 * This is potentially faster than RTStrNICmp and drags in less dependencies.
2470 * It is really handy for hardcoded inputs.
2471 *
2472 * If the string encoding is invalid the function will assert (strict builds)
2473 * and use RTStrNCmp for the remainder of the string.
2474 *
2475 * @returns < 0 if the first string less than the second string.
2476 * @returns 0 if the first string identical to the second string.
2477 * @returns > 0 if the first string greater than the second string.
2478 * @param psz1 First UTF-8 string. Null is allowed.
2479 * @param psz2 Second string, 7-bit ASCII. Null is allowed.
2480 * @param cchMax Maximum string length
2481 * @sa RTStrNICmp, RTUtf16NICmpAscii
2482 */
2483RTDECL(int) RTStrNICmpAscii(const char *psz1, const char *psz2, size_t cchMax);
2484
2485/**
2486 * Checks whether @a pszString starts with @a pszStart.
2487 *
2488 * @returns true / false.
2489 * @param pszString The string to check.
2490 * @param pszStart The start string to check for.
2491 */
2492RTDECL(bool) RTStrStartsWith(const char *pszString, const char *pszStart);
2493
2494/**
2495 * Checks whether @a pszString starts with @a pszStart, case insensitive.
2496 *
2497 * @returns true / false.
2498 * @param pszString The string to check.
2499 * @param pszStart The start string to check for.
2500 */
2501RTDECL(bool) RTStrIStartsWith(const char *pszString, const char *pszStart);
2502
2503/**
2504 * Locates a case sensitive substring.
2505 *
2506 * If any of the two strings are NULL, then NULL is returned. If the needle is
2507 * an empty string, then the haystack is returned (i.e. matches anything).
2508 *
2509 * @returns Pointer to the first occurrence of the substring if found, NULL if
2510 * not.
2511 *
2512 * @param pszHaystack The string to search.
2513 * @param pszNeedle The substring to search for.
2514 *
2515 * @remarks The difference between this and strstr is the handling of NULL
2516 * pointers.
2517 */
2518RTDECL(char *) RTStrStr(const char *pszHaystack, const char *pszNeedle);
2519
2520/**
2521 * Locates a case insensitive substring.
2522 *
2523 * If any of the two strings are NULL, then NULL is returned. If the needle is
2524 * an empty string, then the haystack is returned (i.e. matches anything).
2525 *
2526 * @returns Pointer to the first occurrence of the substring if found, NULL if
2527 * not.
2528 *
2529 * @param pszHaystack The string to search.
2530 * @param pszNeedle The substring to search for.
2531 *
2532 */
2533RTDECL(char *) RTStrIStr(const char *pszHaystack, const char *pszNeedle);
2534
2535/**
2536 * Converts the string to lower case.
2537 *
2538 * @returns Pointer to the converted string.
2539 * @param psz The string to convert.
2540 */
2541RTDECL(char *) RTStrToLower(char *psz);
2542
2543/**
2544 * Converts the string to upper case.
2545 *
2546 * @returns Pointer to the converted string.
2547 * @param psz The string to convert.
2548 */
2549RTDECL(char *) RTStrToUpper(char *psz);
2550
2551/**
2552 * Checks if the string is case foldable, i.e. whether it would change if
2553 * subject to RTStrToLower or RTStrToUpper.
2554 *
2555 * @returns true / false
2556 * @param psz The string in question.
2557 */
2558RTDECL(bool) RTStrIsCaseFoldable(const char *psz);
2559
2560/**
2561 * Checks if the string is upper cased (no lower case chars in it).
2562 *
2563 * @returns true / false
2564 * @param psz The string in question.
2565 */
2566RTDECL(bool) RTStrIsUpperCased(const char *psz);
2567
2568/**
2569 * Checks if the string is lower cased (no upper case chars in it).
2570 *
2571 * @returns true / false
2572 * @param psz The string in question.
2573 */
2574RTDECL(bool) RTStrIsLowerCased(const char *psz);
2575
2576/**
2577 * Find the length of a zero-terminated byte string, given
2578 * a max string length.
2579 *
2580 * See also RTStrNLenEx.
2581 *
2582 * @returns The string length or cbMax. The returned length does not include
2583 * the zero terminator if it was found.
2584 *
2585 * @param pszString The string.
2586 * @param cchMax The max string length.
2587 */
2588RTDECL(size_t) RTStrNLen(const char *pszString, size_t cchMax);
2589
2590/**
2591 * Find the length of a zero-terminated byte string, given
2592 * a max string length.
2593 *
2594 * See also RTStrNLen.
2595 *
2596 * @returns IPRT status code.
2597 * @retval VINF_SUCCESS if the string has a length less than cchMax.
2598 * @retval VERR_BUFFER_OVERFLOW if the end of the string wasn't found
2599 * before cchMax was reached.
2600 *
2601 * @param pszString The string.
2602 * @param cchMax The max string length.
2603 * @param pcch Where to store the string length excluding the
2604 * terminator. This is set to cchMax if the terminator
2605 * isn't found.
2606 */
2607RTDECL(int) RTStrNLenEx(const char *pszString, size_t cchMax, size_t *pcch);
2608
2609RT_C_DECLS_END
2610
2611/** The maximum size argument of a memchr call. */
2612#define RTSTR_MEMCHR_MAX ((~(size_t)0 >> 1) - 15)
2613
2614/**
2615 * Find the zero terminator in a string with a limited length.
2616 *
2617 * @returns Pointer to the zero terminator.
2618 * @returns NULL if the zero terminator was not found.
2619 *
2620 * @param pszString The string.
2621 * @param cchMax The max string length. RTSTR_MAX is fine.
2622 */
2623#if defined(__cplusplus) && !defined(DOXYGEN_RUNNING)
2624DECLINLINE(char const *) RTStrEnd(char const *pszString, size_t cchMax)
2625{
2626 /* Avoid potential issues with memchr seen in glibc.
2627 * See sysdeps/x86_64/memchr.S in glibc versions older than 2.11 */
2628 while (cchMax > RTSTR_MEMCHR_MAX)
2629 {
2630 char const *pszRet = (char const *)memchr(pszString, '\0', RTSTR_MEMCHR_MAX);
2631 if (RT_LIKELY(pszRet))
2632 return pszRet;
2633 pszString += RTSTR_MEMCHR_MAX;
2634 cchMax -= RTSTR_MEMCHR_MAX;
2635 }
2636 return (char const *)memchr(pszString, '\0', cchMax);
2637}
2638
2639DECLINLINE(char *) RTStrEnd(char *pszString, size_t cchMax)
2640#else
2641DECLINLINE(char *) RTStrEnd(const char *pszString, size_t cchMax)
2642#endif
2643{
2644 /* Avoid potential issues with memchr seen in glibc.
2645 * See sysdeps/x86_64/memchr.S in glibc versions older than 2.11 */
2646 while (cchMax > RTSTR_MEMCHR_MAX)
2647 {
2648 char *pszRet = (char *)memchr(pszString, '\0', RTSTR_MEMCHR_MAX);
2649 if (RT_LIKELY(pszRet))
2650 return pszRet;
2651 pszString += RTSTR_MEMCHR_MAX;
2652 cchMax -= RTSTR_MEMCHR_MAX;
2653 }
2654 return (char *)memchr(pszString, '\0', cchMax);
2655}
2656
2657RT_C_DECLS_BEGIN
2658
2659/**
2660 * Finds the offset at which a simple character first occurs in a string.
2661 *
2662 * @returns The offset of the first occurence or the terminator offset.
2663 * @param pszHaystack The string to search.
2664 * @param chNeedle The character to search for.
2665 */
2666DECLINLINE(size_t) RTStrOffCharOrTerm(const char *pszHaystack, char chNeedle)
2667{
2668 const char *psz = pszHaystack;
2669 char ch;
2670 while ( (ch = *psz) != chNeedle
2671 && ch != '\0')
2672 psz++;
2673 return psz - pszHaystack;
2674}
2675
2676
2677/**
2678 * Matches a simple string pattern.
2679 *
2680 * @returns true if the string matches the pattern, otherwise false.
2681 *
2682 * @param pszPattern The pattern. Special chars are '*' and '?', where the
2683 * asterisk matches zero or more characters and question
2684 * mark matches exactly one character.
2685 * @param pszString The string to match against the pattern.
2686 */
2687RTDECL(bool) RTStrSimplePatternMatch(const char *pszPattern, const char *pszString);
2688
2689/**
2690 * Matches a simple string pattern, neither which needs to be zero terminated.
2691 *
2692 * This is identical to RTStrSimplePatternMatch except that you can optionally
2693 * specify the length of both the pattern and the string. The function will
2694 * stop when it hits a string terminator or either of the lengths.
2695 *
2696 * @returns true if the string matches the pattern, otherwise false.
2697 *
2698 * @param pszPattern The pattern. Special chars are '*' and '?', where the
2699 * asterisk matches zero or more characters and question
2700 * mark matches exactly one character.
2701 * @param cchPattern The pattern length. Pass RTSTR_MAX if you don't know the
2702 * length and wish to stop at the string terminator.
2703 * @param pszString The string to match against the pattern.
2704 * @param cchString The string length. Pass RTSTR_MAX if you don't know the
2705 * length and wish to match up to the string terminator.
2706 */
2707RTDECL(bool) RTStrSimplePatternNMatch(const char *pszPattern, size_t cchPattern,
2708 const char *pszString, size_t cchString);
2709
2710/**
2711 * Matches multiple patterns against a string.
2712 *
2713 * The patterns are separated by the pipe character (|).
2714 *
2715 * @returns true if the string matches the pattern, otherwise false.
2716 *
2717 * @param pszPatterns The patterns.
2718 * @param cchPatterns The lengths of the patterns to use. Pass RTSTR_MAX to
2719 * stop at the terminator.
2720 * @param pszString The string to match against the pattern.
2721 * @param cchString The string length. Pass RTSTR_MAX stop stop at the
2722 * terminator.
2723 * @param poffPattern Offset into the patterns string of the patttern that
2724 * matched. If no match, this will be set to RTSTR_MAX.
2725 * This is optional, NULL is fine.
2726 */
2727RTDECL(bool) RTStrSimplePatternMultiMatch(const char *pszPatterns, size_t cchPatterns,
2728 const char *pszString, size_t cchString,
2729 size_t *poffPattern);
2730
2731/**
2732 * Compares two version strings RTStrICmp fashion.
2733 *
2734 * The version string is split up into sections at punctuation, spaces,
2735 * underscores, dashes and plus signs. The sections are then split up into
2736 * numeric and string sub-sections. Finally, the sub-sections are compared
2737 * in a numeric or case insesntivie fashion depending on what they are.
2738 *
2739 * The following strings are considered to be equal: "1.0.0", "1.00.0", "1.0",
2740 * "1". These aren't: "1.0.0r993", "1.0", "1.0r993", "1.0_Beta3", "1.1"
2741 *
2742 * @returns < 0 if the first string less than the second string.
2743 * @returns 0 if the first string identical to the second string.
2744 * @returns > 0 if the first string greater than the second string.
2745 *
2746 * @param pszVer1 First version string to compare.
2747 * @param pszVer2 Second version string to compare first version with.
2748 */
2749RTDECL(int) RTStrVersionCompare(const char *pszVer1, const char *pszVer2);
2750
2751
2752/** @defgroup rt_str_conv String To/From Number Conversions
2753 * @{ */
2754
2755/**
2756 * Converts a string representation of a number to a 64-bit unsigned number.
2757 *
2758 * @returns iprt status code.
2759 * Warnings are used to indicate conversion problems.
2760 * @retval VWRN_NUMBER_TOO_BIG
2761 * @retval VWRN_NEGATIVE_UNSIGNED
2762 * @retval VWRN_TRAILING_CHARS
2763 * @retval VWRN_TRAILING_SPACES
2764 * @retval VINF_SUCCESS
2765 * @retval VERR_NO_DIGITS
2766 *
2767 * @param pszValue Pointer to the string value.
2768 * @param ppszNext Where to store the pointer to the first char following the number. (Optional)
2769 * @param uBase The base of the representation used.
2770 * If 0 the function will look for known prefixes before defaulting to 10.
2771 * @param pu64 Where to store the converted number. (optional)
2772 */
2773RTDECL(int) RTStrToUInt64Ex(const char *pszValue, char **ppszNext, unsigned uBase, uint64_t *pu64);
2774
2775/**
2776 * Converts a string representation of a number to a 64-bit unsigned number,
2777 * making sure the full string is converted.
2778 *
2779 * @returns iprt status code.
2780 * Warnings are used to indicate conversion problems.
2781 * @retval VWRN_NUMBER_TOO_BIG
2782 * @retval VWRN_NEGATIVE_UNSIGNED
2783 * @retval VINF_SUCCESS
2784 * @retval VERR_NO_DIGITS
2785 * @retval VERR_TRAILING_SPACES
2786 * @retval VERR_TRAILING_CHARS
2787 *
2788 * @param pszValue Pointer to the string value.
2789 * @param uBase The base of the representation used.
2790 * If 0 the function will look for known prefixes before defaulting to 10.
2791 * @param pu64 Where to store the converted number. (optional)
2792 */
2793RTDECL(int) RTStrToUInt64Full(const char *pszValue, unsigned uBase, uint64_t *pu64);
2794
2795/**
2796 * Converts a string representation of a number to a 64-bit unsigned number.
2797 * The base is guessed.
2798 *
2799 * @returns 64-bit unsigned number on success.
2800 * @returns 0 on failure.
2801 * @param pszValue Pointer to the string value.
2802 */
2803RTDECL(uint64_t) RTStrToUInt64(const char *pszValue);
2804
2805/**
2806 * Converts a string representation of a number to a 32-bit unsigned number.
2807 *
2808 * @returns iprt status code.
2809 * Warnings are used to indicate conversion problems.
2810 * @retval VWRN_NUMBER_TOO_BIG
2811 * @retval VWRN_NEGATIVE_UNSIGNED
2812 * @retval VWRN_TRAILING_CHARS
2813 * @retval VWRN_TRAILING_SPACES
2814 * @retval VINF_SUCCESS
2815 * @retval VERR_NO_DIGITS
2816 *
2817 * @param pszValue Pointer to the string value.
2818 * @param ppszNext Where to store the pointer to the first char following the number. (Optional)
2819 * @param uBase The base of the representation used.
2820 * If 0 the function will look for known prefixes before defaulting to 10.
2821 * @param pu32 Where to store the converted number. (optional)
2822 */
2823RTDECL(int) RTStrToUInt32Ex(const char *pszValue, char **ppszNext, unsigned uBase, uint32_t *pu32);
2824
2825/**
2826 * Converts a string representation of a number to a 32-bit unsigned number,
2827 * making sure the full string is converted.
2828 *
2829 * @returns iprt status code.
2830 * Warnings are used to indicate conversion problems.
2831 * @retval VWRN_NUMBER_TOO_BIG
2832 * @retval VWRN_NEGATIVE_UNSIGNED
2833 * @retval VINF_SUCCESS
2834 * @retval VERR_NO_DIGITS
2835 * @retval VERR_TRAILING_SPACES
2836 * @retval VERR_TRAILING_CHARS
2837 *
2838 * @param pszValue Pointer to the string value.
2839 * @param uBase The base of the representation used.
2840 * If 0 the function will look for known prefixes before defaulting to 10.
2841 * @param pu32 Where to store the converted number. (optional)
2842 */
2843RTDECL(int) RTStrToUInt32Full(const char *pszValue, unsigned uBase, uint32_t *pu32);
2844
2845/**
2846 * Converts a string representation of a number to a 32-bit unsigned number.
2847 * The base is guessed.
2848 *
2849 * @returns 32-bit unsigned number on success.
2850 * @returns 0 on failure.
2851 * @param pszValue Pointer to the string value.
2852 */
2853RTDECL(uint32_t) RTStrToUInt32(const char *pszValue);
2854
2855/**
2856 * Converts a string representation of a number to a 16-bit unsigned number.
2857 *
2858 * @returns iprt status code.
2859 * Warnings are used to indicate conversion problems.
2860 * @retval VWRN_NUMBER_TOO_BIG
2861 * @retval VWRN_NEGATIVE_UNSIGNED
2862 * @retval VWRN_TRAILING_CHARS
2863 * @retval VWRN_TRAILING_SPACES
2864 * @retval VINF_SUCCESS
2865 * @retval VERR_NO_DIGITS
2866 *
2867 * @param pszValue Pointer to the string value.
2868 * @param ppszNext Where to store the pointer to the first char following the number. (Optional)
2869 * @param uBase The base of the representation used.
2870 * If 0 the function will look for known prefixes before defaulting to 10.
2871 * @param pu16 Where to store the converted number. (optional)
2872 */
2873RTDECL(int) RTStrToUInt16Ex(const char *pszValue, char **ppszNext, unsigned uBase, uint16_t *pu16);
2874
2875/**
2876 * Converts a string representation of a number to a 16-bit unsigned number,
2877 * making sure the full string is converted.
2878 *
2879 * @returns iprt status code.
2880 * Warnings are used to indicate conversion problems.
2881 * @retval VWRN_NUMBER_TOO_BIG
2882 * @retval VWRN_NEGATIVE_UNSIGNED
2883 * @retval VINF_SUCCESS
2884 * @retval VERR_NO_DIGITS
2885 * @retval VERR_TRAILING_SPACES
2886 * @retval VERR_TRAILING_CHARS
2887 *
2888 * @param pszValue Pointer to the string value.
2889 * @param uBase The base of the representation used.
2890 * If 0 the function will look for known prefixes before defaulting to 10.
2891 * @param pu16 Where to store the converted number. (optional)
2892 */
2893RTDECL(int) RTStrToUInt16Full(const char *pszValue, unsigned uBase, uint16_t *pu16);
2894
2895/**
2896 * Converts a string representation of a number to a 16-bit unsigned number.
2897 * The base is guessed.
2898 *
2899 * @returns 16-bit unsigned number on success.
2900 * @returns 0 on failure.
2901 * @param pszValue Pointer to the string value.
2902 */
2903RTDECL(uint16_t) RTStrToUInt16(const char *pszValue);
2904
2905/**
2906 * Converts a string representation of a number to a 8-bit unsigned number.
2907 *
2908 * @returns iprt status code.
2909 * Warnings are used to indicate conversion problems.
2910 * @retval VWRN_NUMBER_TOO_BIG
2911 * @retval VWRN_NEGATIVE_UNSIGNED
2912 * @retval VWRN_TRAILING_CHARS
2913 * @retval VWRN_TRAILING_SPACES
2914 * @retval VINF_SUCCESS
2915 * @retval VERR_NO_DIGITS
2916 *
2917 * @param pszValue Pointer to the string value.
2918 * @param ppszNext Where to store the pointer to the first char following the number. (Optional)
2919 * @param uBase The base of the representation used.
2920 * If 0 the function will look for known prefixes before defaulting to 10.
2921 * @param pu8 Where to store the converted number. (optional)
2922 */
2923RTDECL(int) RTStrToUInt8Ex(const char *pszValue, char **ppszNext, unsigned uBase, uint8_t *pu8);
2924
2925/**
2926 * Converts a string representation of a number to a 8-bit unsigned number,
2927 * making sure the full string is converted.
2928 *
2929 * @returns iprt status code.
2930 * Warnings are used to indicate conversion problems.
2931 * @retval VWRN_NUMBER_TOO_BIG
2932 * @retval VWRN_NEGATIVE_UNSIGNED
2933 * @retval VINF_SUCCESS
2934 * @retval VERR_NO_DIGITS
2935 * @retval VERR_TRAILING_SPACES
2936 * @retval VERR_TRAILING_CHARS
2937 *
2938 * @param pszValue Pointer to the string value.
2939 * @param uBase The base of the representation used.
2940 * If 0 the function will look for known prefixes before defaulting to 10.
2941 * @param pu8 Where to store the converted number. (optional)
2942 */
2943RTDECL(int) RTStrToUInt8Full(const char *pszValue, unsigned uBase, uint8_t *pu8);
2944
2945/**
2946 * Converts a string representation of a number to a 8-bit unsigned number.
2947 * The base is guessed.
2948 *
2949 * @returns 8-bit unsigned number on success.
2950 * @returns 0 on failure.
2951 * @param pszValue Pointer to the string value.
2952 */
2953RTDECL(uint8_t) RTStrToUInt8(const char *pszValue);
2954
2955/**
2956 * Converts a string representation of a number to a 64-bit signed number.
2957 *
2958 * @returns iprt status code.
2959 * Warnings are used to indicate conversion problems.
2960 * @retval VWRN_NUMBER_TOO_BIG
2961 * @retval VWRN_TRAILING_CHARS
2962 * @retval VWRN_TRAILING_SPACES
2963 * @retval VINF_SUCCESS
2964 * @retval VERR_NO_DIGITS
2965 *
2966 * @param pszValue Pointer to the string value.
2967 * @param ppszNext Where to store the pointer to the first char following the number. (Optional)
2968 * @param uBase The base of the representation used.
2969 * If 0 the function will look for known prefixes before defaulting to 10.
2970 * @param pi64 Where to store the converted number. (optional)
2971 */
2972RTDECL(int) RTStrToInt64Ex(const char *pszValue, char **ppszNext, unsigned uBase, int64_t *pi64);
2973
2974/**
2975 * Converts a string representation of a number to a 64-bit signed number,
2976 * making sure the full string is converted.
2977 *
2978 * @returns iprt status code.
2979 * Warnings are used to indicate conversion problems.
2980 * @retval VWRN_NUMBER_TOO_BIG
2981 * @retval VINF_SUCCESS
2982 * @retval VERR_TRAILING_CHARS
2983 * @retval VERR_TRAILING_SPACES
2984 * @retval VERR_NO_DIGITS
2985 *
2986 * @param pszValue Pointer to the string value.
2987 * @param uBase The base of the representation used.
2988 * If 0 the function will look for known prefixes before defaulting to 10.
2989 * @param pi64 Where to store the converted number. (optional)
2990 */
2991RTDECL(int) RTStrToInt64Full(const char *pszValue, unsigned uBase, int64_t *pi64);
2992
2993/**
2994 * Converts a string representation of a number to a 64-bit signed number.
2995 * The base is guessed.
2996 *
2997 * @returns 64-bit signed number on success.
2998 * @returns 0 on failure.
2999 * @param pszValue Pointer to the string value.
3000 */
3001RTDECL(int64_t) RTStrToInt64(const char *pszValue);
3002
3003/**
3004 * Converts a string representation of a number to a 32-bit signed number.
3005 *
3006 * @returns iprt status code.
3007 * Warnings are used to indicate conversion problems.
3008 * @retval VWRN_NUMBER_TOO_BIG
3009 * @retval VWRN_TRAILING_CHARS
3010 * @retval VWRN_TRAILING_SPACES
3011 * @retval VINF_SUCCESS
3012 * @retval VERR_NO_DIGITS
3013 *
3014 * @param pszValue Pointer to the string value.
3015 * @param ppszNext Where to store the pointer to the first char following the number. (Optional)
3016 * @param uBase The base of the representation used.
3017 * If 0 the function will look for known prefixes before defaulting to 10.
3018 * @param pi32 Where to store the converted number. (optional)
3019 */
3020RTDECL(int) RTStrToInt32Ex(const char *pszValue, char **ppszNext, unsigned uBase, int32_t *pi32);
3021
3022/**
3023 * Converts a string representation of a number to a 32-bit signed number,
3024 * making sure the full string is converted.
3025 *
3026 * @returns iprt status code.
3027 * Warnings are used to indicate conversion problems.
3028 * @retval VWRN_NUMBER_TOO_BIG
3029 * @retval VINF_SUCCESS
3030 * @retval VERR_TRAILING_CHARS
3031 * @retval VERR_TRAILING_SPACES
3032 * @retval VERR_NO_DIGITS
3033 *
3034 * @param pszValue Pointer to the string value.
3035 * @param uBase The base of the representation used.
3036 * If 0 the function will look for known prefixes before defaulting to 10.
3037 * @param pi32 Where to store the converted number. (optional)
3038 */
3039RTDECL(int) RTStrToInt32Full(const char *pszValue, unsigned uBase, int32_t *pi32);
3040
3041/**
3042 * Converts a string representation of a number to a 32-bit signed number.
3043 * The base is guessed.
3044 *
3045 * @returns 32-bit signed number on success.
3046 * @returns 0 on failure.
3047 * @param pszValue Pointer to the string value.
3048 */
3049RTDECL(int32_t) RTStrToInt32(const char *pszValue);
3050
3051/**
3052 * Converts a string representation of a number to a 16-bit signed number.
3053 *
3054 * @returns iprt status code.
3055 * Warnings are used to indicate conversion problems.
3056 * @retval VWRN_NUMBER_TOO_BIG
3057 * @retval VWRN_TRAILING_CHARS
3058 * @retval VWRN_TRAILING_SPACES
3059 * @retval VINF_SUCCESS
3060 * @retval VERR_NO_DIGITS
3061 *
3062 * @param pszValue Pointer to the string value.
3063 * @param ppszNext Where to store the pointer to the first char following the number. (Optional)
3064 * @param uBase The base of the representation used.
3065 * If 0 the function will look for known prefixes before defaulting to 10.
3066 * @param pi16 Where to store the converted number. (optional)
3067 */
3068RTDECL(int) RTStrToInt16Ex(const char *pszValue, char **ppszNext, unsigned uBase, int16_t *pi16);
3069
3070/**
3071 * Converts a string representation of a number to a 16-bit signed number,
3072 * making sure the full string is converted.
3073 *
3074 * @returns iprt status code.
3075 * Warnings are used to indicate conversion problems.
3076 * @retval VWRN_NUMBER_TOO_BIG
3077 * @retval VINF_SUCCESS
3078 * @retval VERR_TRAILING_CHARS
3079 * @retval VERR_TRAILING_SPACES
3080 * @retval VERR_NO_DIGITS
3081 *
3082 * @param pszValue Pointer to the string value.
3083 * @param uBase The base of the representation used.
3084 * If 0 the function will look for known prefixes before defaulting to 10.
3085 * @param pi16 Where to store the converted number. (optional)
3086 */
3087RTDECL(int) RTStrToInt16Full(const char *pszValue, unsigned uBase, int16_t *pi16);
3088
3089/**
3090 * Converts a string representation of a number to a 16-bit signed number.
3091 * The base is guessed.
3092 *
3093 * @returns 16-bit signed number on success.
3094 * @returns 0 on failure.
3095 * @param pszValue Pointer to the string value.
3096 */
3097RTDECL(int16_t) RTStrToInt16(const char *pszValue);
3098
3099/**
3100 * Converts a string representation of a number to a 8-bit signed number.
3101 *
3102 * @returns iprt status code.
3103 * Warnings are used to indicate conversion problems.
3104 * @retval VWRN_NUMBER_TOO_BIG
3105 * @retval VWRN_TRAILING_CHARS
3106 * @retval VWRN_TRAILING_SPACES
3107 * @retval VINF_SUCCESS
3108 * @retval VERR_NO_DIGITS
3109 *
3110 * @param pszValue Pointer to the string value.
3111 * @param ppszNext Where to store the pointer to the first char following the number. (Optional)
3112 * @param uBase The base of the representation used.
3113 * If 0 the function will look for known prefixes before defaulting to 10.
3114 * @param pi8 Where to store the converted number. (optional)
3115 */
3116RTDECL(int) RTStrToInt8Ex(const char *pszValue, char **ppszNext, unsigned uBase, int8_t *pi8);
3117
3118/**
3119 * Converts a string representation of a number to a 8-bit signed number,
3120 * making sure the full string is converted.
3121 *
3122 * @returns iprt status code.
3123 * Warnings are used to indicate conversion problems.
3124 * @retval VWRN_NUMBER_TOO_BIG
3125 * @retval VINF_SUCCESS
3126 * @retval VERR_TRAILING_CHARS
3127 * @retval VERR_TRAILING_SPACES
3128 * @retval VERR_NO_DIGITS
3129 *
3130 * @param pszValue Pointer to the string value.
3131 * @param uBase The base of the representation used.
3132 * If 0 the function will look for known prefixes before defaulting to 10.
3133 * @param pi8 Where to store the converted number. (optional)
3134 */
3135RTDECL(int) RTStrToInt8Full(const char *pszValue, unsigned uBase, int8_t *pi8);
3136
3137/**
3138 * Converts a string representation of a number to a 8-bit signed number.
3139 * The base is guessed.
3140 *
3141 * @returns 8-bit signed number on success.
3142 * @returns 0 on failure.
3143 * @param pszValue Pointer to the string value.
3144 */
3145RTDECL(int8_t) RTStrToInt8(const char *pszValue);
3146
3147/**
3148 * Formats a buffer stream as hex bytes.
3149 *
3150 * The default is no separating spaces or line breaks or anything.
3151 *
3152 * @returns IPRT status code.
3153 * @retval VERR_INVALID_POINTER if any of the pointers are wrong.
3154 * @retval VERR_BUFFER_OVERFLOW if the buffer is insufficent to hold the bytes.
3155 *
3156 * @param pszBuf Output string buffer.
3157 * @param cbBuf The size of the output buffer.
3158 * @param pv Pointer to the bytes to stringify.
3159 * @param cb The number of bytes to stringify.
3160 * @param fFlags Combination of RTSTRPRINTHEXBYTES_F_XXX values.
3161 * @sa RTUtf16PrintHexBytes.
3162 */
3163RTDECL(int) RTStrPrintHexBytes(char *pszBuf, size_t cbBuf, void const *pv, size_t cb, uint32_t fFlags);
3164/** @name RTSTRPRINTHEXBYTES_F_XXX - flags for RTStrPrintHexBytes and RTUtf16PritnHexBytes.
3165 * @{ */
3166/** Upper case hex digits, the default is lower case. */
3167#define RTSTRPRINTHEXBYTES_F_UPPER RT_BIT(0)
3168/** Add a space between each group. */
3169#define RTSTRPRINTHEXBYTES_F_SEP_SPACE RT_BIT(1)
3170/** Add a colon between each group. */
3171#define RTSTRPRINTHEXBYTES_F_SEP_COLON RT_BIT(2)
3172/** @} */
3173
3174/**
3175 * Converts a string of hex bytes back into binary data.
3176 *
3177 * @returns IPRT status code.
3178 * @retval VERR_INVALID_POINTER if any of the pointers are wrong.
3179 * @retval VERR_BUFFER_OVERFLOW if the string contains too many hex bytes.
3180 * @retval VERR_BUFFER_UNDERFLOW if there aren't enough hex bytes to fill up
3181 * the output buffer.
3182 * @retval VERR_UNEVEN_INPUT if the input contains a half byte.
3183 * @retval VERR_NO_DIGITS
3184 * @retval VWRN_TRAILING_CHARS
3185 * @retval VWRN_TRAILING_SPACES
3186 *
3187 * @param pszHex The string containing the hex bytes.
3188 * @param pv Output buffer.
3189 * @param cb The size of the output buffer.
3190 * @param fFlags RTSTRCONVERTHEXBYTES_F_XXX.
3191 */
3192RTDECL(int) RTStrConvertHexBytes(char const *pszHex, void *pv, size_t cb, uint32_t fFlags);
3193
3194/** @name RTSTRCONVERTHEXBYTES_F_XXX - Flags for RTStrConvertHexBytes() and RTStrConvertHexBytesEx().
3195 * @{ */
3196/** Accept colon as a byte separator. */
3197#define RTSTRCONVERTHEXBYTES_F_SEP_COLON RT_BIT(0)
3198/** @} */
3199
3200/**
3201 * Converts a string of hex bytes back into binary data, extended version.
3202 *
3203 * @returns IPRT status code.
3204 * @retval VERR_INVALID_POINTER if any of the pointers are wrong.
3205 * @retval VERR_BUFFER_OVERFLOW if the string contains too many hex bytes.
3206 * @retval VERR_BUFFER_UNDERFLOW if there aren't enough hex bytes to fill up
3207 * the output buffer and *pcbReturned is NULL.
3208 * @retval VINF_BUFFER_UNDERFLOW if there aren't enough hex bytes to fill up
3209 * the output buffer and *pcbReturned is not NULL, *pcbReturned holds
3210 * the actual number of bytes.
3211 * @retval VERR_UNEVEN_INPUT if the input contains a half byte.
3212 * @retval VERR_NO_DIGITS
3213 * @retval VWRN_TRAILING_CHARS
3214 * @retval VWRN_TRAILING_SPACES
3215 *
3216 * @param pszHex The string containing the hex bytes.
3217 * @param pv Output buffer.
3218 * @param cb The size of the output buffer.
3219 * @param fFlags RTSTRCONVERTHEXBYTES_F_XXX.
3220 * @param ppszNext Set to point at where we stopped decoding hex bytes.
3221 * Optional.
3222 * @param pcbReturned Where to return the number of bytes found. Optional.
3223 */
3224RTDECL(int) RTStrConvertHexBytesEx(char const *pszHex, void *pv, size_t cb, uint32_t fFlags,
3225 const char **ppszNext, size_t *pcbReturned);
3226
3227/** @} */
3228
3229
3230/** @defgroup rt_str_space Unique String Space
3231 * @{
3232 */
3233
3234/** Pointer to a string name space container node core. */
3235typedef struct RTSTRSPACECORE *PRTSTRSPACECORE;
3236/** Pointer to a pointer to a string name space container node core. */
3237typedef PRTSTRSPACECORE *PPRTSTRSPACECORE;
3238
3239/**
3240 * String name space container node core.
3241 */
3242typedef struct RTSTRSPACECORE
3243{
3244 /** Pointer to the left leaf node. Don't touch. */
3245 PRTSTRSPACECORE pLeft;
3246 /** Pointer to the left right node. Don't touch. */
3247 PRTSTRSPACECORE pRight;
3248 /** Pointer to the list of string with the same hash key value. Don't touch. */
3249 PRTSTRSPACECORE pList;
3250 /** Hash key. Don't touch. */
3251 uint32_t Key;
3252 /** Height of this tree: max(heigth(left), heigth(right)) + 1. Don't touch */
3253 unsigned char uchHeight;
3254 /** The string length. Read only! */
3255 size_t cchString;
3256 /** Pointer to the string. Read only! */
3257 const char *pszString;
3258} RTSTRSPACECORE;
3259
3260/** String space. (Initialize with NULL.) */
3261typedef PRTSTRSPACECORE RTSTRSPACE;
3262/** Pointer to a string space. */
3263typedef PPRTSTRSPACECORE PRTSTRSPACE;
3264
3265
3266/**
3267 * Inserts a string into a unique string space.
3268 *
3269 * @returns true on success.
3270 * @returns false if the string collided with an existing string.
3271 * @param pStrSpace The space to insert it into.
3272 * @param pStr The string node.
3273 */
3274RTDECL(bool) RTStrSpaceInsert(PRTSTRSPACE pStrSpace, PRTSTRSPACECORE pStr);
3275
3276/**
3277 * Removes a string from a unique string space.
3278 *
3279 * @returns Pointer to the removed string node.
3280 * @returns NULL if the string was not found in the string space.
3281 * @param pStrSpace The space to remove it from.
3282 * @param pszString The string to remove.
3283 */
3284RTDECL(PRTSTRSPACECORE) RTStrSpaceRemove(PRTSTRSPACE pStrSpace, const char *pszString);
3285
3286/**
3287 * Gets a string from a unique string space.
3288 *
3289 * @returns Pointer to the string node.
3290 * @returns NULL if the string was not found in the string space.
3291 * @param pStrSpace The space to get it from.
3292 * @param pszString The string to get.
3293 */
3294RTDECL(PRTSTRSPACECORE) RTStrSpaceGet(PRTSTRSPACE pStrSpace, const char *pszString);
3295
3296/**
3297 * Gets a string from a unique string space.
3298 *
3299 * @returns Pointer to the string node.
3300 * @returns NULL if the string was not found in the string space.
3301 * @param pStrSpace The space to get it from.
3302 * @param pszString The string to get.
3303 * @param cchMax The max string length to evaluate. Passing
3304 * RTSTR_MAX is ok and makes it behave just like
3305 * RTStrSpaceGet.
3306 */
3307RTDECL(PRTSTRSPACECORE) RTStrSpaceGetN(PRTSTRSPACE pStrSpace, const char *pszString, size_t cchMax);
3308
3309/**
3310 * Callback function for RTStrSpaceEnumerate() and RTStrSpaceDestroy().
3311 *
3312 * @returns 0 on continue.
3313 * @returns Non-zero to aborts the operation.
3314 * @param pStr The string node
3315 * @param pvUser The user specified argument.
3316 */
3317typedef DECLCALLBACK(int) FNRTSTRSPACECALLBACK(PRTSTRSPACECORE pStr, void *pvUser);
3318/** Pointer to callback function for RTStrSpaceEnumerate() and RTStrSpaceDestroy(). */
3319typedef FNRTSTRSPACECALLBACK *PFNRTSTRSPACECALLBACK;
3320
3321/**
3322 * Destroys the string space.
3323 *
3324 * The caller supplies a callback which will be called for each of the string
3325 * nodes in for freeing their memory and other resources.
3326 *
3327 * @returns 0 or what ever non-zero return value pfnCallback returned
3328 * when aborting the destruction.
3329 * @param pStrSpace The space to destroy.
3330 * @param pfnCallback The callback.
3331 * @param pvUser The user argument.
3332 */
3333RTDECL(int) RTStrSpaceDestroy(PRTSTRSPACE pStrSpace, PFNRTSTRSPACECALLBACK pfnCallback, void *pvUser);
3334
3335/**
3336 * Enumerates the string space.
3337 * The caller supplies a callback which will be called for each of
3338 * the string nodes.
3339 *
3340 * @returns 0 or what ever non-zero return value pfnCallback returned
3341 * when aborting the destruction.
3342 * @param pStrSpace The space to enumerate.
3343 * @param pfnCallback The callback.
3344 * @param pvUser The user argument.
3345 */
3346RTDECL(int) RTStrSpaceEnumerate(PRTSTRSPACE pStrSpace, PFNRTSTRSPACECALLBACK pfnCallback, void *pvUser);
3347
3348/** @} */
3349
3350
3351/** @defgroup rt_str_hash Sting hashing
3352 * @{ */
3353
3354/**
3355 * Hashes the given string using algorithm \#1.
3356 *
3357 * @returns String hash.
3358 * @param pszString The string to hash.
3359 */
3360RTDECL(uint32_t) RTStrHash1(const char *pszString);
3361
3362/**
3363 * Hashes the given string using algorithm \#1.
3364 *
3365 * @returns String hash.
3366 * @param pszString The string to hash.
3367 * @param cchString The max length to hash. Hashing will stop if the
3368 * terminator character is encountered first. Passing
3369 * RTSTR_MAX is fine.
3370 */
3371RTDECL(uint32_t) RTStrHash1N(const char *pszString, size_t cchString);
3372
3373/**
3374 * Hashes the given strings as if they were concatenated using algorithm \#1.
3375 *
3376 * @returns String hash.
3377 * @param cPairs The number of string / length pairs in the
3378 * ellipsis.
3379 * @param ... List of string (const char *) and length
3380 * (size_t) pairs. Passing RTSTR_MAX as the size is
3381 * fine.
3382 */
3383RTDECL(uint32_t) RTStrHash1ExN(size_t cPairs, ...);
3384
3385/**
3386 * Hashes the given strings as if they were concatenated using algorithm \#1.
3387 *
3388 * @returns String hash.
3389 * @param cPairs The number of string / length pairs in the @a va.
3390 * @param va List of string (const char *) and length
3391 * (size_t) pairs. Passing RTSTR_MAX as the size is
3392 * fine.
3393 */
3394RTDECL(uint32_t) RTStrHash1ExNV(size_t cPairs, va_list va);
3395
3396/** @} */
3397
3398/** @} */
3399
3400RT_C_DECLS_END
3401
3402#endif /* !IPRT_INCLUDED_string_h */
3403
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette