2 * IPRT - String Manipulation.
6 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 #ifndef IPRT_INCLUDED_string_h
37 #define IPRT_INCLUDED_string_h
38 #ifndef RT_WITHOUT_PRAGMA_ONCE
42 #include <iprt/cdefs.h>
43 #include <iprt/types.h>
44 #include <iprt/assert.h>
45 #include <iprt/stdarg.h>
46 #include <iprt/errcore.h> /* for VINF_SUCCESS */
47 #if defined(RT_OS_LINUX) && defined(__KERNEL__)
48 /* no C++ hacks ('new' etc) here anymore! */
49 # include <linux/string.h>
50 # include <iprt/linux/version.h>
52 #elif defined(IN_XF86_MODULE) && !defined(NO_ANSIC)
54 # include "xf86_ansic.h"
57 #elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
59 # include <sys/libkern.h>
62 #elif defined(RT_OS_NETBSD) && defined(_KERNEL)
64 # include <lib/libkern/libkern.h>
67 #elif defined(RT_OS_SOLARIS) && defined(_KERNEL)
69 * Same case as with FreeBSD kernel:
70 * The string.h stuff clashes with sys/system.h
71 * ffs = find first set bit.
73 # define ffs ffs_string_h
74 # define fls fls_string_h
85 * Supply prototypes for standard string functions provided by
86 * IPRT instead of the operating environment.
88 #if defined(RT_OS_DARWIN) && defined(KERNEL)
90 void *memchr(const void *pv
, int ch
, size_t cb
);
91 char *strpbrk(const char *pszStr
, const char *pszChars
);
95 #if defined(RT_OS_FREEBSD) && defined(_KERNEL)
97 char *strpbrk(const char *pszStr
, const char *pszChars
);
101 #if defined(RT_OS_NETBSD) && defined(_KERNEL)
103 char *strpbrk(const char *pszStr
, const char *pszChars
);
107 #if !defined(IPRT_NO_CRT) \
108 && ( defined(RT_OS_DARWIN) \
109 || (defined(RT_OS_OS2) && (!defined(_GNU_SOURCE) || !defined(__GNUC__))) \
110 || defined(RT_OS_SOLARIS) \
111 || defined(RT_OS_WINDOWS))
113 # if !defined(RT_OS_DARWIN) || RT_CLANG_PREREQ(7 /* whatever post gcc-4.2 */, 0)
114 RTDECL(void *) mempcpy(void *pvDst
, const void *pvSrc
, size_t cb
);
116 void *mempcpy(void *pvDst
, const void *pvSrc
, size_t cb
);
121 #if (!defined(RT_OS_LINUX) || !defined(_GNU_SOURCE)) \
122 && (!defined(RT_OS_OS2) || !defined(_GNU_SOURCE)) \
123 && !defined(RT_OS_FREEBSD) \
124 && !defined(RT_OS_NETBSD)
126 void *memrchr(const void *pv
, int ch
, size_t cb
);
131 /** @def RT_USE_RTC_3629
132 * When defined the UTF-8 range will stop at 0x10ffff. If not defined, the
133 * range stops at 0x7fffffff.
134 * @remarks Must be defined both when building and using the IPRT. */
135 #ifdef DOXYGEN_RUNNING
136 # define RT_USE_RTC_3629
140 /** @defgroup grp_rt_str RTStr - String Manipulation
141 * Mostly UTF-8 related helpers where the standard string functions won't do.
150 * The maximum string length.
152 #define RTSTR_MAX (~(size_t)0)
156 * The default allocation tag used by the RTStr allocation APIs.
158 * When not defined before the inclusion of iprt/string.h, this will default to
159 * the pointer to the current file name. The string API will make of use of
160 * this as pointer to a volatile but read-only string.
162 #if !defined(RTSTR_TAG) || defined(DOXYGEN_RUNNING)
163 # define RTSTR_TAG (__FILE__)
168 * Byte zero the specified object.
170 * This will use sizeof(Obj) to figure the size and will call memset, bzero
171 * or some compiler intrinsic to perform the actual zeroing.
173 * @param Obj The object to zero. Make sure to dereference pointers.
175 * @remarks Because the macro may use memset it has been placed in string.h
176 * instead of cdefs.h to avoid build issues because someone forgot
177 * to include this header.
179 * @ingroup grp_rt_cdefs
181 #define RT_ZERO(Obj) RT_BZERO(&(Obj), sizeof(Obj))
184 * Byte zero the specified memory area.
186 * This will call memset, bzero or some compiler intrinsic to clear the
187 * specified bytes of memory.
189 * @param pv Pointer to the memory.
190 * @param cb The number of bytes to clear. Please, don't pass 0.
192 * @remarks Because the macro may use memset it has been placed in string.h
193 * instead of cdefs.h to avoid build issues because someone forgot
194 * to include this header.
196 * @ingroup grp_rt_cdefs
198 #define RT_BZERO(pv, cb) do { memset((pv), 0, cb); } while (0)
202 * For copying a volatile variable to a non-volatile one.
203 * @param a_Dst The non-volatile destination variable.
204 * @param a_VolatileSrc The volatile source variable / dereferenced pointer.
206 #define RT_COPY_VOLATILE(a_Dst, a_VolatileSrc) \
208 void const volatile *a_pvVolatileSrc_BCopy_Volatile = &(a_VolatileSrc); \
209 AssertCompile(sizeof(a_Dst) == sizeof(a_VolatileSrc)); \
210 memcpy(&(a_Dst), (void const *)a_pvVolatileSrc_BCopy_Volatile, sizeof(a_Dst)); \
214 * For copy a number of bytes from a volatile buffer to a non-volatile one.
216 * @param a_pDst Pointer to the destination buffer.
217 * @param a_pVolatileSrc Pointer to the volatile source buffer.
218 * @param a_cbToCopy Number of bytes to copy.
220 #define RT_BCOPY_VOLATILE(a_pDst, a_pVolatileSrc, a_cbToCopy) \
222 void const volatile *a_pvVolatileSrc_BCopy_Volatile = (a_pVolatileSrc); \
223 memcpy((a_pDst), (void const *)a_pvVolatileSrc_BCopy_Volatile, (a_cbToCopy)); \
226 /** @def RT_BCOPY_UNFORTIFIED
227 * For copying a number of bytes from/to variable length structures.
229 * This is for working around false positives ("field-spanning writes") in the
230 * linux kernel's fortified memcpy (v5.18+) when copying from/to
231 * RT_FLEXIBLE_ARRAY fields and similar tricks going beyond the strict
232 * definition of a target or source structure.
234 * @param a_pDst Pointer to the destination buffer.
235 * @param a_pSrc Pointer to the source buffer.
236 * @param a_cbToCopy Number of bytes to copy.
237 * @see @bugref{10209}, @ticketref{21410}
239 #if defined(RT_OS_LINUX) && defined(__KERNEL__)
240 # if (RTLNX_VER_MIN(5,18,0) || RTLNX_RHEL_RANGE(9,3, 9,99)) \
241 && !defined(__NO_FORTIFY) \
242 && defined(__OPTIMIZE__) \
243 && defined(CONFIG_FORTIFY_SOURCE)
244 # define RT_BCOPY_UNFORTIFIED(a_pDst, a_pSrc, a_cbToCopy) __underlying_memcpy((a_pDst), (a_pSrc), (a_cbToCopy))
246 # define RT_BCOPY_UNFORTIFIED(a_pDst, a_pSrc, a_cbToCopy) memcpy((a_pDst), (a_pSrc), (a_cbToCopy))
248 #else /* !RT_OS_LINUX && !__KERNEL__ */
249 # define RT_BCOPY_UNFORTIFIED(a_pDst, a_pSrc, a_cbToCopy) memcpy((a_pDst), (a_pSrc), (a_cbToCopy))
250 #endif /* !RT_OS_LINUX && !__KERNEL__ */
256 * Allocates tmp buffer with default tag, translates pszString from UTF8 to
259 * @returns iprt status code.
260 * @param ppszString Receives pointer of allocated native CP string.
261 * The returned pointer must be freed using RTStrFree().
262 * @param pszString UTF-8 string to convert.
264 #define RTStrUtf8ToCurrentCP(ppszString, pszString) RTStrUtf8ToCurrentCPTag((ppszString), (pszString), RTSTR_TAG)
267 * Allocates tmp buffer with custom tag, translates pszString from UTF-8 to
270 * @returns iprt status code.
271 * @param ppszString Receives pointer of allocated native CP string.
272 * The returned pointer must be freed using
273 * RTStrFree()., const char *pszTag
274 * @param pszString UTF-8 string to convert.
275 * @param pszTag Allocation tag used for statistics and such.
277 RTR3DECL(int) RTStrUtf8ToCurrentCPTag(char **ppszString
, const char *pszString
, const char *pszTag
);
280 * Allocates tmp buffer with default tag, translates pszString from UTF-8 to
281 * current codepage, extended version.
283 * @returns iprt status code.
284 * @param ppszString Receives pointer of allocated native CP string.
285 * The returned pointer must be freed using RTStrFree().
286 * @param pszString UTF-8 string to convert.
287 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
288 * when it reaches cchString or the string terminator ('\\0').
289 * Use RTSTR_MAX to translate the entire string.
291 #define RTStrUtf8ToCurrentCPEx(ppszString, pszString, cchString) \
292 RTStrUtf8ToCurrentCPExTag((ppszString), (pszString), (cchString), RTSTR_TAG)
295 * Allocates tmp buffer with custom tag, translates pszString from UTF8 to
298 * @returns iprt status code.
299 * @param ppszString Receives pointer of allocated native CP string.
300 * The returned pointer must be freed using
301 * RTStrFree()., const char *pszTag
302 * @param pszString UTF-8 string to convert.
303 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
304 * when it reaches cchString or the string terminator ('\\0').
305 * Use RTSTR_MAX to translate the entire string.
306 * @param pszTag Allocation tag used for statistics and such.
308 RTR3DECL(int) RTStrUtf8ToCurrentCPExTag(char **ppszString
, const char *pszString
, size_t cchString
, const char *pszTag
);
311 * Allocates tmp buffer, translates pszString from current codepage to UTF-8.
313 * @returns iprt status code.
314 * @param ppszString Receives pointer of allocated UTF-8 string.
315 * The returned pointer must be freed using RTStrFree().
316 * @param pszString Native string to convert.
318 #define RTStrCurrentCPToUtf8(ppszString, pszString) RTStrCurrentCPToUtf8Tag((ppszString), (pszString), RTSTR_TAG)
321 * Allocates tmp buffer, translates pszString from current codepage to UTF-8.
323 * @returns iprt status code.
324 * @param ppszString Receives pointer of allocated UTF-8 string.
325 * The returned pointer must be freed using RTStrFree().
326 * @param pszString Native string to convert.
327 * @param pszTag Allocation tag used for statistics and such.
329 RTR3DECL(int) RTStrCurrentCPToUtf8Tag(char **ppszString
, const char *pszString
, const char *pszTag
);
332 * Allocates tmp buffer, translates pszString from console codepage to UTF-8.
334 * @returns iprt status code.
335 * @param ppszString Receives pointer of allocated UTF-8 string.
336 * The returned pointer must be freed using RTStrFree().
337 * @param pszString Native string to convert.
339 #define RTStrConsoleCPToUtf8(ppszString, pszString) RTStrConsoleCPToUtf8Tag((ppszString), (pszString), RTSTR_TAG)
342 * Allocates tmp buffer, translates pszString from console codepage to UTF-8.
344 * @returns iprt status code.
345 * @param ppszString Receives pointer of allocated UTF-8 string.
346 * The returned pointer must be freed using RTStrFree().
347 * @param pszString Native string to convert.
348 * @param pszTag Allocation tag used for statistics and such.
350 RTR3DECL(int) RTStrConsoleCPToUtf8Tag(char **ppszString
, const char *pszString
, const char *pszTag
);
352 #endif /* IN_RING3 */
355 * Free string allocated by any of the non-UCS-2 string functions.
357 * @param pszString Pointer to buffer with string to free.
360 RTDECL(void) RTStrFree(char *pszString
);
363 * Allocates a new copy of the given UTF-8 string (default tag).
365 * @returns Pointer to the allocated UTF-8 string.
366 * @param pszString UTF-8 string to duplicate.
368 #define RTStrDup(pszString) RTStrDupTag((pszString), RTSTR_TAG)
371 * Allocates a new copy of the given UTF-8 string (custom tag).
373 * @returns Pointer to the allocated UTF-8 string.
374 * @param pszString UTF-8 string to duplicate.
375 * @param pszTag Allocation tag used for statistics and such.
377 RTDECL(char *) RTStrDupTag(const char *pszString
, const char *pszTag
);
380 * Allocates a new copy of the given UTF-8 string (default tag).
382 * @returns iprt status code.
383 * @param ppszCopy Receives pointer of the allocated UTF-8 string.
384 * The returned pointer must be freed using RTStrFree().
385 * @param pszString UTF-8 string to duplicate.
387 #define RTStrDupEx(ppszCopy, pszString) RTStrDupExTag((ppszCopy), (pszString), RTSTR_TAG)
390 * Allocates a new copy of the given UTF-8 string (custom tag).
392 * @returns iprt status code.
393 * @param ppszCopy Receives pointer of the allocated UTF-8 string.
394 * The returned pointer must be freed using RTStrFree().
395 * @param pszString UTF-8 string to duplicate.
396 * @param pszTag Allocation tag used for statistics and such.
398 RTDECL(int) RTStrDupExTag(char **ppszCopy
, const char *pszString
, const char *pszTag
);
401 * Allocates a new copy of the given UTF-8 substring (default tag).
403 * @returns Pointer to the allocated UTF-8 substring.
404 * @param pszString UTF-8 string to duplicate.
405 * @param cchMax The max number of chars to duplicate, not counting
408 #define RTStrDupN(pszString, cchMax) RTStrDupNTag((pszString), (cchMax), RTSTR_TAG)
411 * Allocates a new copy of the given UTF-8 substring (custom tag).
413 * @returns Pointer to the allocated UTF-8 substring.
414 * @param pszString UTF-8 string to duplicate.
415 * @param cchMax The max number of chars to duplicate, not counting
417 * @param pszTag Allocation tag used for statistics and such.
419 RTDECL(char *) RTStrDupNTag(const char *pszString
, size_t cchMax
, const char *pszTag
);
422 * Allocates a new copy of the given UTF-8 substring (default tag).
424 * @returns iprt status code (VINF_SUCCESS or VERR_NO_STR_MEMORY).
425 * @param ppszCopy Receives pointer of the allocated UTF-8 substring.
426 * The returned pointer must be freed using RTStrFree().
427 * @param pszString UTF-8 string to duplicate.
428 * @param cchMax The max number of chars to duplicate, not counting
431 #define RTStrDupNEx(ppszCopy, pszString, cchMax) RTStrDupNExTag((ppszCopy), (pszString), (cchMax), RTSTR_TAG)
434 * Allocates a new copy of the given UTF-8 substring (custom tag).
436 * @returns iprt status code (VINF_SUCCESS or VERR_NO_STR_MEMORY).
437 * @param ppszCopy Receives pointer of the allocated UTF-8 substring.
438 * The returned pointer must be freed using RTStrFree().
439 * @param pszString UTF-8 string to duplicate.
440 * @param cchMax The max number of chars to duplicate, not counting
442 * @param pszTag Allocation tag used for statistics and such.
444 RTDECL(int) RTStrDupNExTag(char **ppszCopy
, const char *pszString
, size_t cchMax
, const char *pszTag
);
447 * Appends a string onto an existing IPRT allocated string (default tag).
449 * @retval VINF_SUCCESS
450 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
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 pszAppend The string to append. NULL and empty strings
457 * are quietly ignored.
459 #define RTStrAAppend(ppsz, pszAppend) RTStrAAppendTag((ppsz), (pszAppend), RTSTR_TAG)
462 * Appends a string onto an existing IPRT allocated string (custom tag).
464 * @retval VINF_SUCCESS
465 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
468 * @param ppsz Pointer to the string pointer. The string
469 * pointer must either be NULL or point to a string
470 * returned by an IPRT string API. (In/Out)
471 * @param pszAppend The string to append. NULL and empty strings
472 * are quietly ignored.
473 * @param pszTag Allocation tag used for statistics and such.
475 RTDECL(int) RTStrAAppendTag(char **ppsz
, const char *pszAppend
, const char *pszTag
);
478 * Appends N bytes from a strings onto an existing IPRT allocated string
481 * @retval VINF_SUCCESS
482 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
485 * @param ppsz Pointer to the string pointer. The string
486 * pointer must either be NULL or point to a string
487 * returned by an IPRT string API. (In/Out)
488 * @param pszAppend The string to append. Can be NULL if cchAppend
490 * @param cchAppend The number of chars (not code points) to append
491 * from pszAppend. Must not be more than
492 * @a pszAppend contains, except for the special
493 * value RTSTR_MAX that can be used to indicate all
494 * of @a pszAppend without having to strlen it.
496 #define RTStrAAppendN(ppsz, pszAppend, cchAppend) RTStrAAppendNTag((ppsz), (pszAppend), (cchAppend), RTSTR_TAG)
499 * Appends N bytes from a strings onto an existing IPRT allocated string (custom
502 * @retval VINF_SUCCESS
503 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
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 pszAppend The string to append. Can be NULL if cchAppend
511 * @param cchAppend The number of chars (not code points) to append
512 * from pszAppend. Must not be more than
513 * @a pszAppend contains, except for the special
514 * value RTSTR_MAX that can be used to indicate all
515 * of @a pszAppend without having to strlen it.
516 * @param pszTag Allocation tag used for statistics and such.
518 RTDECL(int) RTStrAAppendNTag(char **ppsz
, const char *pszAppend
, size_t cchAppend
, const char *pszTag
);
521 * Appends one or more strings onto an existing IPRT allocated string.
523 * This is a very flexible and efficient alternative to using RTStrAPrintf to
524 * combine several strings together.
526 * @retval VINF_SUCCESS
527 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
530 * @param ppsz Pointer to the string pointer. The string
531 * pointer must either be NULL or point to a string
532 * returned by an IPRT string API. (In/Out)
533 * @param cPairs The number of string / length pairs in the
535 * @param va List of string (const char *) and length
536 * (size_t) pairs. The strings will be appended to
537 * the string in the first argument.
539 #define RTStrAAppendExNV(ppsz, cPairs, va) RTStrAAppendExNVTag((ppsz), (cPairs), (va), RTSTR_TAG)
542 * Appends one or more strings onto an existing IPRT allocated string.
544 * This is a very flexible and efficient alternative to using RTStrAPrintf to
545 * combine several strings together.
547 * @retval VINF_SUCCESS
548 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
551 * @param ppsz Pointer to the string pointer. The string
552 * pointer must either be NULL or point to a string
553 * returned by an IPRT string API. (In/Out)
554 * @param cPairs The number of string / length pairs in the
556 * @param va List of string (const char *) and length
557 * (size_t) pairs. The strings will be appended to
558 * the string in the first argument.
559 * @param pszTag Allocation tag used for statistics and such.
561 RTDECL(int) RTStrAAppendExNVTag(char **ppsz
, size_t cPairs
, va_list va
, const char *pszTag
);
564 * Appends one or more strings onto an existing IPRT allocated string
567 * This is a very flexible and efficient alternative to using RTStrAPrintf to
568 * combine several strings together.
570 * @retval VINF_SUCCESS
571 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
574 * @param ppsz Pointer to the string pointer. The string
575 * pointer must either be NULL or point to a string
576 * returned by an IPRT string API. (In/Out)
577 * @param cPairs The number of string / length pairs in the
579 * @param ... List of string (const char *) and length
580 * (size_t) pairs. The strings will be appended to
581 * the string in the first argument.
583 DECLINLINE(int) RTStrAAppendExN(char **ppsz
, size_t cPairs
, ...)
587 va_start(va
, cPairs
);
588 rc
= RTStrAAppendExNVTag(ppsz
, cPairs
, va
, RTSTR_TAG
);
594 * Appends one or more strings onto an existing IPRT allocated string (custom
597 * This is a very flexible and efficient alternative to using RTStrAPrintf to
598 * combine several strings together.
600 * @retval VINF_SUCCESS
601 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
604 * @param ppsz Pointer to the string pointer. The string
605 * pointer must either be NULL or point to a string
606 * returned by an IPRT string API. (In/Out)
607 * @param pszTag Allocation tag used for statistics and such.
608 * @param cPairs The number of string / length pairs in the
610 * @param ... List of string (const char *) and length
611 * (size_t) pairs. The strings will be appended to
612 * the string in the first argument.
614 DECLINLINE(int) RTStrAAppendExNTag(char **ppsz
, const char *pszTag
, size_t cPairs
, ...)
618 va_start(va
, cPairs
);
619 rc
= RTStrAAppendExNVTag(ppsz
, cPairs
, va
, pszTag
);
625 * Truncates an IPRT allocated string (default tag).
627 * @retval VINF_SUCCESS.
628 * @retval VERR_OUT_OF_RANGE if cchNew is too long. Nothing is done.
630 * @param ppsz Pointer to the string pointer. The string
631 * pointer can be NULL if @a cchNew is 0, no change
632 * is made then. If we actually reallocate the
633 * string, the string pointer might be changed by
634 * this call. (In/Out)
635 * @param cchNew The new string length (excluding the
636 * terminator). The string must be at least this
637 * long or we'll return VERR_OUT_OF_RANGE and
640 #define RTStrATruncate(ppsz, cchNew) RTStrATruncateTag((ppsz), (cchNew), RTSTR_TAG)
643 * Truncates an IPRT allocated string.
645 * @retval VINF_SUCCESS.
646 * @retval VERR_OUT_OF_RANGE if cchNew is too long. Nothing is done.
648 * @param ppsz Pointer to the string pointer. The string
649 * pointer can be NULL if @a cchNew is 0, no change
650 * is made then. If we actually reallocate the
651 * string, the string pointer might be changed by
652 * this call. (In/Out)
653 * @param cchNew The new string length (excluding the
654 * terminator). The string must be at least this
655 * long or we'll return VERR_OUT_OF_RANGE and
657 * @param pszTag Allocation tag used for statistics and such.
659 RTDECL(int) RTStrATruncateTag(char **ppsz
, size_t cchNew
, const char *pszTag
);
662 * Allocates memory for string storage (default tag).
664 * You should normally not use this function, except if there is some very
665 * custom string handling you need doing that isn't covered by any of the other
668 * @returns Pointer to the allocated string. The first byte is always set
669 * to the string terminator char, the contents of the remainder of the
670 * memory is undefined. The string must be freed by calling RTStrFree.
672 * NULL is returned if the allocation failed. Please translate this to
673 * VERR_NO_STR_MEMORY and not VERR_NO_MEMORY. Also consider
674 * RTStrAllocEx if an IPRT status code is required.
676 * @param cb How many bytes to allocate. If this is zero, we
677 * will allocate a terminator byte anyway.
679 #define RTStrAlloc(cb) RTStrAllocTag((cb), RTSTR_TAG)
682 * Allocates memory for string storage (custom tag).
684 * You should normally not use this function, except if there is some very
685 * custom string handling you need doing that isn't covered by any of the other
688 * @returns Pointer to the allocated string. The first byte is always set
689 * to the string terminator char, the contents of the remainder of the
690 * memory is undefined. The string must be freed by calling RTStrFree.
692 * NULL is returned if the allocation failed. Please translate this to
693 * VERR_NO_STR_MEMORY and not VERR_NO_MEMORY. Also consider
694 * RTStrAllocEx if an IPRT status code is required.
696 * @param cb How many bytes to allocate. If this is zero, we
697 * will allocate a terminator byte anyway.
698 * @param pszTag Allocation tag used for statistics and such.
700 RTDECL(char *) RTStrAllocTag(size_t cb
, const char *pszTag
);
703 * Allocates memory for string storage, with status code (default tag).
705 * You should normally not use this function, except if there is some very
706 * custom string handling you need doing that isn't covered by any of the other
709 * @retval VINF_SUCCESS
710 * @retval VERR_NO_STR_MEMORY
712 * @param ppsz Where to return the allocated string. This will
713 * be set to NULL on failure. On success, the
714 * returned memory will always start with a
715 * terminator char so that it is considered a valid
716 * C string, the contents of rest of the memory is
718 * @param cb How many bytes to allocate. If this is zero, we
719 * will allocate a terminator byte anyway.
721 #define RTStrAllocEx(ppsz, cb) RTStrAllocExTag((ppsz), (cb), RTSTR_TAG)
724 * Allocates memory for string storage, with status code (custom tag).
726 * You should normally not use this function, except if there is some very
727 * custom string handling you need doing that isn't covered by any of the other
730 * @retval VINF_SUCCESS
731 * @retval VERR_NO_STR_MEMORY
733 * @param ppsz Where to return the allocated string. This will
734 * be set to NULL on failure. On success, the
735 * returned memory will always start with a
736 * terminator char so that it is considered a valid
737 * C string, the contents of rest of the memory is
739 * @param cb How many bytes to allocate. If this is zero, we
740 * will allocate a terminator byte anyway.
741 * @param pszTag Allocation tag used for statistics and such.
743 RTDECL(int) RTStrAllocExTag(char **ppsz
, size_t cb
, const char *pszTag
);
746 * Reallocates the specified string (default tag).
748 * You should normally not have use this function, except perhaps to truncate a
749 * really long string you've got from some IPRT string API, but then you should
750 * use RTStrATruncate.
752 * @returns VINF_SUCCESS.
753 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
756 * @param ppsz Pointer to the string variable containing the
757 * input and output string.
759 * When not freeing the string, the result will
760 * always have the last byte set to the terminator
761 * character so that when used for string
762 * truncation the result will be a valid C string
763 * (your job to keep it a valid UTF-8 string).
765 * When the input string is NULL and we're supposed
766 * to reallocate, the returned string will also
767 * have the first byte set to the terminator char
768 * so it will be a valid C string.
770 * @param cbNew When @a cbNew is zero, we'll behave like
771 * RTStrFree and @a *ppsz will be set to NULL.
773 * When not zero, this will be the new size of the
774 * memory backing the string, i.e. it includes the
777 #define RTStrRealloc(ppsz, cbNew) RTStrReallocTag((ppsz), (cbNew), RTSTR_TAG)
780 * Reallocates the specified string (custom tag).
782 * You should normally not have use this function, except perhaps to truncate a
783 * really long string you've got from some IPRT string API, but then you should
784 * use RTStrATruncate.
786 * @returns VINF_SUCCESS.
787 * @retval VERR_NO_STR_MEMORY if we failed to reallocate the string, @a *ppsz
790 * @param ppsz Pointer to the string variable containing the
791 * input and output string.
793 * When not freeing the string, the result will
794 * always have the last byte set to the terminator
795 * character so that when used for string
796 * truncation the result will be a valid C string
797 * (your job to keep it a valid UTF-8 string).
799 * When the input string is NULL and we're supposed
800 * to reallocate, the returned string will also
801 * have the first byte set to the terminator char
802 * so it will be a valid C string.
804 * @param cbNew When @a cbNew is zero, we'll behave like
805 * RTStrFree and @a *ppsz will be set to NULL.
807 * When not zero, this will be the new size of the
808 * memory backing the string, i.e. it includes the
810 * @param pszTag Allocation tag used for statistics and such.
812 RTDECL(int) RTStrReallocTag(char **ppsz
, size_t cbNew
, const char *pszTag
);
815 * Validates the UTF-8 encoding of the string.
817 * @returns iprt status code.
818 * @param psz The string.
820 RTDECL(int) RTStrValidateEncoding(const char *psz
);
822 /** @name Flags for RTStrValidateEncodingEx and RTUtf16ValidateEncodingEx
825 /** Check that the string is zero terminated within the given size.
826 * VERR_BUFFER_OVERFLOW will be returned if the check fails. */
827 #define RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED RT_BIT_32(0)
828 /** Check that the string is exactly the given length.
829 * If it terminates early, VERR_BUFFER_UNDERFLOW will be returned. When used
830 * together with RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED, the given length must
831 * include the terminator or VERR_BUFFER_OVERFLOW will be returned. */
832 #define RTSTR_VALIDATE_ENCODING_EXACT_LENGTH RT_BIT_32(1)
836 * Validates the UTF-8 encoding of the string.
838 * @returns iprt status code.
839 * @param psz The string.
840 * @param cch The max string length (/ size). Use RTSTR_MAX to
841 * process the entire string.
842 * @param fFlags Combination of RTSTR_VALIDATE_ENCODING_XXX flags.
844 RTDECL(int) RTStrValidateEncodingEx(const char *psz
, size_t cch
, uint32_t fFlags
);
847 * Checks if the UTF-8 encoding is valid.
849 * @returns true / false.
850 * @param psz The string.
852 RTDECL(bool) RTStrIsValidEncoding(const char *psz
);
855 * Purge all bad UTF-8 encoding in the string, replacing it with '?'.
857 * @returns The number of bad characters (0 if nothing was done).
858 * @param psz The string to purge.
860 RTDECL(size_t) RTStrPurgeEncoding(char *psz
);
863 * Sanitizes a (valid) UTF-8 string by replacing all characters outside a white
864 * list in-place by an ASCII replacedment character.
866 * Multi-byte characters will be replaced byte by byte.
868 * @returns The number of code points replaced. In the case of an incorrectly
869 * encoded string -1 will be returned, and the string is not completely
870 * processed. In the case of puszValidPairs having an odd number of
871 * code points, -1 will be also return but without any modification to
873 * @param psz The string to sanitise.
874 * @param puszValidPairs A zero-terminated array of pairs of Unicode points.
875 * Each pair is the start and end point of a range,
876 * and the union of these ranges forms the white list.
877 * @param chReplacement The ASCII replacement character.
879 RTDECL(ssize_t
) RTStrPurgeComplementSet(char *psz
, PCRTUNICP puszValidPairs
, char chReplacement
);
882 * Gets the number of code points the string is made up of, excluding
886 * @returns Number of code points (RTUNICP).
887 * @returns 0 if the string was incorrectly encoded.
888 * @param psz The string.
890 RTDECL(size_t) RTStrUniLen(const char *psz
);
893 * Gets the number of code points the string is made up of, excluding
896 * This function will validate the string, and incorrectly encoded UTF-8
897 * strings will be rejected.
899 * @returns iprt status code.
900 * @param psz The string.
901 * @param cch The max string length. Use RTSTR_MAX to process the entire string.
902 * @param pcuc Where to store the code point count.
903 * This is undefined on failure.
905 RTDECL(int) RTStrUniLenEx(const char *psz
, size_t cch
, size_t *pcuc
);
908 * Translate a UTF-8 string into an unicode string (i.e. RTUNICPs), allocating the string buffer.
910 * @returns iprt status code.
911 * @param pszString UTF-8 string to convert.
912 * @param ppUniString Receives pointer to the allocated unicode string.
913 * The returned string must be freed using RTUniFree().
915 RTDECL(int) RTStrToUni(const char *pszString
, PRTUNICP
*ppUniString
);
918 * Translates pszString from UTF-8 to an array of code points, allocating the result
919 * array if requested.
921 * @returns iprt status code.
922 * @param pszString UTF-8 string to convert.
923 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
924 * when it reaches cchString or the string terminator ('\\0').
925 * Use RTSTR_MAX to translate the entire string.
926 * @param ppaCps If cCps is non-zero, this must either be pointing to pointer to
927 * a buffer of the specified size, or pointer to a NULL pointer.
928 * If *ppusz is NULL or cCps is zero a buffer of at least cCps items
929 * will be allocated to hold the translated string.
930 * If a buffer was requested it must be freed using RTUtf16Free().
931 * @param cCps The number of code points in the unicode string. This includes the terminator.
932 * @param pcCps Where to store the length of the translated string,
933 * excluding the terminator. (Optional)
935 * This may be set under some error conditions,
936 * however, only for VERR_BUFFER_OVERFLOW and
937 * VERR_NO_STR_MEMORY will it contain a valid string
938 * length that can be used to resize the buffer.
940 RTDECL(int) RTStrToUniEx(const char *pszString
, size_t cchString
, PRTUNICP
*ppaCps
, size_t cCps
, size_t *pcCps
);
943 * Calculates the length of the string in RTUTF16 items.
945 * This function will validate the string, and incorrectly encoded UTF-8
946 * strings will be rejected. The primary purpose of this function is to
947 * help allocate buffers for RTStrToUtf16Ex of the correct size. For most
948 * other purposes RTStrCalcUtf16LenEx() should be used.
950 * @returns Number of RTUTF16 items.
951 * @returns 0 if the string was incorrectly encoded.
952 * @param psz The string.
954 RTDECL(size_t) RTStrCalcUtf16Len(const char *psz
);
957 * Calculates the length of the string in RTUTF16 items.
959 * This function will validate the string, and incorrectly encoded UTF-8
960 * strings will be rejected.
962 * @returns iprt status code.
963 * @param psz The string.
964 * @param cch The max string length. Use RTSTR_MAX to process the entire string.
965 * @param pcwc Where to store the string length. Optional.
966 * This is undefined on failure.
968 RTDECL(int) RTStrCalcUtf16LenEx(const char *psz
, size_t cch
, size_t *pcwc
);
971 * Translate a UTF-8 string into a UTF-16 allocating the result buffer (default
974 * @returns iprt status code.
975 * @param pszString UTF-8 string to convert.
976 * @param ppwszString Receives pointer to the allocated UTF-16 string.
977 * The returned string must be freed using RTUtf16Free().
979 #define RTStrToUtf16(pszString, ppwszString) RTStrToUtf16Tag((pszString), (ppwszString), RTSTR_TAG)
982 * Translate a UTF-8 string into a UTF-16 allocating the result buffer (custom
985 * This differs from RTStrToUtf16 in that it always produces a
988 * @returns iprt status code.
989 * @param pszString UTF-8 string to convert.
990 * @param ppwszString Receives pointer to the allocated UTF-16 string.
991 * The returned string must be freed using RTUtf16Free().
992 * @param pszTag Allocation tag used for statistics and such.
994 RTDECL(int) RTStrToUtf16Tag(const char *pszString
, PRTUTF16
*ppwszString
, const char *pszTag
);
997 * Translate a UTF-8 string into a UTF-16BE allocating the result buffer
1000 * This differs from RTStrToUtf16Tag in that it always produces a
1001 * big-endian string.
1003 * @returns iprt status code.
1004 * @param pszString UTF-8 string to convert.
1005 * @param ppwszString Receives pointer to the allocated UTF-16BE string.
1006 * The returned string must be freed using RTUtf16Free().
1008 #define RTStrToUtf16Big(pszString, ppwszString) RTStrToUtf16BigTag((pszString), (ppwszString), RTSTR_TAG)
1011 * Translate a UTF-8 string into a UTF-16BE allocating the result buffer (custom
1014 * @returns iprt status code.
1015 * @param pszString UTF-8 string to convert.
1016 * @param ppwszString Receives pointer to the allocated UTF-16BE string.
1017 * The returned string must be freed using RTUtf16Free().
1018 * @param pszTag Allocation tag used for statistics and such.
1020 RTDECL(int) RTStrToUtf16BigTag(const char *pszString
, PRTUTF16
*ppwszString
, const char *pszTag
);
1023 * Translates pszString from UTF-8 to UTF-16, allocating the result buffer if requested.
1025 * @returns iprt status code.
1026 * @param pszString UTF-8 string to convert.
1027 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
1028 * when it reaches cchString or the string terminator ('\\0').
1029 * Use RTSTR_MAX to translate the entire string.
1030 * @param ppwsz If cwc is non-zero, this must either be pointing to pointer to
1031 * a buffer of the specified size, or pointer to a NULL pointer.
1032 * If *ppwsz is NULL or cwc is zero a buffer of at least cwc items
1033 * will be allocated to hold the translated string.
1034 * If a buffer was requested it must be freed using RTUtf16Free().
1035 * @param cwc The buffer size in RTUTF16s. This includes the terminator.
1036 * @param pcwc Where to store the length of the translated string,
1037 * excluding the terminator. (Optional)
1039 * This may be set under some error conditions,
1040 * however, only for VERR_BUFFER_OVERFLOW and
1041 * VERR_NO_STR_MEMORY will it contain a valid string
1042 * length that can be used to resize the buffer.
1044 #define RTStrToUtf16Ex(pszString, cchString, ppwsz, cwc, pcwc) \
1045 RTStrToUtf16ExTag((pszString), (cchString), (ppwsz), (cwc), (pcwc), RTSTR_TAG)
1048 * Translates pszString from UTF-8 to UTF-16, allocating the result buffer if
1049 * requested (custom tag).
1051 * @returns iprt status code.
1052 * @param pszString UTF-8 string to convert.
1053 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
1054 * when it reaches cchString or the string terminator ('\\0').
1055 * Use RTSTR_MAX to translate the entire string.
1056 * @param ppwsz If cwc is non-zero, this must either be pointing to pointer to
1057 * a buffer of the specified size, or pointer to a NULL pointer.
1058 * If *ppwsz is NULL or cwc is zero a buffer of at least cwc items
1059 * will be allocated to hold the translated string.
1060 * If a buffer was requested it must be freed using RTUtf16Free().
1061 * @param cwc The buffer size in RTUTF16s. This includes the terminator.
1062 * @param pcwc Where to store the length of the translated string,
1063 * excluding the terminator. (Optional)
1065 * This may be set under some error conditions,
1066 * however, only for VERR_BUFFER_OVERFLOW and
1067 * VERR_NO_STR_MEMORY will it contain a valid string
1068 * length that can be used to resize the buffer.
1069 * @param pszTag Allocation tag used for statistics and such.
1071 RTDECL(int) RTStrToUtf16ExTag(const char *pszString
, size_t cchString
,
1072 PRTUTF16
*ppwsz
, size_t cwc
, size_t *pcwc
, const char *pszTag
);
1076 * Translates pszString from UTF-8 to UTF-16BE, allocating the result buffer if requested.
1078 * This differs from RTStrToUtf16Ex in that it always produces a
1079 * big-endian string.
1081 * @returns iprt status code.
1082 * @param pszString UTF-8 string to convert.
1083 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
1084 * when it reaches cchString or the string terminator ('\\0').
1085 * Use RTSTR_MAX to translate the entire string.
1086 * @param ppwsz If cwc is non-zero, this must either be pointing to pointer to
1087 * a buffer of the specified size, or pointer to a NULL pointer.
1088 * If *ppwsz is NULL or cwc is zero a buffer of at least cwc items
1089 * will be allocated to hold the translated string.
1090 * If a buffer was requested it must be freed using RTUtf16Free().
1091 * @param cwc The buffer size in RTUTF16s. This includes the terminator.
1092 * @param pcwc Where to store the length of the translated string,
1093 * excluding the terminator. (Optional)
1095 * This may be set under some error conditions,
1096 * however, only for VERR_BUFFER_OVERFLOW and
1097 * VERR_NO_STR_MEMORY will it contain a valid string
1098 * length that can be used to resize the buffer.
1100 #define RTStrToUtf16BigEx(pszString, cchString, ppwsz, cwc, pcwc) \
1101 RTStrToUtf16BigExTag((pszString), (cchString), (ppwsz), (cwc), (pcwc), RTSTR_TAG)
1104 * Translates pszString from UTF-8 to UTF-16BE, allocating the result buffer if
1105 * requested (custom tag).
1107 * This differs from RTStrToUtf16ExTag in that it always produces a
1108 * big-endian string.
1110 * @returns iprt status code.
1111 * @param pszString UTF-8 string to convert.
1112 * @param cchString The maximum size in chars (the type) to convert. The conversion stop
1113 * when it reaches cchString or the string terminator ('\\0').
1114 * Use RTSTR_MAX to translate the entire string.
1115 * @param ppwsz If cwc is non-zero, this must either be pointing to pointer to
1116 * a buffer of the specified size, or pointer to a NULL pointer.
1117 * If *ppwsz is NULL or cwc is zero a buffer of at least cwc items
1118 * will be allocated to hold the translated string.
1119 * If a buffer was requested it must be freed using RTUtf16Free().
1120 * @param cwc The buffer size in RTUTF16s. This includes the terminator.
1121 * @param pcwc Where to store the length of the translated string,
1122 * excluding the terminator. (Optional)
1124 * This may be set under some error conditions,
1125 * however, only for VERR_BUFFER_OVERFLOW and
1126 * VERR_NO_STR_MEMORY will it contain a valid string
1127 * length that can be used to resize the buffer.
1128 * @param pszTag Allocation tag used for statistics and such.
1130 RTDECL(int) RTStrToUtf16BigExTag(const char *pszString
, size_t cchString
,
1131 PRTUTF16
*ppwsz
, size_t cwc
, size_t *pcwc
, const char *pszTag
);
1135 * Calculates the length of the string in Latin-1 characters.
1137 * This function will validate the string, and incorrectly encoded UTF-8
1138 * strings as well as string with codepoints outside the latin-1 range will be
1139 * rejected. The primary purpose of this function is to help allocate buffers
1140 * for RTStrToLatin1Ex of the correct size. For most other purposes
1141 * RTStrCalcLatin1LenEx() should be used.
1143 * @returns Number of Latin-1 characters.
1144 * @returns 0 if the string was incorrectly encoded.
1145 * @param psz The string.
1147 RTDECL(size_t) RTStrCalcLatin1Len(const char *psz
);
1150 * Calculates the length of the string in Latin-1 characters.
1152 * This function will validate the string, and incorrectly encoded UTF-8
1153 * strings as well as string with codepoints outside the latin-1 range will be
1156 * @returns iprt status code.
1157 * @param psz The string.
1158 * @param cch The max string length. Use RTSTR_MAX to process the
1160 * @param pcch Where to store the string length. Optional.
1161 * This is undefined on failure.
1163 RTDECL(int) RTStrCalcLatin1LenEx(const char *psz
, size_t cch
, size_t *pcch
);
1166 * Translate a UTF-8 string into a Latin-1 allocating the result buffer (default
1169 * @returns iprt status code.
1170 * @param pszString UTF-8 string to convert.
1171 * @param ppszString Receives pointer to the allocated Latin-1 string.
1172 * The returned string must be freed using RTStrFree().
1174 #define RTStrToLatin1(pszString, ppszString) RTStrToLatin1Tag((pszString), (ppszString), RTSTR_TAG)
1177 * Translate a UTF-8 string into a Latin-1 allocating the result buffer (custom
1180 * @returns iprt status code.
1181 * @param pszString UTF-8 string to convert.
1182 * @param ppszString Receives pointer to the allocated Latin-1 string.
1183 * The returned string must be freed using RTStrFree().
1184 * @param pszTag Allocation tag used for statistics and such.
1186 RTDECL(int) RTStrToLatin1Tag(const char *pszString
, char **ppszString
, const char *pszTag
);
1189 * Translates pszString from UTF-8 to Latin-1, allocating the result buffer if requested.
1191 * @returns iprt status code.
1192 * @param pszString UTF-8 string to convert.
1193 * @param cchString The maximum size in chars (the type) to convert.
1194 * The conversion stop when it reaches cchString or
1195 * the string terminator ('\\0'). Use RTSTR_MAX to
1196 * translate the entire string.
1197 * @param ppsz If cch is non-zero, this must either be pointing to
1198 * pointer to a buffer of the specified size, or
1199 * pointer to a NULL pointer. If *ppsz is NULL or cch
1200 * is zero a buffer of at least cch items will be
1201 * allocated to hold the translated string. If a
1202 * buffer was requested it must be freed using
1204 * @param cch The buffer size in bytes. This includes the
1206 * @param pcch Where to store the length of the translated string,
1207 * excluding the terminator. (Optional)
1209 * This may be set under some error conditions,
1210 * however, only for VERR_BUFFER_OVERFLOW and
1211 * VERR_NO_STR_MEMORY will it contain a valid string
1212 * length that can be used to resize the buffer.
1214 #define RTStrToLatin1Ex(pszString, cchString, ppsz, cch, pcch) \
1215 RTStrToLatin1ExTag((pszString), (cchString), (ppsz), (cch), (pcch), RTSTR_TAG)
1218 * Translates pszString from UTF-8 to Latin1, allocating the result buffer if
1219 * requested (custom tag).
1221 * @returns iprt status code.
1222 * @param pszString UTF-8 string to convert.
1223 * @param cchString The maximum size in chars (the type) to convert.
1224 * The conversion stop when it reaches cchString or
1225 * the string terminator ('\\0'). Use RTSTR_MAX to
1226 * translate the entire string.
1227 * @param ppsz If cch is non-zero, this must either be pointing to
1228 * pointer to a buffer of the specified size, or
1229 * pointer to a NULL pointer. If *ppsz is NULL or cch
1230 * is zero a buffer of at least cch items will be
1231 * allocated to hold the translated string. If a
1232 * buffer was requested it must be freed using
1234 * @param cch The buffer size in bytes. This includes the
1236 * @param pcch Where to store the length of the translated string,
1237 * excluding the terminator. (Optional)
1239 * This may be set under some error conditions,
1240 * however, only for VERR_BUFFER_OVERFLOW and
1241 * VERR_NO_STR_MEMORY will it contain a valid string
1242 * length that can be used to resize the buffer.
1243 * @param pszTag Allocation tag used for statistics and such.
1245 RTDECL(int) RTStrToLatin1ExTag(const char *pszString
, size_t cchString
, char **ppsz
, size_t cch
, size_t *pcch
, const char *pszTag
);
1248 * Get the unicode code point at the given string position.
1250 * @returns unicode code point.
1251 * @returns RTUNICP_INVALID if the encoding is invalid.
1252 * @param psz The string.
1254 RTDECL(RTUNICP
) RTStrGetCpInternal(const char *psz
);
1257 * Get the unicode code point at the given string position.
1259 * @returns iprt status code
1260 * @returns VERR_INVALID_UTF8_ENCODING if the encoding is invalid.
1261 * @param ppsz The string cursor.
1262 * This is advanced one character forward on failure.
1263 * @param pCp Where to store the unicode code point.
1264 * Stores RTUNICP_INVALID if the encoding is invalid.
1266 RTDECL(int) RTStrGetCpExInternal(const char **ppsz
, PRTUNICP pCp
);
1269 * Get the unicode code point at the given string position for a string of a
1272 * @returns iprt status code
1273 * @retval VERR_INVALID_UTF8_ENCODING if the encoding is invalid.
1274 * @retval VERR_END_OF_STRING if *pcch is 0. *pCp is set to RTUNICP_INVALID.
1276 * @param ppsz The string.
1277 * @param pcch Pointer to the length of the string. This will be
1278 * decremented by the size of the code point.
1279 * @param pCp Where to store the unicode code point.
1280 * Stores RTUNICP_INVALID if the encoding is invalid.
1282 RTDECL(int) RTStrGetCpNExInternal(const char **ppsz
, size_t *pcch
, PRTUNICP pCp
);
1285 * Put the unicode code point at the given string position
1286 * and return the pointer to the char following it.
1288 * This function will not consider anything at or following the
1289 * buffer area pointed to by psz. It is therefore not suitable for
1290 * inserting code points into a string, only appending/overwriting.
1292 * @returns pointer to the char following the written code point.
1293 * @param psz The string.
1294 * @param CodePoint The code point to write.
1295 * This should not be RTUNICP_INVALID or any other
1296 * character out of the UTF-8 range.
1298 * @remark This is a worker function for RTStrPutCp().
1301 RTDECL(char *) RTStrPutCpInternal(char *psz
, RTUNICP CodePoint
);
1304 * Get the unicode code point at the given string position.
1306 * @returns unicode code point.
1307 * @returns RTUNICP_INVALID if the encoding is invalid.
1308 * @param psz The string.
1310 * @remark We optimize this operation by using an inline function for
1311 * the most frequent and simplest sequence, the rest is
1312 * handled by RTStrGetCpInternal().
1314 DECLINLINE(RTUNICP
) RTStrGetCp(const char *psz
)
1316 const unsigned char uch
= *(const unsigned char *)psz
;
1317 if (!(uch
& RT_BIT(7)))
1319 return RTStrGetCpInternal(psz
);
1323 * Get the unicode code point at the given string position.
1325 * @returns iprt status code.
1326 * @param ppsz Pointer to the string pointer. This will be updated to
1327 * point to the char following the current code point.
1328 * This is advanced one character forward on failure.
1329 * @param pCp Where to store the code point.
1330 * RTUNICP_INVALID is stored here on failure.
1332 * @remark We optimize this operation by using an inline function for
1333 * the most frequent and simplest sequence, the rest is
1334 * handled by RTStrGetCpExInternal().
1336 DECLINLINE(int) RTStrGetCpEx(const char **ppsz
, PRTUNICP pCp
)
1338 const unsigned char uch
= **(const unsigned char **)ppsz
;
1339 if (!(uch
& RT_BIT(7)))
1343 return VINF_SUCCESS
;
1345 return RTStrGetCpExInternal(ppsz
, pCp
);
1349 * Get the unicode code point at the given string position for a string of a
1350 * given maximum length.
1352 * @returns iprt status code.
1353 * @retval VERR_INVALID_UTF8_ENCODING if the encoding is invalid.
1354 * @retval VERR_END_OF_STRING if *pcch is 0. *pCp is set to RTUNICP_INVALID.
1356 * @param ppsz Pointer to the string pointer. This will be updated to
1357 * point to the char following the current code point.
1358 * @param pcch Pointer to the maximum string length. This will be
1359 * decremented by the size of the code point found.
1360 * @param pCp Where to store the code point.
1361 * RTUNICP_INVALID is stored here on failure.
1363 * @remark We optimize this operation by using an inline function for
1364 * the most frequent and simplest sequence, the rest is
1365 * handled by RTStrGetCpNExInternal().
1367 DECLINLINE(int) RTStrGetCpNEx(const char **ppsz
, size_t *pcch
, PRTUNICP pCp
)
1369 if (RT_LIKELY(*pcch
!= 0))
1371 const unsigned char uch
= **(const unsigned char **)ppsz
;
1372 if (!(uch
& RT_BIT(7)))
1377 return VINF_SUCCESS
;
1380 return RTStrGetCpNExInternal(ppsz
, pcch
, pCp
);
1384 * Get the UTF-8 size in characters of a given Unicode code point.
1386 * The code point is expected to be a valid Unicode one, but not necessarily in
1387 * the range supported by UTF-8.
1389 * @returns The number of chars (bytes) required to encode the code point, or
1390 * zero if there is no UTF-8 encoding.
1391 * @param CodePoint The unicode code point.
1393 DECLINLINE(size_t) RTStrCpSize(RTUNICP CodePoint
)
1395 if (CodePoint
< 0x00000080)
1397 if (CodePoint
< 0x00000800)
1399 if (CodePoint
< 0x00010000)
1401 #ifdef RT_USE_RTC_3629
1402 if (CodePoint
< 0x00011000)
1405 if (CodePoint
< 0x00200000)
1407 if (CodePoint
< 0x04000000)
1409 if (CodePoint
< 0x7fffffff)
1416 * Put the unicode code point at the given string position
1417 * and return the pointer to the char following it.
1419 * This function will not consider anything at or following the
1420 * buffer area pointed to by psz. It is therefore not suitable for
1421 * inserting code points into a string, only appending/overwriting.
1423 * @returns pointer to the char following the written code point.
1424 * @param psz The string.
1425 * @param CodePoint The code point to write.
1426 * This should not be RTUNICP_INVALID or any other
1427 * character out of the UTF-8 range.
1429 * @remark We optimize this operation by using an inline function for
1430 * the most frequent and simplest sequence, the rest is
1431 * handled by RTStrPutCpInternal().
1433 DECLINLINE(char *) RTStrPutCp(char *psz
, RTUNICP CodePoint
)
1435 if (CodePoint
< 0x80)
1437 *psz
++ = (char)CodePoint
;
1440 return RTStrPutCpInternal(psz
, CodePoint
);
1444 * Skips ahead, past the current code point.
1446 * @returns Pointer to the char after the current code point.
1447 * @param psz Pointer to the current code point.
1448 * @remark This will not move the next valid code point, only past the current one.
1450 DECLINLINE(char *) RTStrNextCp(const char *psz
)
1453 RTStrGetCpEx(&psz
, &Cp
);
1458 * Skips back to the previous code point.
1460 * @returns Pointer to the char before the current code point.
1461 * @returns pszStart on failure.
1462 * @param pszStart Pointer to the start of the string.
1463 * @param psz Pointer to the current code point.
1465 RTDECL(char *) RTStrPrevCp(const char *pszStart
, const char *psz
);
1468 /** @page pg_rt_str_format The IPRT Format Strings
1470 * IPRT implements most of the commonly used format types and flags with the
1471 * exception of floating point which is completely missing. In addition IPRT
1472 * provides a number of IPRT specific format types for the IPRT typedefs and
1473 * other useful things. Note that several of these extensions are similar to
1474 * \%p and doesn't care much if you try add formating flags/width/precision.
1477 * Group 0a, The commonly used format types:
1478 * - \%s - Takes a pointer to a zero terminated string (UTF-8) and
1479 * prints it with the optionally adjustment (width, -) and
1480 * length restriction (precision).
1481 * - \%ls - Same as \%s except that the input is UTF-16 (output UTF-8).
1482 * - \%Ls - Same as \%s except that the input is UCS-32 (output UTF-8).
1483 * - \%S - Same as \%s, used to convert to current codeset but this is
1484 * now done by the streams code. Deprecated, use \%s.
1485 * - \%lS - Ditto. Deprecated, use \%ls.
1486 * - \%LS - Ditto. Deprecated, use \%Ls.
1487 * - \%c - Takes a char and prints it.
1488 * - \%d - Takes a signed integer and prints it as decimal. Thousand
1489 * separator (\'), zero padding (0), adjustment (-+), width,
1491 * - \%i - Same as \%d.
1492 * - \%u - Takes an unsigned integer and prints it as decimal. Thousand
1493 * separator (\'), zero padding (0), adjustment (-+), width,
1495 * - \%x - Takes an unsigned integer and prints it as lowercased
1496 * hexadecimal. The special hash (\#) flag causes a '0x'
1497 * prefixed to be printed. Zero padding (0), adjustment (-+),
1499 * - \%X - Same as \%x except that it is uppercased.
1500 * - \%o - Takes an unsigned (?) integer and prints it as octal. Zero
1501 * padding (0), adjustment (-+), width, precision.
1502 * - \%p - Takes a pointer (void technically) and prints it. Zero
1503 * padding (0), adjustment (-+), width, precision.
1505 * The \%d, \%i, \%u, \%x, \%X and \%o format types support the following
1506 * argument type specifiers:
1507 * - \%ll - long long (uint64_t).
1508 * - \%L - long long (uint64_t).
1509 * - \%l - long (uint32_t, uint64_t)
1510 * - \%h - short (int16_t).
1511 * - \%hh - char (int8_t).
1512 * - \%H - char (int8_t).
1514 * - \%j - intmax_t (int64_t).
1515 * - \%t - ptrdiff_t.
1516 * The type in parentheses is typical sizes, however when printing those types
1517 * you are better off using the special group 2 format types below (\%RX32 and
1521 * Group 0b, IPRT format tricks:
1522 * - %M - Replaces the format string, takes a string pointer.
1523 * - %N - Nested formatting, takes a pointer to a format string
1524 * followed by the pointer to a va_list variable. The va_list
1525 * variable will not be modified and the caller must do va_end()
1526 * on it. Make sure the va_list variable is NOT in a parameter
1527 * list or some gcc versions/targets may get it all wrong.
1530 * Group 1, the basic runtime typedefs (excluding those which obviously are
1532 * - \%RTbool - Takes a bool value and prints 'true', 'false', or '!%d!'.
1533 * - \%RTeic - Takes a #PCRTERRINFO value outputting 'rc: msg',
1534 * or 'rc - msg' with the \# flag.
1535 * - \%RTeim - Takes a #PCRTERRINFO value outputting ': msg', or
1536 * ' - msg' with the \# flag.
1537 * - \%RTfile - Takes a #RTFILE value.
1538 * - \%RTfmode - Takes a #RTFMODE value.
1539 * - \%RTfoff - Takes a #RTFOFF value.
1540 * - \%RTfp16 - Takes a #RTFAR16 value.
1541 * - \%RTfp32 - Takes a #RTFAR32 value.
1542 * - \%RTfp64 - Takes a #RTFAR64 value.
1543 * - \%RTgid - Takes a #RTGID value.
1544 * - \%RTino - Takes a #RTINODE value.
1545 * - \%RTint - Takes a #RTINT value.
1546 * - \%RTiop - Takes a #RTIOPORT value.
1547 * - \%RTldrm - Takes a #RTLDRMOD value.
1548 * - \%RTmac - Takes a #PCRTMAC pointer.
1549 * - \%RTnaddr - Takes a #PCRTNETADDR value.
1550 * - \%RTnaipv4 - Takes a #RTNETADDRIPV4 value.
1551 * - \%RTnaipv6 - Takes a #PCRTNETADDRIPV6 value.
1552 * - \%RTnthrd - Takes a #RTNATIVETHREAD value.
1553 * - \%RTnthrd - Takes a #RTNATIVETHREAD value.
1554 * - \%RTproc - Takes a #RTPROCESS value.
1555 * - \%RTptr - Takes a #RTINTPTR or #RTUINTPTR value (but not void *).
1556 * - \%RTreg - Takes a #RTCCUINTREG value.
1557 * - \%RTsel - Takes a #RTSEL value.
1558 * - \%RTsem - Takes a #RTSEMEVENT, #RTSEMEVENTMULTI, #RTSEMMUTEX, #RTSEMFASTMUTEX, or #RTSEMRW value.
1559 * - \%RTsock - Takes a #RTSOCKET value.
1560 * - \%RTthrd - Takes a #RTTHREAD value.
1561 * - \%RTuid - Takes a #RTUID value.
1562 * - \%RTuint - Takes a #RTUINT value.
1563 * - \%RTunicp - Takes a #RTUNICP value.
1564 * - \%RTutf16 - Takes a #RTUTF16 value.
1565 * - \%RTuuid - Takes a #PCRTUUID and will print the UUID as a string.
1566 * - \%RTxuint - Takes a #RTUINT or #RTINT value, formatting it as hex.
1567 * - \%RGi - Takes a #RTGCINT value.
1568 * - \%RGp - Takes a #RTGCPHYS value.
1569 * - \%RGr - Takes a #RTGCUINTREG value.
1570 * - \%RGu - Takes a #RTGCUINT value.
1571 * - \%RGv - Takes a #RTGCPTR, #RTGCINTPTR or #RTGCUINTPTR value.
1572 * - \%RGx - Takes a #RTGCUINT or #RTGCINT value, formatting it as hex.
1573 * - \%RHi - Takes a #RTHCINT value.
1574 * - \%RHp - Takes a #RTHCPHYS value.
1575 * - \%RHr - Takes a #RTHCUINTREG value.
1576 * - \%RHu - Takes a #RTHCUINT value.
1577 * - \%RHv - Takes a #RTHCPTR, #RTHCINTPTR or #RTHCUINTPTR value.
1578 * - \%RHx - Takes a #RTHCUINT or #RTHCINT value, formatting it as hex.
1579 * - \%RRv - Takes a #RTRCPTR, #RTRCINTPTR or #RTRCUINTPTR value.
1580 * - \%RCi - Takes a #RTINT value.
1581 * - \%RCp - Takes a #RTCCPHYS value.
1582 * - \%RCr - Takes a #RTCCUINTREG value.
1583 * - \%RCu - Takes a #RTUINT value.
1584 * - \%RCv - Takes a #uintptr_t, #intptr_t, void * value.
1585 * - \%RCx - Takes a #RTUINT or #RTINT value, formatting it as hex.
1588 * Group 2, the generic integer types which are prefered over relying on what
1589 * bit-count a 'long', 'short', or 'long long' has on a platform. This are
1590 * highly prefered for the [u]intXX_t kind of types:
1591 * - \%RI[8|16|32|64] - Signed integer value of the specifed bit count.
1592 * - \%RU[8|16|32|64] - Unsigned integer value of the specifed bit count.
1593 * - \%RX[8|16|32|64] - Hexadecimal integer value of the specifed bit count.
1596 * Group 3, hex dumpers and other complex stuff which requires more than simple
1598 * - \%Rhxd - Takes a pointer to the memory which is to be dumped in typical
1599 * hex format. Use the precision to specify the length, and the width to
1600 * set the number of bytes per line. Default width and precision is 16.
1601 * - \%RhxD - Same as \%Rhxd, except that it skips duplicate lines.
1602 * - \%Rhxs - Takes a pointer to the memory to be displayed as a hex string,
1603 * i.e. a series of space separated bytes formatted as two digit hex value.
1604 * Use the precision to specify the length. Default length is 16 bytes.
1605 * The width, if specified, is ignored.
1606 * The space separtor can get change to a colon by
1607 * using the ' flag, and removed entirely using \#.
1608 * - \%RhXd - Same as \%Rhxd, but takes an additional uint64_t
1609 * value with the memory start address/offset after
1610 * the memory pointer.
1611 * - \%RhXD - Same as \%RhxD, but takes an additional uint64_t
1612 * value with the memory start address/offset after
1613 * the memory pointer.
1614 * - \%RhXs - Same as \%Rhxs, but takes an additional uint64_t
1615 * value with the memory start address/offset after
1616 * the memory pointer.
1618 * - \%Rhcb - Human readable byte size formatting, using
1619 * binary unit prefixes (GiB, MiB and such). Takes a
1620 * 64-bit unsigned integer as input. Does one
1621 * decimal point by default, can do 0-3 via precision
1622 * field. No rounding when calculating fraction.
1623 * The space flag add a space between the value and
1625 * - \%RhcB - Same a \%Rhcb only the 'i' is skipped in the unit.
1626 * - \%Rhci - SI variant of \%Rhcb, fraction is rounded.
1627 * - \%Rhub - Human readable number formatting, using
1628 * binary unit prefixes. Takes a 64-bit unsigned
1629 * integer as input. Does one decimal point by
1630 * default, can do 0-3 via precision field. No
1631 * rounding when calculating fraction. The space
1632 * flag add a space between the value and unit.
1633 * - \%RhuB - Same a \%Rhub only the 'i' is skipped in the unit.
1634 * - \%Rhui - SI variant of \%Rhub, fraction is rounded.
1636 * - \%Rrc - Takes an integer iprt status code as argument. Will insert the
1637 * status code define corresponding to the iprt status code.
1638 * - \%Rrs - Takes an integer iprt status code as argument. Will insert the
1639 * short description of the specified status code.
1640 * - \%Rrf - Takes an integer iprt status code as argument. Will insert the
1641 * full description of the specified status code.
1642 * Note! Works like \%Rrs when IN_RT_STATIC is defined (so please avoid).
1643 * - \%Rra - Takes an integer iprt status code as argument. Will insert the
1644 * status code define + full description.
1645 * Note! Reduced output when IN_RT_STATIC is defined (so please avoid).
1646 * - \%Rwc - Takes a long Windows error code as argument. Will insert the status
1647 * code define corresponding to the Windows error code.
1648 * - \%Rwf - Takes a long Windows error code as argument. Will insert the
1649 * full description of the specified status code.
1650 * Note! Works like \%Rwc when IN_RT_STATIC is defined.
1651 * - \%Rwa - Takes a long Windows error code as argument. Will insert the
1652 * error code define + full description.
1653 * Note! Reduced output when IN_RT_STATIC is defined (so please avoid).
1655 * - \%Rhrc - Takes a COM/XPCOM status code as argument. Will insert the status
1656 * code define corresponding to the Windows error code.
1657 * - \%Rhrf - Takes a COM/XPCOM status code as argument. Will insert the
1658 * full description of the specified status code.
1659 * Note! Works like \%Rhrc when IN_RT_STATIC is
1660 * defined on Windows (so please avoid).
1661 * - \%Rhra - Takes a COM/XPCOM error code as argument. Will insert the
1662 * error code define + full description.
1663 * Note! Reduced output when IN_RT_STATIC is defined on Windows (so please avoid).
1665 * - \%Rfn - Pretty printing of a function or method. It drops the
1666 * return code and parameter list.
1667 * - \%Rbn - Prints the base name. For dropping the path in
1668 * order to save space when printing a path name.
1670 * - \%lRbs - Same as \%ls except inlut is big endian UTF-16.
1672 * On other platforms, \%Rw? simply prints the argument in a form of 0xXXXXXXXX.
1675 * Group 4, structure dumpers:
1676 * - \%RDtimespec - Takes a PCRTTIMESPEC.
1679 * Group 5, XML / HTML, JSON and URI escapers:
1680 * - \%RMas - Takes a string pointer (const char *) and outputs
1681 * it as an attribute value with the proper escaping.
1682 * This typically ends up in double quotes.
1684 * - \%RMes - Takes a string pointer (const char *) and outputs
1685 * it as an element with the necessary escaping.
1687 * - \%RMjs - Takes a string pointer (const char *) and outputs
1688 * it in quotes with proper JSON escaping.
1690 * - \%RMpa - Takes a string pointer (const char *) and outputs
1691 * it percent-encoded (RFC-3986). All reserved characters
1694 * - \%RMpf - Takes a string pointer (const char *) and outputs
1695 * it percent-encoded (RFC-3986), form style. This
1696 * means '+' is used to escape space (' ') and '%2B'
1697 * is used to escape '+'.
1699 * - \%RMpp - Takes a string pointer (const char *) and outputs
1700 * it percent-encoded (RFC-3986), path style. This
1701 * means '/' will not be escaped.
1703 * - \%RMpq - Takes a string pointer (const char *) and outputs
1704 * it percent-encoded (RFC-3986), query style. This
1705 * means '+' will not be escaped.
1708 * Group 6, CPU Architecture Register dumpers:
1709 * - \%RAx86[reg] - Takes a 64-bit register value if the register is
1710 * 64-bit or smaller. Check the code wrt which
1711 * registers are implemented.
1715 #ifndef DECLARED_FNRTSTROUTPUT /* duplicated in iprt/log.h & errcore.h */
1716 # define DECLARED_FNRTSTROUTPUT
1720 * @returns number of bytes written.
1721 * @param pvArg User argument.
1722 * @param pachChars Pointer to an array of utf-8 characters.
1723 * @param cbChars Number of bytes in the character array pointed to by pachChars.
1725 typedef DECLCALLBACKTYPE(size_t, FNRTSTROUTPUT
,(void *pvArg
, const char *pachChars
, size_t cbChars
));
1726 /** Pointer to callback function. */
1727 typedef FNRTSTROUTPUT
*PFNRTSTROUTPUT
;
1730 /** @name Format flag.
1731 * These are used by RTStrFormat extensions and RTStrFormatNumber, mind
1732 * that not all flags makes sense to both of the functions.
1734 #define RTSTR_F_CAPITAL 0x0001
1735 #define RTSTR_F_LEFT 0x0002
1736 #define RTSTR_F_ZEROPAD 0x0004
1737 #define RTSTR_F_SPECIAL 0x0008
1738 #define RTSTR_F_VALSIGNED 0x0010
1739 #define RTSTR_F_PLUS 0x0020
1740 #define RTSTR_F_BLANK 0x0040
1741 #define RTSTR_F_WIDTH 0x0080
1742 #define RTSTR_F_PRECISION 0x0100
1743 #define RTSTR_F_THOUSAND_SEP 0x0200
1744 #define RTSTR_F_OBFUSCATE_PTR 0x0400
1746 #define RTSTR_F_BIT_MASK 0xf800
1747 #define RTSTR_F_8BIT 0x0800
1748 #define RTSTR_F_16BIT 0x1000
1749 #define RTSTR_F_32BIT 0x2000
1750 #define RTSTR_F_64BIT 0x4000
1751 #define RTSTR_F_128BIT 0x8000
1754 /** @def RTSTR_GET_BIT_FLAG
1755 * Gets the bit flag for the specified type.
1757 #define RTSTR_GET_BIT_FLAG(type) \
1758 ( sizeof(type) * 8 == 32 ? RTSTR_F_32BIT \
1759 : sizeof(type) * 8 == 64 ? RTSTR_F_64BIT \
1760 : sizeof(type) * 8 == 16 ? RTSTR_F_16BIT \
1761 : sizeof(type) * 8 == 8 ? RTSTR_F_8BIT \
1762 : sizeof(type) * 8 == 128 ? RTSTR_F_128BIT \
1767 * Callback to format non-standard format specifiers.
1769 * @returns The number of bytes formatted.
1770 * @param pvArg Formatter argument.
1771 * @param pfnOutput Pointer to output function.
1772 * @param pvArgOutput Argument for the output function.
1773 * @param ppszFormat Pointer to the format string pointer. Advance this till the char
1774 * after the format specifier.
1775 * @param pArgs Pointer to the argument list. Use this to fetch the arguments.
1776 * @param cchWidth Format Width. -1 if not specified.
1777 * @param cchPrecision Format Precision. -1 if not specified.
1778 * @param fFlags Flags (RTSTR_NTFS_*).
1779 * @param chArgSize The argument size specifier, 'l' or 'L'.
1781 typedef DECLCALLBACKTYPE(size_t, FNSTRFORMAT
,(void *pvArg
, PFNRTSTROUTPUT pfnOutput
, void *pvArgOutput
,
1782 const char **ppszFormat
, va_list *pArgs
, int cchWidth
,
1783 int cchPrecision
, unsigned fFlags
, char chArgSize
));
1784 /** Pointer to a FNSTRFORMAT() function. */
1785 typedef FNSTRFORMAT
*PFNSTRFORMAT
;
1789 * Partial implementation of a printf like formatter.
1790 * It doesn't do everything correct, and there is no floating point support.
1791 * However, it supports custom formats by the means of a format callback.
1793 * @returns number of bytes formatted.
1794 * @param pfnOutput Output worker.
1795 * Called in two ways. Normally with a string and its length.
1796 * For termination, it's called with NULL for string, 0 for length.
1797 * @param pvArgOutput Argument to the output worker.
1798 * @param pfnFormat Custom format worker.
1799 * @param pvArgFormat Argument to the format worker.
1800 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
1801 * @param InArgs Argument list.
1803 RTDECL(size_t) RTStrFormatV(PFNRTSTROUTPUT pfnOutput
, void *pvArgOutput
, PFNSTRFORMAT pfnFormat
, void *pvArgFormat
,
1804 const char *pszFormat
, va_list InArgs
) RT_IPRT_FORMAT_ATTR(5, 0);
1807 * Partial implementation of a printf like formatter.
1809 * It doesn't do everything correct, and there is no floating point support.
1810 * However, it supports custom formats by the means of a format callback.
1812 * @returns number of bytes formatted.
1813 * @param pfnOutput Output worker.
1814 * Called in two ways. Normally with a string and its length.
1815 * For termination, it's called with NULL for string, 0 for length.
1816 * @param pvArgOutput Argument to the output worker.
1817 * @param pfnFormat Custom format worker.
1818 * @param pvArgFormat Argument to the format worker.
1819 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
1820 * @param ... Argument list.
1822 RTDECL(size_t) RTStrFormat(PFNRTSTROUTPUT pfnOutput
, void *pvArgOutput
, PFNSTRFORMAT pfnFormat
, void *pvArgFormat
,
1823 const char *pszFormat
, ...) RT_IPRT_FORMAT_ATTR(5, 6);
1826 * Formats an integer number according to the parameters.
1828 * @returns Length of the formatted number.
1829 * @param psz Pointer to output string buffer of sufficient size.
1830 * @param u64Value Value to format.
1831 * @param uiBase Number representation base.
1832 * @param cchWidth Width.
1833 * @param cchPrecision Precision.
1834 * @param fFlags Flags, RTSTR_F_XXX.
1836 RTDECL(int) RTStrFormatNumber(char *psz
, uint64_t u64Value
, unsigned int uiBase
, signed int cchWidth
, signed int cchPrecision
,
1837 unsigned int fFlags
);
1840 * Formats an unsigned 8-bit number.
1842 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1843 * @param pszBuf The output buffer.
1844 * @param cbBuf The size of the output buffer.
1845 * @param u8Value The value to format.
1846 * @param uiBase Number representation base.
1847 * @param cchWidth Width.
1848 * @param cchPrecision Precision.
1849 * @param fFlags Flags, RTSTR_F_XXX.
1851 RTDECL(ssize_t
) RTStrFormatU8(char *pszBuf
, size_t cbBuf
, uint8_t u8Value
, unsigned int uiBase
,
1852 signed int cchWidth
, signed int cchPrecision
, uint32_t fFlags
);
1855 * Formats an unsigned 16-bit number.
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 u16Value The value to format.
1861 * @param uiBase Number representation base.
1862 * @param cchWidth Width.
1863 * @param cchPrecision Precision.
1864 * @param fFlags Flags, RTSTR_F_XXX.
1866 RTDECL(ssize_t
) RTStrFormatU16(char *pszBuf
, size_t cbBuf
, uint16_t u16Value
, unsigned int uiBase
,
1867 signed int cchWidth
, signed int cchPrecision
, uint32_t fFlags
);
1870 * Formats an unsigned 32-bit number.
1872 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1873 * @param pszBuf The output buffer.
1874 * @param cbBuf The size of the output buffer.
1875 * @param u32Value The value to format.
1876 * @param uiBase Number representation base.
1877 * @param cchWidth Width.
1878 * @param cchPrecision Precision.
1879 * @param fFlags Flags, RTSTR_F_XXX.
1881 RTDECL(ssize_t
) RTStrFormatU32(char *pszBuf
, size_t cbBuf
, uint32_t u32Value
, unsigned int uiBase
,
1882 signed int cchWidth
, signed int cchPrecision
, uint32_t fFlags
);
1885 * Formats an unsigned 64-bit number.
1887 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1888 * @param pszBuf The output buffer.
1889 * @param cbBuf The size of the output buffer.
1890 * @param u64Value The value to format.
1891 * @param uiBase Number representation base.
1892 * @param cchWidth Width.
1893 * @param cchPrecision Precision.
1894 * @param fFlags Flags, RTSTR_F_XXX.
1896 RTDECL(ssize_t
) RTStrFormatU64(char *pszBuf
, size_t cbBuf
, uint64_t u64Value
, unsigned int uiBase
,
1897 signed int cchWidth
, signed int cchPrecision
, uint32_t fFlags
);
1900 * Formats an unsigned 128-bit number.
1902 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1903 * @param pszBuf The output buffer.
1904 * @param cbBuf The size of the output buffer.
1905 * @param pu128Value The value to format.
1906 * @param uiBase Number representation base.
1907 * @param cchWidth Width.
1908 * @param cchPrecision Precision.
1909 * @param fFlags Flags, RTSTR_F_XXX.
1910 * @remarks The current implementation is limited to base 16 and doesn't do
1911 * width or precision and probably ignores few flags too.
1913 RTDECL(ssize_t
) RTStrFormatU128(char *pszBuf
, size_t cbBuf
, PCRTUINT128U pu128Value
, unsigned int uiBase
,
1914 signed int cchWidth
, signed int cchPrecision
, uint32_t fFlags
);
1917 * Formats an unsigned 256-bit number.
1919 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1920 * @param pszBuf The output buffer.
1921 * @param cbBuf The size of the output buffer.
1922 * @param pu256Value The value to format.
1923 * @param uiBase Number representation base.
1924 * @param cchWidth Width.
1925 * @param cchPrecision Precision.
1926 * @param fFlags Flags, RTSTR_F_XXX.
1927 * @remarks The current implementation is limited to base 16 and doesn't do
1928 * width or precision and probably ignores few flags too.
1930 RTDECL(ssize_t
) RTStrFormatU256(char *pszBuf
, size_t cbBuf
, PCRTUINT256U pu256Value
, unsigned int uiBase
,
1931 signed int cchWidth
, signed int cchPrecision
, uint32_t fFlags
);
1934 * Formats an unsigned 512-bit number.
1936 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1937 * @param pszBuf The output buffer.
1938 * @param cbBuf The size of the output buffer.
1939 * @param pu512Value The value to format.
1940 * @param uiBase Number representation base.
1941 * @param cchWidth Width.
1942 * @param cchPrecision Precision.
1943 * @param fFlags Flags, RTSTR_F_XXX.
1944 * @remarks The current implementation is limited to base 16 and doesn't do
1945 * width or precision and probably ignores few flags too.
1947 RTDECL(ssize_t
) RTStrFormatU512(char *pszBuf
, size_t cbBuf
, PCRTUINT512U pu512Value
, unsigned int uiBase
,
1948 signed int cchWidth
, signed int cchPrecision
, uint32_t fFlags
);
1951 * Formats an 32-bit extended floating point number.
1953 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1954 * @param pszBuf The output buffer.
1955 * @param cbBuf The size of the output buffer.
1956 * @param pr32Value The value to format.
1957 * @param cchWidth Width.
1958 * @param cchPrecision Precision.
1959 * @param fFlags Flags, RTSTR_F_XXX.
1961 RTDECL(ssize_t
) RTStrFormatR32(char *pszBuf
, size_t cbBuf
, PCRTFLOAT32U pr32Value
, signed int cchWidth
,
1962 signed int cchPrecision
, uint32_t fFlags
);
1965 * Formats an 64-bit extended floating point number.
1967 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1968 * @param pszBuf The output buffer.
1969 * @param cbBuf The size of the output buffer.
1970 * @param pr64Value The value to format.
1971 * @param cchWidth Width.
1972 * @param cchPrecision Precision.
1973 * @param fFlags Flags, RTSTR_F_XXX.
1975 RTDECL(ssize_t
) RTStrFormatR64(char *pszBuf
, size_t cbBuf
, PCRTFLOAT64U pr64Value
, signed int cchWidth
,
1976 signed int cchPrecision
, uint32_t fFlags
);
1978 #if !defined(__IBMCPP__) && !defined(__IBMC__)
1981 * Formats an 80-bit extended floating point number.
1983 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1984 * @param pszBuf The output buffer.
1985 * @param cbBuf The size of the output buffer.
1986 * @param pr80Value The value to format.
1987 * @param cchWidth Width.
1988 * @param cchPrecision Precision.
1989 * @param fFlags Flags, RTSTR_F_XXX.
1991 RTDECL(ssize_t
) RTStrFormatR80(char *pszBuf
, size_t cbBuf
, PCRTFLOAT80U pr80Value
, signed int cchWidth
,
1992 signed int cchPrecision
, uint32_t fFlags
);
1995 * Formats an 80-bit extended floating point number, version 2.
1997 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
1998 * @param pszBuf The output buffer.
1999 * @param cbBuf The size of the output buffer.
2000 * @param pr80Value The value to format.
2001 * @param cchWidth Width.
2002 * @param cchPrecision Precision.
2003 * @param fFlags Flags, RTSTR_F_XXX.
2005 RTDECL(ssize_t
) RTStrFormatR80u2(char *pszBuf
, size_t cbBuf
, PCRTFLOAT80U2 pr80Value
, signed int cchWidth
,
2006 signed int cchPrecision
, uint32_t fFlags
);
2008 #endif /* uint16_t bitfields doesn't work */
2012 * Callback for formatting a type.
2014 * This is registered using the RTStrFormatTypeRegister function and will
2015 * be called during string formatting to handle the specified %R[type].
2016 * The argument for this format type is assumed to be a pointer and it's
2017 * passed in the @a pvValue argument.
2019 * @returns Length of the formatted output.
2020 * @param pfnOutput Output worker.
2021 * @param pvArgOutput Argument to the output worker.
2022 * @param pszType The type name.
2023 * @param pvValue The argument value.
2024 * @param cchWidth Width.
2025 * @param cchPrecision Precision.
2026 * @param fFlags Flags (NTFS_*).
2027 * @param pvUser The user argument.
2029 typedef DECLCALLBACKTYPE(size_t, FNRTSTRFORMATTYPE
,(PFNRTSTROUTPUT pfnOutput
, void *pvArgOutput
,
2030 const char *pszType
, void const *pvValue
,
2031 int cchWidth
, int cchPrecision
, unsigned fFlags
,
2033 /** Pointer to a FNRTSTRFORMATTYPE. */
2034 typedef FNRTSTRFORMATTYPE
*PFNRTSTRFORMATTYPE
;
2038 * Register a format handler for a type.
2040 * The format handler is used to handle '%R[type]' format types, where the argument
2041 * in the vector is a pointer value (a bit restrictive, but keeps it simple).
2043 * The caller must ensure that no other thread will be making use of any of
2044 * the dynamic formatting type facilities simultaneously with this call.
2046 * @returns IPRT status code.
2047 * @retval VINF_SUCCESS on success.
2048 * @retval VERR_ALREADY_EXISTS if the type has already been registered.
2049 * @retval VERR_TOO_MANY_OPEN_FILES if all the type slots has been allocated already.
2051 * @param pszType The type name.
2052 * @param pfnHandler The handler address. See FNRTSTRFORMATTYPE for details.
2053 * @param pvUser The user argument to pass to the handler. See RTStrFormatTypeSetUser
2054 * for how to update this later.
2056 RTDECL(int) RTStrFormatTypeRegister(const char *pszType
, PFNRTSTRFORMATTYPE pfnHandler
, void *pvUser
);
2059 * Deregisters a format type.
2061 * The caller must ensure that no other thread will be making use of any of
2062 * the dynamic formatting type facilities simultaneously with this call.
2064 * @returns IPRT status code.
2065 * @retval VINF_SUCCESS on success.
2066 * @retval VERR_FILE_NOT_FOUND if not found.
2068 * @param pszType The type to deregister.
2070 RTDECL(int) RTStrFormatTypeDeregister(const char *pszType
);
2073 * Sets the user argument for a type.
2075 * This can be used if a user argument needs relocating in GC.
2077 * @returns IPRT status code.
2078 * @retval VINF_SUCCESS on success.
2079 * @retval VERR_FILE_NOT_FOUND if not found.
2081 * @param pszType The type to update.
2082 * @param pvUser The new user argument value.
2084 RTDECL(int) RTStrFormatTypeSetUser(const char *pszType
, void *pvUser
);
2090 * @returns The length of the returned string (in pszBuffer) excluding the
2092 * @param pszBuffer Output buffer.
2093 * @param cchBuffer Size of the output buffer.
2094 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2095 * @param args The format argument.
2097 * @deprecated Use RTStrPrintf2V! Problematic return value on overflow.
2099 RTDECL(size_t) RTStrPrintfV(char *pszBuffer
, size_t cchBuffer
, const char *pszFormat
, va_list args
) RT_IPRT_FORMAT_ATTR(3, 0);
2104 * @returns The length of the returned string (in pszBuffer) excluding the
2106 * @param pszBuffer Output buffer.
2107 * @param cchBuffer Size of the output buffer.
2108 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2109 * @param ... The format argument.
2111 * @deprecated Use RTStrPrintf2! Problematic return value on overflow.
2113 RTDECL(size_t) RTStrPrintf(char *pszBuffer
, size_t cchBuffer
, const char *pszFormat
, ...) RT_IPRT_FORMAT_ATTR(3, 4);
2116 * String printf with custom formatting.
2118 * @returns The length of the returned string (in pszBuffer) excluding the
2120 * @param pfnFormat Pointer to handler function for the custom formats.
2121 * @param pvArg Argument to the pfnFormat function.
2122 * @param pszBuffer Output buffer.
2123 * @param cchBuffer Size of the output buffer.
2124 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2125 * @param args The format argument.
2127 * @deprecated Use RTStrPrintf2ExV! Problematic return value on overflow.
2129 RTDECL(size_t) RTStrPrintfExV(PFNSTRFORMAT pfnFormat
, void *pvArg
, char *pszBuffer
, size_t cchBuffer
,
2130 const char *pszFormat
, va_list args
) RT_IPRT_FORMAT_ATTR(5, 0);
2133 * String printf with custom formatting.
2135 * @returns The length of the returned string (in pszBuffer) excluding the
2137 * @param pfnFormat Pointer to handler function for the custom formats.
2138 * @param pvArg Argument to the pfnFormat function.
2139 * @param pszBuffer Output buffer.
2140 * @param cchBuffer Size of the output buffer.
2141 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2142 * @param ... The format argument.
2144 * @deprecated Use RTStrPrintf2Ex! Problematic return value on overflow.
2146 RTDECL(size_t) RTStrPrintfEx(PFNSTRFORMAT pfnFormat
, void *pvArg
, char *pszBuffer
, size_t cchBuffer
,
2147 const char *pszFormat
, ...) RT_IPRT_FORMAT_ATTR(5, 6);
2150 * String printf, version 2.
2152 * @returns On success, positive count of formatted character excluding the
2153 * terminator. On buffer overflow, negative number giving the required
2154 * buffer size (including terminator char).
2156 * @param pszBuffer Output buffer.
2157 * @param cbBuffer Size of the output buffer.
2158 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2159 * @param args The format argument.
2161 RTDECL(ssize_t
) RTStrPrintf2V(char *pszBuffer
, size_t cbBuffer
, const char *pszFormat
, va_list args
) RT_IPRT_FORMAT_ATTR(3, 0);
2164 * String printf, version 2.
2166 * @returns On success, positive count of formatted character excluding the
2167 * terminator. On buffer overflow, negative number giving the required
2168 * buffer size (including terminator char).
2170 * @param pszBuffer Output buffer.
2171 * @param cbBuffer Size of the output buffer.
2172 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2173 * @param ... The format argument.
2175 RTDECL(ssize_t
) RTStrPrintf2(char *pszBuffer
, size_t cbBuffer
, const char *pszFormat
, ...) RT_IPRT_FORMAT_ATTR(3, 4);
2178 * String printf with custom formatting, version 2.
2180 * @returns On success, positive count of formatted character excluding the
2181 * terminator. On buffer overflow, negative number giving the required
2182 * buffer size (including terminator char).
2184 * @param pfnFormat Pointer to handler function for the custom formats.
2185 * @param pvArg Argument to the pfnFormat function.
2186 * @param pszBuffer Output buffer.
2187 * @param cbBuffer Size of the output buffer.
2188 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2189 * @param args The format argument.
2191 RTDECL(ssize_t
) RTStrPrintf2ExV(PFNSTRFORMAT pfnFormat
, void *pvArg
, char *pszBuffer
, size_t cbBuffer
,
2192 const char *pszFormat
, va_list args
) RT_IPRT_FORMAT_ATTR(5, 0);
2195 * String printf with custom formatting, version 2.
2197 * @returns On success, positive count of formatted character excluding the
2198 * terminator. On buffer overflow, negative number giving the required
2199 * buffer size (including terminator char).
2201 * @param pfnFormat Pointer to handler function for the custom formats.
2202 * @param pvArg Argument to the pfnFormat function.
2203 * @param pszBuffer Output buffer.
2204 * @param cbBuffer Size of the output buffer.
2205 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2206 * @param ... The format argument.
2208 RTDECL(ssize_t
) RTStrPrintf2Ex(PFNSTRFORMAT pfnFormat
, void *pvArg
, char *pszBuffer
, size_t cbBuffer
,
2209 const char *pszFormat
, ...) RT_IPRT_FORMAT_ATTR(5, 6);
2212 * Allocating string printf (default tag).
2214 * @returns The length of the string in the returned *ppszBuffer excluding the
2216 * @returns -1 on failure.
2217 * @param ppszBuffer Where to store the pointer to the allocated output buffer.
2218 * The buffer should be freed using RTStrFree().
2219 * On failure *ppszBuffer will be set to NULL.
2220 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2221 * @param args The format argument.
2223 #define RTStrAPrintfV(ppszBuffer, pszFormat, args) RTStrAPrintfVTag((ppszBuffer), (pszFormat), (args), RTSTR_TAG)
2226 * Allocating string printf (custom tag).
2228 * @returns The length of the string in the returned *ppszBuffer excluding the
2230 * @returns -1 on failure.
2231 * @param ppszBuffer Where to store the pointer to the allocated output buffer.
2232 * The buffer should be freed using RTStrFree().
2233 * On failure *ppszBuffer will be set to NULL.
2234 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2235 * @param args The format argument.
2236 * @param pszTag Allocation tag used for statistics and such.
2238 RTDECL(int) RTStrAPrintfVTag(char **ppszBuffer
, const char *pszFormat
, va_list args
, const char *pszTag
) RT_IPRT_FORMAT_ATTR(2, 0);
2241 * Allocating string printf.
2243 * @returns The length of the string in the returned *ppszBuffer excluding the
2245 * @returns -1 on failure.
2246 * @param ppszBuffer Where to store the pointer to the allocated output buffer.
2247 * The buffer should be freed using RTStrFree().
2248 * On failure *ppszBuffer will be set to NULL.
2249 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2250 * @param ... The format argument.
2252 DECLINLINE(int) RT_IPRT_FORMAT_ATTR(2, 3) RTStrAPrintf(char **ppszBuffer
, const char *pszFormat
, ...)
2256 va_start(va
, pszFormat
);
2257 cbRet
= RTStrAPrintfVTag(ppszBuffer
, pszFormat
, va
, RTSTR_TAG
);
2263 * Allocating string printf (custom tag).
2265 * @returns The length of the string in the returned *ppszBuffer excluding the
2267 * @returns -1 on failure.
2268 * @param ppszBuffer Where to store the pointer to the allocated output buffer.
2269 * The buffer should be freed using RTStrFree().
2270 * On failure *ppszBuffer will be set to NULL.
2271 * @param pszTag Allocation tag used for statistics and such.
2272 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2273 * @param ... The format argument.
2275 DECLINLINE(int) RT_IPRT_FORMAT_ATTR(3, 4) RTStrAPrintfTag(char **ppszBuffer
, const char *pszTag
, const char *pszFormat
, ...)
2279 va_start(va
, pszFormat
);
2280 cbRet
= RTStrAPrintfVTag(ppszBuffer
, pszFormat
, va
, pszTag
);
2286 * Allocating string printf, version 2.
2288 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
2290 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2291 * @param args The format argument.
2293 #define RTStrAPrintf2V(pszFormat, args) RTStrAPrintf2VTag((pszFormat), (args), RTSTR_TAG)
2296 * Allocating string printf, version 2.
2298 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
2300 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2301 * @param args The format argument.
2302 * @param pszTag Allocation tag used for statistics and such.
2304 RTDECL(char *) RTStrAPrintf2VTag(const char *pszFormat
, va_list args
, const char *pszTag
) RT_IPRT_FORMAT_ATTR(1, 0);
2307 * Allocating string printf, version 2 (default tag).
2309 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
2311 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2312 * @param ... The format argument.
2314 DECLINLINE(char *) RT_IPRT_FORMAT_ATTR(1, 2) RTStrAPrintf2(const char *pszFormat
, ...)
2318 va_start(va
, pszFormat
);
2319 pszRet
= RTStrAPrintf2VTag(pszFormat
, va
, RTSTR_TAG
);
2325 * Allocating string printf, version 2 (custom tag).
2327 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
2329 * @param pszTag Allocation tag used for statistics and such.
2330 * @param pszFormat Pointer to the format string, @see pg_rt_str_format.
2331 * @param ... The format argument.
2333 DECLINLINE(char *) RT_IPRT_FORMAT_ATTR(2, 3) RTStrAPrintf2Tag(const char *pszTag
, const char *pszFormat
, ...)
2337 va_start(va
, pszFormat
);
2338 pszRet
= RTStrAPrintf2VTag(pszFormat
, va
, pszTag
);
2344 * Strips blankspaces from both ends of the string.
2346 * @returns Pointer to first non-blank char in the string.
2347 * @param psz The string to strip.
2349 RTDECL(char *) RTStrStrip(char *psz
);
2352 * Strips blankspaces from the start of the string.
2354 * @returns Pointer to first non-blank char in the string.
2355 * @param psz The string to strip.
2357 RTDECL(char *) RTStrStripL(const char *psz
);
2360 * Strips blankspaces from the end of the string.
2363 * @param psz The string to strip.
2365 RTDECL(char *) RTStrStripR(char *psz
);
2368 * String copy with overflow handling.
2370 * @retval VINF_SUCCESS on success.
2371 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2372 * buffer will contain as much of the string as it can hold, fully
2375 * @param pszDst The destination buffer.
2376 * @param cbDst The size of the destination buffer (in bytes).
2377 * @param pszSrc The source string. NULL is not OK.
2379 RTDECL(int) RTStrCopy(char *pszDst
, size_t cbDst
, const char *pszSrc
);
2382 * String copy with overflow handling.
2384 * @retval VINF_SUCCESS on success.
2385 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2386 * buffer will contain as much of the string as it can hold, fully
2389 * @param pszDst The destination buffer.
2390 * @param cbDst The size of the destination buffer (in bytes).
2391 * @param pszSrc The source string. NULL is not OK.
2392 * @param cchSrcMax The maximum number of chars (not code points) to
2393 * copy from the source string, not counting the
2394 * terminator as usual.
2396 RTDECL(int) RTStrCopyEx(char *pszDst
, size_t cbDst
, const char *pszSrc
, size_t cchSrcMax
);
2399 * String copy with overflow handling and buffer advancing.
2401 * @retval VINF_SUCCESS on success.
2402 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2403 * buffer will contain as much of the string as it can hold, fully
2406 * @param ppszDst Pointer to the destination buffer pointer.
2407 * This will be advanced to the end of the copied
2408 * bytes (points at the terminator). This is also
2409 * updated on overflow.
2410 * @param pcbDst Pointer to the destination buffer size
2411 * variable. This will be updated in accord with
2412 * the buffer pointer.
2413 * @param pszSrc The source string. NULL is not OK.
2415 RTDECL(int) RTStrCopyP(char **ppszDst
, size_t *pcbDst
, const char *pszSrc
);
2418 * String copy with overflow handling.
2420 * @retval VINF_SUCCESS on success.
2421 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2422 * buffer will contain as much of the string as it can hold, fully
2425 * @param ppszDst Pointer to the destination buffer pointer.
2426 * This will be advanced to the end of the copied
2427 * bytes (points at the terminator). This is also
2428 * updated on overflow.
2429 * @param pcbDst Pointer to the destination buffer size
2430 * variable. This will be updated in accord with
2431 * the buffer pointer.
2432 * @param pszSrc The source string. NULL is not OK.
2433 * @param cchSrcMax The maximum number of chars (not code points) to
2434 * copy from the source string, not counting the
2435 * terminator as usual.
2437 RTDECL(int) RTStrCopyPEx(char **ppszDst
, size_t *pcbDst
, const char *pszSrc
, size_t cchSrcMax
);
2440 * String concatenation with overflow handling.
2442 * @retval VINF_SUCCESS on success.
2443 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2444 * buffer will contain as much of the string as it can hold, fully
2447 * @param pszDst The destination buffer.
2448 * @param cbDst The size of the destination buffer (in bytes).
2449 * @param pszSrc The source string. NULL is not OK.
2451 RTDECL(int) RTStrCat(char *pszDst
, size_t cbDst
, const char *pszSrc
);
2454 * String concatenation with overflow handling.
2456 * @retval VINF_SUCCESS on success.
2457 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2458 * buffer will contain as much of the string as it can hold, fully
2461 * @param pszDst The destination buffer.
2462 * @param cbDst The size of the destination buffer (in bytes).
2463 * @param pszSrc The source string. NULL is not OK.
2464 * @param cchSrcMax The maximum number of chars (not code points) to
2465 * copy from the source string, not counting the
2466 * terminator as usual.
2468 RTDECL(int) RTStrCatEx(char *pszDst
, size_t cbDst
, const char *pszSrc
, size_t cchSrcMax
);
2471 * String concatenation with overflow handling.
2473 * @retval VINF_SUCCESS on success.
2474 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2475 * buffer will contain as much of the string as it can hold, fully
2478 * @param ppszDst Pointer to the destination buffer pointer.
2479 * This will be advanced to the end of the copied
2480 * bytes (points at the terminator). This is also
2481 * updated on overflow.
2482 * @param pcbDst Pointer to the destination buffer size
2483 * variable. This will be updated in accord with
2484 * the buffer pointer.
2485 * @param pszSrc The source string. NULL is not OK.
2487 RTDECL(int) RTStrCatP(char **ppszDst
, size_t *pcbDst
, const char *pszSrc
);
2490 * String concatenation with overflow handling and buffer advancing.
2492 * @retval VINF_SUCCESS on success.
2493 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The
2494 * buffer will contain as much of the string as it can hold, fully
2497 * @param ppszDst Pointer to the destination buffer pointer.
2498 * This will be advanced to the end of the copied
2499 * bytes (points at the terminator). This is also
2500 * updated on overflow.
2501 * @param pcbDst Pointer to the destination buffer size
2502 * variable. This will be updated in accord with
2503 * the buffer pointer.
2504 * @param pszSrc The source string. NULL is not OK.
2505 * @param cchSrcMax The maximum number of chars (not code points) to
2506 * copy from the source string, not counting the
2507 * terminator as usual.
2509 RTDECL(int) RTStrCatPEx(char **ppszDst
, size_t *pcbDst
, const char *pszSrc
, size_t cchSrcMax
);
2512 * Performs a case sensitive string compare between two UTF-8 strings.
2514 * Encoding errors are ignored by the current implementation. So, the only
2515 * difference between this and the CRT strcmp function is the handling of
2518 * @returns < 0 if the first string less than the second string.
2519 * @returns 0 if the first string identical to the second string.
2520 * @returns > 0 if the first string greater than the second string.
2521 * @param psz1 First UTF-8 string. Null is allowed.
2522 * @param psz2 Second UTF-8 string. Null is allowed.
2524 RTDECL(int) RTStrCmp(const char *psz1
, const char *psz2
);
2527 * Performs a case sensitive string compare between two UTF-8 strings, given
2528 * a maximum string length.
2530 * Encoding errors are ignored by the current implementation. So, the only
2531 * difference between this and the CRT strncmp function is the handling of
2534 * @returns < 0 if the first string less than the second string.
2535 * @returns 0 if the first string identical to the second string.
2536 * @returns > 0 if the first string greater than the second string.
2537 * @param psz1 First UTF-8 string. Null is allowed.
2538 * @param psz2 Second UTF-8 string. Null is allowed.
2539 * @param cchMax The maximum string length
2541 RTDECL(int) RTStrNCmp(const char *psz1
, const char *psz2
, size_t cchMax
);
2544 * Performs a case insensitive string compare between two UTF-8 strings.
2546 * This is a simplified compare, as only the simplified lower/upper case folding
2547 * specified by the unicode specs are used. It does not consider character pairs
2548 * as they are used in some languages, just simple upper & lower case compares.
2550 * The result is the difference between the mismatching codepoints after they
2551 * both have been lower cased.
2553 * If the string encoding is invalid the function will assert (strict builds)
2554 * and use RTStrCmp for the remainder of the string.
2556 * @returns < 0 if the first string less than the second string.
2557 * @returns 0 if the first string identical to the second string.
2558 * @returns > 0 if the first string greater than the second string.
2559 * @param psz1 First UTF-8 string. Null is allowed.
2560 * @param psz2 Second UTF-8 string. Null is allowed.
2562 RTDECL(int) RTStrICmp(const char *psz1
, const char *psz2
);
2565 * Performs a case insensitive string compare between two UTF-8 strings, given a
2566 * maximum string length.
2568 * This is a simplified compare, as only the simplified lower/upper case folding
2569 * specified by the unicode specs are used. It does not consider character pairs
2570 * as they are used in some languages, just simple upper & lower case compares.
2572 * The result is the difference between the mismatching codepoints after they
2573 * both have been lower cased.
2575 * If the string encoding is invalid the function will assert (strict builds)
2576 * and use RTStrNCmp for the remainder of the string.
2578 * @returns < 0 if the first string less than the second string.
2579 * @returns 0 if the first string identical to the second string.
2580 * @returns > 0 if the first string greater than the second string.
2581 * @param psz1 First UTF-8 string. Null is allowed.
2582 * @param psz2 Second UTF-8 string. Null is allowed.
2583 * @param cchMax Maximum string length
2585 RTDECL(int) RTStrNICmp(const char *psz1
, const char *psz2
, size_t cchMax
);
2588 * Performs a case insensitive string compare between a UTF-8 string and a 7-bit
2591 * This is potentially faster than RTStrICmp and drags in less dependencies. It
2592 * is really handy for hardcoded inputs.
2594 * If the string encoding is invalid the function will assert (strict builds)
2595 * and use RTStrCmp for the remainder of the string.
2597 * @returns < 0 if the first string less than the second string.
2598 * @returns 0 if the first string identical to the second string.
2599 * @returns > 0 if the first string greater than the second string.
2600 * @param psz1 First UTF-8 string. Null is allowed.
2601 * @param psz2 Second string, 7-bit ASCII. Null is allowed.
2602 * @sa RTStrICmp, RTUtf16ICmpAscii
2604 RTDECL(int) RTStrICmpAscii(const char *psz1
, const char *psz2
);
2607 * Performs a case insensitive string compare between a UTF-8 string and a 7-bit
2608 * ASCII string, given a maximum string length.
2610 * This is potentially faster than RTStrNICmp and drags in less dependencies.
2611 * It is really handy for hardcoded inputs.
2613 * If the string encoding is invalid the function will assert (strict builds)
2614 * and use RTStrNCmp for the remainder of the string.
2616 * @returns < 0 if the first string less than the second string.
2617 * @returns 0 if the first string identical to the second string.
2618 * @returns > 0 if the first string greater than the second string.
2619 * @param psz1 First UTF-8 string. Null is allowed.
2620 * @param psz2 Second string, 7-bit ASCII. Null is allowed.
2621 * @param cchMax Maximum string length
2622 * @sa RTStrNICmp, RTUtf16NICmpAscii
2624 RTDECL(int) RTStrNICmpAscii(const char *psz1
, const char *psz2
, size_t cchMax
);
2627 * Checks whether @a pszString starts with @a pszStart.
2629 * @returns true / false.
2630 * @param pszString The string to check.
2631 * @param pszStart The start string to check for.
2633 RTDECL(bool) RTStrStartsWith(const char *pszString
, const char *pszStart
);
2636 * Checks whether @a pszString starts with @a pszStart, case insensitive.
2638 * @returns true / false.
2639 * @param pszString The string to check.
2640 * @param pszStart The start string to check for.
2642 RTDECL(bool) RTStrIStartsWith(const char *pszString
, const char *pszStart
);
2645 * Splits a string buffer with a given separator into separate strings.
2646 * If no separators are found, no strings are returned. Consequtive separators will be skipped.
2648 * @returns iprt status code.
2649 * @param pcszStrings String buffer to split.
2650 * @param cbStrings Size (in bytes) of string buffer to split, including terminator.
2651 * @param pcszSeparator Separator to use / find for splitting strings.
2652 * @param ppapszStrings Where to return the allocated string array on success. Needs to be free'd by the caller.
2653 * @param pcStrings Where to return the number of split strings in \a ppapszStrings.
2655 RTDECL(int) RTStrSplit(const char *pcszStrings
, size_t cbStrings
,
2656 const char *pcszSeparator
, char ***ppapszStrings
, size_t *pcStrings
);
2659 * Locates a case sensitive substring.
2661 * If any of the two strings are NULL, then NULL is returned. If the needle is
2662 * an empty string, then the haystack is returned (i.e. matches anything).
2664 * @returns Pointer to the first occurrence of the substring if found, NULL if
2667 * @param pszHaystack The string to search.
2668 * @param pszNeedle The substring to search for.
2670 * @remarks The difference between this and strstr is the handling of NULL
2673 RTDECL(char *) RTStrStr(const char *pszHaystack
, const char *pszNeedle
);
2676 * Locates a case insensitive substring.
2678 * If any of the two strings are NULL, then NULL is returned. If the needle is
2679 * an empty string, then the haystack is returned (i.e. matches anything).
2681 * @returns Pointer to the first occurrence of the substring if found, NULL if
2684 * @param pszHaystack The string to search.
2685 * @param pszNeedle The substring to search for.
2688 RTDECL(char *) RTStrIStr(const char *pszHaystack
, const char *pszNeedle
);
2691 * Converts the string to lower case.
2693 * @returns Pointer to the converted string.
2694 * @param psz The string to convert.
2696 RTDECL(char *) RTStrToLower(char *psz
);
2699 * Converts the string to upper case.
2701 * @returns Pointer to the converted string.
2702 * @param psz The string to convert.
2704 RTDECL(char *) RTStrToUpper(char *psz
);
2707 * Checks if the string is case foldable, i.e. whether it would change if
2708 * subject to RTStrToLower or RTStrToUpper.
2710 * @returns true / false
2711 * @param psz The string in question.
2713 RTDECL(bool) RTStrIsCaseFoldable(const char *psz
);
2716 * Checks if the string is upper cased (no lower case chars in it).
2718 * @returns true / false
2719 * @param psz The string in question.
2721 RTDECL(bool) RTStrIsUpperCased(const char *psz
);
2724 * Checks if the string is lower cased (no upper case chars in it).
2726 * @returns true / false
2727 * @param psz The string in question.
2729 RTDECL(bool) RTStrIsLowerCased(const char *psz
);
2732 * Find the length of a zero-terminated byte string, given
2733 * a max string length.
2735 * See also RTStrNLenEx.
2737 * @returns The string length or cbMax. The returned length does not include
2738 * the zero terminator if it was found.
2740 * @param pszString The string.
2741 * @param cchMax The max string length.
2743 RTDECL(size_t) RTStrNLen(const char *pszString
, size_t cchMax
);
2746 * Find the length of a zero-terminated byte string, given
2747 * a max string length.
2749 * See also RTStrNLen.
2751 * @returns IPRT status code.
2752 * @retval VINF_SUCCESS if the string has a length less than cchMax.
2753 * @retval VERR_BUFFER_OVERFLOW if the end of the string wasn't found
2754 * before cchMax was reached.
2756 * @param pszString The string.
2757 * @param cchMax The max string length.
2758 * @param pcch Where to store the string length excluding the
2759 * terminator. This is set to cchMax if the terminator
2762 RTDECL(int) RTStrNLenEx(const char *pszString
, size_t cchMax
, size_t *pcch
);
2764 /** The maximum size argument of a memchr call. */
2765 #define RTSTR_MEMCHR_MAX ((~(size_t)0 >> 1) - 15)
2768 * Find the zero terminator in a string with a limited length.
2770 * @returns Pointer to the zero terminator.
2771 * @returns NULL if the zero terminator was not found.
2773 * @param pszString The string.
2774 * @param cchMax The max string length. RTSTR_MAX is fine.
2776 RTDECL(char *) RTStrEnd(char const *pszString
, size_t cchMax
);
2779 * Finds the offset at which a simple character first occurs in a string.
2781 * @returns The offset of the first occurence or the terminator offset.
2782 * @param pszHaystack The string to search.
2783 * @param chNeedle The character to search for.
2785 DECLINLINE(size_t) RTStrOffCharOrTerm(const char *pszHaystack
, char chNeedle
)
2787 const char *psz
= pszHaystack
;
2789 while ( (ch
= *psz
) != chNeedle
2792 return (size_t)(psz
- pszHaystack
);
2796 * Matches a simple string pattern.
2798 * @returns true if the string matches the pattern, otherwise false.
2800 * @param pszPattern The pattern. Special chars are '*' and '?', where the
2801 * asterisk matches zero or more characters and question
2802 * mark matches exactly one character.
2803 * @param pszString The string to match against the pattern.
2805 RTDECL(bool) RTStrSimplePatternMatch(const char *pszPattern
, const char *pszString
);
2808 * Matches a simple string pattern, neither which needs to be zero terminated.
2810 * This is identical to RTStrSimplePatternMatch except that you can optionally
2811 * specify the length of both the pattern and the string. The function will
2812 * stop when it hits a string terminator or either of the lengths.
2814 * @returns true if the string matches the pattern, otherwise false.
2816 * @param pszPattern The pattern. Special chars are '*' and '?', where the
2817 * asterisk matches zero or more characters and question
2818 * mark matches exactly one character.
2819 * @param cchPattern The pattern length. Pass RTSTR_MAX if you don't know the
2820 * length and wish to stop at the string terminator.
2821 * @param pszString The string to match against the pattern.
2822 * @param cchString The string length. Pass RTSTR_MAX if you don't know the
2823 * length and wish to match up to the string terminator.
2825 RTDECL(bool) RTStrSimplePatternNMatch(const char *pszPattern
, size_t cchPattern
,
2826 const char *pszString
, size_t cchString
);
2829 * Matches multiple patterns against a string.
2831 * The patterns are separated by the pipe character (|).
2833 * @returns true if the string matches the pattern, otherwise false.
2835 * @param pszPatterns The patterns.
2836 * @param cchPatterns The lengths of the patterns to use. Pass RTSTR_MAX to
2837 * stop at the terminator.
2838 * @param pszString The string to match against the pattern.
2839 * @param cchString The string length. Pass RTSTR_MAX stop stop at the
2841 * @param poffPattern Offset into the patterns string of the patttern that
2842 * matched. If no match, this will be set to RTSTR_MAX.
2843 * This is optional, NULL is fine.
2845 RTDECL(bool) RTStrSimplePatternMultiMatch(const char *pszPatterns
, size_t cchPatterns
,
2846 const char *pszString
, size_t cchString
,
2847 size_t *poffPattern
);
2850 * Compares two version strings RTStrICmp fashion.
2852 * The version string is split up into sections at punctuation, spaces,
2853 * underscores, dashes and plus signs. The sections are then split up into
2854 * numeric and string sub-sections. Finally, the sub-sections are compared
2855 * in a numeric or case insesntivie fashion depending on what they are.
2857 * The following strings are considered to be equal: "1.0.0", "1.00.0", "1.0",
2858 * "1". These aren't: "1.0.0r993", "1.0", "1.0r993", "1.0_Beta3", "1.1"
2860 * @returns < 0 if the first string less than the second string.
2861 * @returns 0 if the first string identical to the second string.
2862 * @returns > 0 if the first string greater than the second string.
2864 * @param pszVer1 First version string to compare.
2865 * @param pszVer2 Second version string to compare first version with.
2867 RTDECL(int) RTStrVersionCompare(const char *pszVer1
, const char *pszVer2
);
2870 /** @defgroup rt_str_conv String To/From Number Conversions
2874 * Converts a string representation of a number to a 64-bit unsigned number.
2876 * @returns iprt status code.
2877 * Warnings are used to indicate conversion problems.
2878 * @retval VWRN_NUMBER_TOO_BIG
2879 * @retval VWRN_NEGATIVE_UNSIGNED
2880 * @retval VWRN_TRAILING_CHARS
2881 * @retval VWRN_TRAILING_SPACES
2882 * @retval VINF_SUCCESS
2883 * @retval VERR_NO_DIGITS
2885 * @param pszValue Pointer to the string value.
2886 * @param ppszNext Where to store the pointer to the first char
2887 * following the number. (Optional)
2888 * @param uBaseAndMaxLen The low byte is the base of the representation, the
2889 * upper 24 bits are the max length to parse. If the base
2890 * is zero the function will look for known prefixes before
2891 * defaulting to 10. A max length of zero means no length
2893 * @param pu64 Where to store the converted number. (optional)
2895 RTDECL(int) RTStrToUInt64Ex(const char *pszValue
, char **ppszNext
, unsigned uBaseAndMaxLen
, uint64_t *pu64
);
2898 * Converts a string representation of a number to a 64-bit unsigned number,
2899 * making sure the full string is converted.
2901 * @returns iprt status code.
2902 * Warnings are used to indicate conversion problems.
2903 * @retval VWRN_NUMBER_TOO_BIG
2904 * @retval VWRN_NEGATIVE_UNSIGNED
2905 * @retval VINF_SUCCESS
2906 * @retval VERR_NO_DIGITS
2907 * @retval VERR_TRAILING_SPACES
2908 * @retval VERR_TRAILING_CHARS
2910 * @param pszValue Pointer to the string value.
2911 * @param uBaseAndMaxLen The low byte is the base of the representation, the
2912 * upper 24 bits are the max length to parse. If the base
2913 * is zero the function will look for known prefixes before
2914 * defaulting to 10. A max length of zero means no length
2916 * @param pu64 Where to store the converted number. (optional)
2918 RTDECL(int) RTStrToUInt64Full(const char *pszValue
, unsigned uBaseAndMaxLen
, uint64_t *pu64
);
2921 * Converts a string representation of a number to a 64-bit unsigned number.
2922 * The base is guessed.
2924 * @returns 64-bit unsigned number on success.
2925 * @returns 0 on failure.
2926 * @param pszValue Pointer to the string value.
2928 RTDECL(uint64_t) RTStrToUInt64(const char *pszValue
);
2931 * Converts a string representation of a number to a 32-bit unsigned number.
2933 * @returns iprt status code.
2934 * Warnings are used to indicate conversion problems.
2935 * @retval VWRN_NUMBER_TOO_BIG
2936 * @retval VWRN_NEGATIVE_UNSIGNED
2937 * @retval VWRN_TRAILING_CHARS
2938 * @retval VWRN_TRAILING_SPACES
2939 * @retval VINF_SUCCESS
2940 * @retval VERR_NO_DIGITS
2942 * @param pszValue Pointer to the string value.
2943 * @param ppszNext Where to store the pointer to the first char
2944 * following the number. (Optional)
2945 * @param uBaseAndMaxLen The low byte is the base of the representation, the
2946 * upper 24 bits are the max length to parse. If the base
2947 * is zero the function will look for known prefixes before
2948 * defaulting to 10. A max length of zero means no length
2950 * @param pu32 Where to store the converted number. (optional)
2952 RTDECL(int) RTStrToUInt32Ex(const char *pszValue
, char **ppszNext
, unsigned uBaseAndMaxLen
, uint32_t *pu32
);
2955 * Converts a string representation of a number to a 32-bit unsigned number,
2956 * making sure the full string is converted.
2958 * @returns iprt status code.
2959 * Warnings are used to indicate conversion problems.
2960 * @retval VWRN_NUMBER_TOO_BIG
2961 * @retval VWRN_NEGATIVE_UNSIGNED
2962 * @retval VINF_SUCCESS
2963 * @retval VERR_NO_DIGITS
2964 * @retval VERR_TRAILING_SPACES
2965 * @retval VERR_TRAILING_CHARS
2967 * @param pszValue Pointer to the string value.
2968 * @param uBaseAndMaxLen The low byte is the base of the representation, the
2969 * upper 24 bits are the max length to parse. If the base
2970 * is zero the function will look for known prefixes before
2971 * defaulting to 10. A max length of zero means no length
2973 * @param pu32 Where to store the converted number. (optional)
2975 RTDECL(int) RTStrToUInt32Full(const char *pszValue
, unsigned uBaseAndMaxLen
, uint32_t *pu32
);
2978 * Converts a string representation of a number to a 32-bit unsigned number.
2979 * The base is guessed.
2981 * @returns 32-bit unsigned number on success.
2982 * @returns 0 on failure.
2983 * @param pszValue Pointer to the string value.
2985 RTDECL(uint32_t) RTStrToUInt32(const char *pszValue
);
2988 * Converts a string representation of a number to a 16-bit unsigned number.
2990 * @returns iprt status code.
2991 * Warnings are used to indicate conversion problems.
2992 * @retval VWRN_NUMBER_TOO_BIG
2993 * @retval VWRN_NEGATIVE_UNSIGNED
2994 * @retval VWRN_TRAILING_CHARS
2995 * @retval VWRN_TRAILING_SPACES
2996 * @retval VINF_SUCCESS
2997 * @retval VERR_NO_DIGITS
2999 * @param pszValue Pointer to the string value.
3000 * @param ppszNext Where to store the pointer to the first char
3001 * following the number. (Optional)
3002 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3003 * upper 24 bits are the max length to parse. If the base
3004 * is zero the function will look for known prefixes before
3005 * defaulting to 10. A max length of zero means no length
3007 * @param pu16 Where to store the converted number. (optional)
3009 RTDECL(int) RTStrToUInt16Ex(const char *pszValue
, char **ppszNext
, unsigned uBaseAndMaxLen
, uint16_t *pu16
);
3012 * Converts a string representation of a number to a 16-bit unsigned number,
3013 * making sure the full string is converted.
3015 * @returns iprt status code.
3016 * Warnings are used to indicate conversion problems.
3017 * @retval VWRN_NUMBER_TOO_BIG
3018 * @retval VWRN_NEGATIVE_UNSIGNED
3019 * @retval VINF_SUCCESS
3020 * @retval VERR_NO_DIGITS
3021 * @retval VERR_TRAILING_SPACES
3022 * @retval VERR_TRAILING_CHARS
3024 * @param pszValue Pointer to the string value.
3025 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3026 * upper 24 bits are the max length to parse. If the base
3027 * is zero the function will look for known prefixes before
3028 * defaulting to 10. A max length of zero means no length
3030 * @param pu16 Where to store the converted number. (optional)
3032 RTDECL(int) RTStrToUInt16Full(const char *pszValue
, unsigned uBaseAndMaxLen
, uint16_t *pu16
);
3035 * Converts a string representation of a number to a 16-bit unsigned number.
3036 * The base is guessed.
3038 * @returns 16-bit unsigned number on success.
3039 * @returns 0 on failure.
3040 * @param pszValue Pointer to the string value.
3042 RTDECL(uint16_t) RTStrToUInt16(const char *pszValue
);
3045 * Converts a string representation of a number to a 8-bit unsigned number.
3047 * @returns iprt status code.
3048 * Warnings are used to indicate conversion problems.
3049 * @retval VWRN_NUMBER_TOO_BIG
3050 * @retval VWRN_NEGATIVE_UNSIGNED
3051 * @retval VWRN_TRAILING_CHARS
3052 * @retval VWRN_TRAILING_SPACES
3053 * @retval VINF_SUCCESS
3054 * @retval VERR_NO_DIGITS
3056 * @param pszValue Pointer to the string value.
3057 * @param ppszNext Where to store the pointer to the first char
3058 * following the number. (Optional)
3059 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3060 * upper 24 bits are the max length to parse. If the base
3061 * is zero the function will look for known prefixes before
3062 * defaulting to 10. A max length of zero means no length
3064 * @param pu8 Where to store the converted number. (optional)
3066 RTDECL(int) RTStrToUInt8Ex(const char *pszValue
, char **ppszNext
, unsigned uBaseAndMaxLen
, uint8_t *pu8
);
3069 * Converts a string representation of a number to a 8-bit unsigned number,
3070 * making sure the full string is converted.
3072 * @returns iprt status code.
3073 * Warnings are used to indicate conversion problems.
3074 * @retval VWRN_NUMBER_TOO_BIG
3075 * @retval VWRN_NEGATIVE_UNSIGNED
3076 * @retval VINF_SUCCESS
3077 * @retval VERR_NO_DIGITS
3078 * @retval VERR_TRAILING_SPACES
3079 * @retval VERR_TRAILING_CHARS
3081 * @param pszValue Pointer to the string value.
3082 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3083 * upper 24 bits are the max length to parse. If the base
3084 * is zero the function will look for known prefixes before
3085 * defaulting to 10. A max length of zero means no length
3087 * @param pu8 Where to store the converted number. (optional)
3089 RTDECL(int) RTStrToUInt8Full(const char *pszValue
, unsigned uBaseAndMaxLen
, uint8_t *pu8
);
3092 * Converts a string representation of a number to a 8-bit unsigned number.
3093 * The base is guessed.
3095 * @returns 8-bit unsigned number on success.
3096 * @returns 0 on failure.
3097 * @param pszValue Pointer to the string value.
3099 RTDECL(uint8_t) RTStrToUInt8(const char *pszValue
);
3102 * Converts a string representation of a number to a 64-bit signed number.
3104 * @returns iprt status code.
3105 * Warnings are used to indicate conversion problems.
3106 * @retval VWRN_NUMBER_TOO_BIG
3107 * @retval VWRN_TRAILING_CHARS
3108 * @retval VWRN_TRAILING_SPACES
3109 * @retval VINF_SUCCESS
3110 * @retval VERR_NO_DIGITS
3112 * @param pszValue Pointer to the string value.
3113 * @param ppszNext Where to store the pointer to the first char
3114 * following the number. (Optional)
3115 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3116 * upper 24 bits are the max length to parse. If the base
3117 * is zero the function will look for known prefixes before
3118 * defaulting to 10. A max length of zero means no length
3120 * @param pi64 Where to store the converted number. (optional)
3122 RTDECL(int) RTStrToInt64Ex(const char *pszValue
, char **ppszNext
, unsigned uBaseAndMaxLen
, int64_t *pi64
);
3125 * Converts a string representation of a number to a 64-bit signed number,
3126 * making sure the full string is converted.
3128 * @returns iprt status code.
3129 * Warnings are used to indicate conversion problems.
3130 * @retval VWRN_NUMBER_TOO_BIG
3131 * @retval VINF_SUCCESS
3132 * @retval VERR_TRAILING_CHARS
3133 * @retval VERR_TRAILING_SPACES
3134 * @retval VERR_NO_DIGITS
3136 * @param pszValue Pointer to the string value.
3137 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3138 * upper 24 bits are the max length to parse. If the base
3139 * is zero the function will look for known prefixes before
3140 * defaulting to 10. A max length of zero means no length
3142 * @param pi64 Where to store the converted number. (optional)
3144 RTDECL(int) RTStrToInt64Full(const char *pszValue
, unsigned uBaseAndMaxLen
, int64_t *pi64
);
3147 * Converts a string representation of a number to a 64-bit signed number.
3148 * The base is guessed.
3150 * @returns 64-bit signed number on success.
3151 * @returns 0 on failure.
3152 * @param pszValue Pointer to the string value.
3154 RTDECL(int64_t) RTStrToInt64(const char *pszValue
);
3157 * Converts a string representation of a number to a 32-bit signed number.
3159 * @returns iprt status code.
3160 * Warnings are used to indicate conversion problems.
3161 * @retval VWRN_NUMBER_TOO_BIG
3162 * @retval VWRN_TRAILING_CHARS
3163 * @retval VWRN_TRAILING_SPACES
3164 * @retval VINF_SUCCESS
3165 * @retval VERR_NO_DIGITS
3167 * @param pszValue Pointer to the string value.
3168 * @param ppszNext Where to store the pointer to the first char
3169 * following the number. (Optional)
3170 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3171 * upper 24 bits are the max length to parse. If the base
3172 * is zero the function will look for known prefixes before
3173 * defaulting to 10. A max length of zero means no length
3175 * @param pi32 Where to store the converted number. (optional)
3177 RTDECL(int) RTStrToInt32Ex(const char *pszValue
, char **ppszNext
, unsigned uBaseAndMaxLen
, int32_t *pi32
);
3180 * Converts a string representation of a number to a 32-bit signed number,
3181 * making sure the full string is converted.
3183 * @returns iprt status code.
3184 * Warnings are used to indicate conversion problems.
3185 * @retval VWRN_NUMBER_TOO_BIG
3186 * @retval VINF_SUCCESS
3187 * @retval VERR_TRAILING_CHARS
3188 * @retval VERR_TRAILING_SPACES
3189 * @retval VERR_NO_DIGITS
3191 * @param pszValue Pointer to the string value.
3192 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3193 * upper 24 bits are the max length to parse. If the base
3194 * is zero the function will look for known prefixes before
3195 * defaulting to 10. A max length of zero means no length
3197 * @param pi32 Where to store the converted number. (optional)
3199 RTDECL(int) RTStrToInt32Full(const char *pszValue
, unsigned uBaseAndMaxLen
, int32_t *pi32
);
3202 * Converts a string representation of a number to a 32-bit signed number.
3203 * The base is guessed.
3205 * @returns 32-bit signed number on success.
3206 * @returns 0 on failure.
3207 * @param pszValue Pointer to the string value.
3209 RTDECL(int32_t) RTStrToInt32(const char *pszValue
);
3212 * Converts a string representation of a number to a 16-bit signed number.
3214 * @returns iprt status code.
3215 * Warnings are used to indicate conversion problems.
3216 * @retval VWRN_NUMBER_TOO_BIG
3217 * @retval VWRN_TRAILING_CHARS
3218 * @retval VWRN_TRAILING_SPACES
3219 * @retval VINF_SUCCESS
3220 * @retval VERR_NO_DIGITS
3222 * @param pszValue Pointer to the string value.
3223 * @param ppszNext Where to store the pointer to the first char
3224 * following the number. (Optional)
3225 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3226 * upper 24 bits are the max length to parse. If the base
3227 * is zero the function will look for known prefixes before
3228 * defaulting to 10. A max length of zero means no length
3230 * @param pi16 Where to store the converted number. (optional)
3232 RTDECL(int) RTStrToInt16Ex(const char *pszValue
, char **ppszNext
, unsigned uBaseAndMaxLen
, int16_t *pi16
);
3235 * Converts a string representation of a number to a 16-bit signed number,
3236 * making sure the full string is converted.
3238 * @returns iprt status code.
3239 * Warnings are used to indicate conversion problems.
3240 * @retval VWRN_NUMBER_TOO_BIG
3241 * @retval VINF_SUCCESS
3242 * @retval VERR_TRAILING_CHARS
3243 * @retval VERR_TRAILING_SPACES
3244 * @retval VERR_NO_DIGITS
3246 * @param pszValue Pointer to the string value.
3247 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3248 * upper 24 bits are the max length to parse. If the base
3249 * is zero the function will look for known prefixes before
3250 * defaulting to 10. A max length of zero means no length
3252 * @param pi16 Where to store the converted number. (optional)
3254 RTDECL(int) RTStrToInt16Full(const char *pszValue
, unsigned uBaseAndMaxLen
, int16_t *pi16
);
3257 * Converts a string representation of a number to a 16-bit signed number.
3258 * The base is guessed.
3260 * @returns 16-bit signed number on success.
3261 * @returns 0 on failure.
3262 * @param pszValue Pointer to the string value.
3264 RTDECL(int16_t) RTStrToInt16(const char *pszValue
);
3267 * Converts a string representation of a number to a 8-bit signed number.
3269 * @returns iprt status code.
3270 * Warnings are used to indicate conversion problems.
3271 * @retval VWRN_NUMBER_TOO_BIG
3272 * @retval VWRN_TRAILING_CHARS
3273 * @retval VWRN_TRAILING_SPACES
3274 * @retval VINF_SUCCESS
3275 * @retval VERR_NO_DIGITS
3277 * @param pszValue Pointer to the string value.
3278 * @param ppszNext Where to store the pointer to the first char
3279 * following the number. (Optional)
3280 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3281 * upper 24 bits are the max length to parse. If the base
3282 * is zero the function will look for known prefixes before
3283 * defaulting to 10. A max length of zero means no length
3285 * @param pi8 Where to store the converted number. (optional)
3287 RTDECL(int) RTStrToInt8Ex(const char *pszValue
, char **ppszNext
, unsigned uBaseAndMaxLen
, int8_t *pi8
);
3290 * Converts a string representation of a number to a 8-bit signed number,
3291 * making sure the full string is converted.
3293 * @returns iprt status code.
3294 * Warnings are used to indicate conversion problems.
3295 * @retval VWRN_NUMBER_TOO_BIG
3296 * @retval VINF_SUCCESS
3297 * @retval VERR_TRAILING_CHARS
3298 * @retval VERR_TRAILING_SPACES
3299 * @retval VERR_NO_DIGITS
3301 * @param pszValue Pointer to the string value.
3302 * @param uBaseAndMaxLen The low byte is the base of the representation, the
3303 * upper 24 bits are the max length to parse. If the base
3304 * is zero the function will look for known prefixes before
3305 * defaulting to 10. A max length of zero means no length
3307 * @param pi8 Where to store the converted number. (optional)
3309 RTDECL(int) RTStrToInt8Full(const char *pszValue
, unsigned uBaseAndMaxLen
, int8_t *pi8
);
3312 * Converts a string representation of a number to a 8-bit signed number.
3313 * The base is guessed.
3315 * @returns 8-bit signed number on success.
3316 * @returns 0 on failure.
3317 * @param pszValue Pointer to the string value.
3319 RTDECL(int8_t) RTStrToInt8(const char *pszValue
);
3323 * Converts a string to long double floating point, extended edition.
3325 * Please note that long double can be double precision, extended precision, or
3326 * quad precision floating point depending on the platform and architecture. See
3327 * RT_COMPILER_WITH_128BIT_LONG_DOUBLE and RT_COMPILER_WITH_80BIT_LONG_DOUBLE.
3329 * @returns IPRT status code.
3330 * @retval VERR_NO_DIGITS if no valid digits found.
3331 * @retval VWRN_FLOAT_UNDERFLOW on underflow with denormal/subnormal return
3333 * @retval VERR_FLOAT_UNDERFLOW on underflow, value set to +/- zero.
3334 * @retval VERR_FLOAT_OVERFLOW on overflow, value set to +/- infinity.
3335 * @retval VWRN_TRAILING_CHARS
3336 * @retval VWRN_TRAILING_SPACES
3338 * @param pszValue The string to parse.
3339 * @param ppszNext Where to store the pointer to the first char following
3340 * the number. Optional.
3341 * @param cchMax Max number of character to parse. Zero means unlimited.
3342 * @param plrd Where to return the number. Optional.
3344 * @note This code isn't entirely perfect yet. It could exhibit rounding
3345 * differences compared to strtold & the compiler, and extreme value
3346 * may overflow/underflow prematurely depending on the build config.
3348 RTDECL(int) RTStrToLongDoubleEx(const char *pszValue
, char **ppszNext
, size_t cchMax
, long double *plrd
);
3351 * Converts a string to double precision floating point, extended edition.
3353 * @returns IPRT status code.
3354 * @retval VERR_NO_DIGITS if no valid digits found.
3355 * @retval VWRN_FLOAT_UNDERFLOW on underflow with denormal/subnormal return
3357 * @retval VERR_FLOAT_UNDERFLOW on underflow, value set to +/- zero.
3358 * @retval VERR_FLOAT_OVERFLOW on overflow, value set to +/- infinity.
3359 * @retval VWRN_TRAILING_CHARS
3360 * @retval VWRN_TRAILING_SPACES
3362 * @param pszValue The string to parse.
3363 * @param ppszNext Where to store the pointer to the first char following
3364 * the number. Optional.
3365 * @param cchMax Max number of character to parse. Zero means unlimited.
3366 * @param prd Where to return the number. Optional.
3368 * @note This code isn't entirely perfect yet. It could exhibit rounding
3369 * differences compared to strtold & the compiler, and extreme value
3370 * may overflow/underflow prematurely depending on the build config.
3372 RTDECL(int) RTStrToDoubleEx(const char *pszValue
, char **ppszNext
, size_t cchMax
, double *prd
);
3375 * Converts a string to single precision floating point, extended edition.
3377 * @returns IPRT status code.
3378 * @retval VERR_NO_DIGITS if no valid digits found.
3379 * @retval VWRN_FLOAT_UNDERFLOW on underflow with denormal/subnormal return
3381 * @retval VERR_FLOAT_UNDERFLOW on underflow, value set to +/- zero.
3382 * @retval VERR_FLOAT_OVERFLOW on overflow, value set to +/- infinity.
3383 * @retval VWRN_TRAILING_CHARS
3384 * @retval VWRN_TRAILING_SPACES
3386 * @param pszValue The string to parse.
3387 * @param ppszNext Where to store the pointer to the first char following
3388 * the number. Optional.
3389 * @param cchMax Max number of character to parse. Zero means unlimited.
3390 * @param pr Where to return the number. Optional.
3392 * @note This code isn't entirely perfect yet. It could exhibit rounding
3393 * differences compared to strtold & the compiler, and extreme value
3394 * may overflow/underflow prematurely depending on the build config.
3396 RTDECL(int) RTStrToFloatEx(const char *pszValue
, char **ppszNext
, size_t cchMax
, float *pr
);
3400 * Gets a long double NaN.
3402 * @returns NaN value.
3403 * @param pszTag Optional NaN tag for modifying the NaN value. We
3404 * recognizes a string of hex digits for inserting into the
3405 * fraction part. This may be followed 'quiet' or
3406 * 'signaling', ignoring case and requiring at only the
3407 * first character. The two components may be separated by
3408 * zero or more '_' characters. Any other stuff in the tag
3411 * If the tag is empty or we cannot grok any of it, we'll
3412 * return a default quiet NaN.
3413 * @param fPositive Whether the NaN value should be positive or negative
3414 * (for what that's worth).
3416 RTDECL(long double) RTStrNanLongDouble(const char *pszTag
, bool fPositive
);
3419 * Gets a double NaN.
3421 * @returns NaN value.
3422 * @param pszTag Optional NaN tag for modifying the NaN value. We
3423 * recognizes a string of hex digits for inserting into the
3424 * fraction part. This may be followed 'quiet' or
3425 * 'signaling', ignoring case and requiring at only the
3426 * first character. The two components may be separated by
3427 * zero or more '_' characters. Any other stuff in the tag
3430 * If the tag is empty or we cannot grok any of it, we'll
3431 * return a default quiet NaN.
3432 * @param fPositive Whether the NaN value should be positive or negative
3433 * (for what that's worth).
3435 RTDECL(double) RTStrNanDouble(const char *pszTag
, bool fPositive
);
3440 * @returns NaN value.
3441 * @param pszTag Optional NaN tag for modifying the NaN value. We
3442 * recognizes a string of hex digits for inserting into the
3443 * fraction part. This may be followed 'quiet' or
3444 * 'signaling', ignoring case and requiring at only the
3445 * first character. The two components may be separated by
3446 * zero or more '_' characters. Any other stuff in the tag
3449 * If the tag is empty or we cannot grok any of it, we'll
3450 * return a default quiet NaN.
3451 * @param fPositive Whether the NaN value should be positive or negative
3452 * (for what that's worth).
3454 RTDECL(float) RTStrNanFloat(const char *pszTag
, bool fPositive
);
3457 * Formats a buffer stream as hex bytes.
3459 * The default is no separating spaces or line breaks or anything.
3461 * @returns IPRT status code.
3462 * @retval VERR_INVALID_POINTER if any of the pointers are wrong.
3463 * @retval VERR_BUFFER_OVERFLOW if the buffer is insufficent to hold the bytes.
3465 * @param pszBuf Output string buffer.
3466 * @param cbBuf The size of the output buffer.
3467 * @param pv Pointer to the bytes to stringify.
3468 * @param cb The number of bytes to stringify.
3469 * @param fFlags Combination of RTSTRPRINTHEXBYTES_F_XXX values.
3470 * @sa RTUtf16PrintHexBytes.
3472 RTDECL(int) RTStrPrintHexBytes(char *pszBuf
, size_t cbBuf
, void const *pv
, size_t cb
, uint32_t fFlags
);
3473 /** @name RTSTRPRINTHEXBYTES_F_XXX - flags for RTStrPrintHexBytes and RTUtf16PritnHexBytes.
3475 /** Upper case hex digits, the default is lower case. */
3476 #define RTSTRPRINTHEXBYTES_F_UPPER RT_BIT(0)
3477 /** Add a space between each group. */
3478 #define RTSTRPRINTHEXBYTES_F_SEP_SPACE RT_BIT(1)
3479 /** Add a colon between each group. */
3480 #define RTSTRPRINTHEXBYTES_F_SEP_COLON RT_BIT(2)
3484 * Converts a string of hex bytes back into binary data.
3486 * @returns IPRT status code.
3487 * @retval VERR_INVALID_POINTER if any of the pointers are wrong.
3488 * @retval VERR_BUFFER_OVERFLOW if the string contains too many hex bytes.
3489 * @retval VERR_BUFFER_UNDERFLOW if there aren't enough hex bytes to fill up
3490 * the output buffer.
3491 * @retval VERR_UNEVEN_INPUT if the input contains a half byte.
3492 * @retval VERR_NO_DIGITS
3493 * @retval VWRN_TRAILING_CHARS
3494 * @retval VWRN_TRAILING_SPACES
3496 * @param pszHex The string containing the hex bytes.
3497 * @param pv Output buffer.
3498 * @param cb The size of the output buffer.
3499 * @param fFlags RTSTRCONVERTHEXBYTES_F_XXX.
3501 RTDECL(int) RTStrConvertHexBytes(char const *pszHex
, void *pv
, size_t cb
, uint32_t fFlags
);
3503 /** @name RTSTRCONVERTHEXBYTES_F_XXX - Flags for RTStrConvertHexBytes() and RTStrConvertHexBytesEx().
3505 /** Accept colon as a byte separator. */
3506 #define RTSTRCONVERTHEXBYTES_F_SEP_COLON RT_BIT(0)
3510 * Converts a string of hex bytes back into binary data, extended version.
3512 * @returns IPRT status code.
3513 * @retval VERR_INVALID_POINTER if any of the pointers are wrong.
3514 * @retval VERR_BUFFER_OVERFLOW if the string contains too many hex bytes.
3515 * @retval VERR_BUFFER_UNDERFLOW if there aren't enough hex bytes to fill up
3516 * the output buffer and *pcbReturned is NULL.
3517 * @retval VINF_BUFFER_UNDERFLOW if there aren't enough hex bytes to fill up
3518 * the output buffer and *pcbReturned is not NULL, *pcbReturned holds
3519 * the actual number of bytes.
3520 * @retval VERR_UNEVEN_INPUT if the input contains a half byte.
3521 * @retval VERR_NO_DIGITS
3522 * @retval VWRN_TRAILING_CHARS
3523 * @retval VWRN_TRAILING_SPACES
3525 * @param pszHex The string containing the hex bytes.
3526 * @param pv Output buffer.
3527 * @param cb The size of the output buffer.
3528 * @param fFlags RTSTRCONVERTHEXBYTES_F_XXX.
3529 * @param ppszNext Set to point at where we stopped decoding hex bytes.
3531 * @param pcbReturned Where to return the number of bytes found. Optional.
3533 RTDECL(int) RTStrConvertHexBytesEx(char const *pszHex
, void *pv
, size_t cb
, uint32_t fFlags
,
3534 const char **ppszNext
, size_t *pcbReturned
);
3539 /** @defgroup rt_str_space Unique String Space
3543 /** Pointer to a string name space container node core. */
3544 typedef struct RTSTRSPACECORE
*PRTSTRSPACECORE
;
3545 /** Pointer to a pointer to a string name space container node core. */
3546 typedef PRTSTRSPACECORE
*PPRTSTRSPACECORE
;
3549 * String name space container node core.
3551 typedef struct RTSTRSPACECORE
3553 /** Pointer to the left leaf node. Don't touch. */
3554 PRTSTRSPACECORE pLeft
;
3555 /** Pointer to the left right node. Don't touch. */
3556 PRTSTRSPACECORE pRight
;
3557 /** Pointer to the list of string with the same hash key value. Don't touch. */
3558 PRTSTRSPACECORE pList
;
3559 /** Hash key. Don't touch. */
3561 /** Height of this tree: max(heigth(left), heigth(right)) + 1. Don't touch */
3562 unsigned char uchHeight
;
3563 /** The string length. Read only! */
3565 /** Pointer to the string. Read only! */
3566 const char *pszString
;
3569 /** String space. (Initialize with NULL.) */
3570 typedef PRTSTRSPACECORE RTSTRSPACE
;
3571 /** Pointer to a string space. */
3572 typedef PPRTSTRSPACECORE PRTSTRSPACE
;
3576 * Inserts a string into a unique string space.
3578 * @returns true on success.
3579 * @returns false if the string collided with an existing string.
3580 * @param pStrSpace The space to insert it into.
3581 * @param pStr The string node.
3583 RTDECL(bool) RTStrSpaceInsert(PRTSTRSPACE pStrSpace
, PRTSTRSPACECORE pStr
);
3586 * Removes a string from a unique string space.
3588 * @returns Pointer to the removed string node.
3589 * @returns NULL if the string was not found in the string space.
3590 * @param pStrSpace The space to remove it from.
3591 * @param pszString The string to remove.
3593 RTDECL(PRTSTRSPACECORE
) RTStrSpaceRemove(PRTSTRSPACE pStrSpace
, const char *pszString
);
3596 * Gets a string from a unique string space.
3598 * @returns Pointer to the string node.
3599 * @returns NULL if the string was not found in the string space.
3600 * @param pStrSpace The space to get it from.
3601 * @param pszString The string to get.
3603 RTDECL(PRTSTRSPACECORE
) RTStrSpaceGet(PRTSTRSPACE pStrSpace
, const char *pszString
);
3606 * Gets a string from a unique string space.
3608 * @returns Pointer to the string node.
3609 * @returns NULL if the string was not found in the string space.
3610 * @param pStrSpace The space to get it from.
3611 * @param pszString The string to get.
3612 * @param cchMax The max string length to evaluate. Passing
3613 * RTSTR_MAX is ok and makes it behave just like
3616 RTDECL(PRTSTRSPACECORE
) RTStrSpaceGetN(PRTSTRSPACE pStrSpace
, const char *pszString
, size_t cchMax
);
3619 * Callback function for RTStrSpaceEnumerate() and RTStrSpaceDestroy().
3621 * @returns 0 on continue.
3622 * @returns Non-zero to aborts the operation.
3623 * @param pStr The string node
3624 * @param pvUser The user specified argument.
3626 typedef DECLCALLBACKTYPE(int, FNRTSTRSPACECALLBACK
,(PRTSTRSPACECORE pStr
, void *pvUser
));
3627 /** Pointer to callback function for RTStrSpaceEnumerate() and RTStrSpaceDestroy(). */
3628 typedef FNRTSTRSPACECALLBACK
*PFNRTSTRSPACECALLBACK
;
3631 * Destroys the string space.
3633 * The caller supplies a callback which will be called for each of the string
3634 * nodes in for freeing their memory and other resources.
3636 * @returns 0 or what ever non-zero return value pfnCallback returned
3637 * when aborting the destruction.
3638 * @param pStrSpace The space to destroy.
3639 * @param pfnCallback The callback.
3640 * @param pvUser The user argument.
3642 RTDECL(int) RTStrSpaceDestroy(PRTSTRSPACE pStrSpace
, PFNRTSTRSPACECALLBACK pfnCallback
, void *pvUser
);
3645 * Enumerates the string space.
3646 * The caller supplies a callback which will be called for each of
3649 * @returns 0 or what ever non-zero return value pfnCallback returned
3650 * when aborting the destruction.
3651 * @param pStrSpace The space to enumerate.
3652 * @param pfnCallback The callback.
3653 * @param pvUser The user argument.
3655 RTDECL(int) RTStrSpaceEnumerate(PRTSTRSPACE pStrSpace
, PFNRTSTRSPACECALLBACK pfnCallback
, void *pvUser
);
3660 /** @defgroup rt_str_hash Sting hashing
3664 * Hashes the given string using algorithm \#1.
3666 * @returns String hash.
3667 * @param pszString The string to hash.
3669 RTDECL(uint32_t) RTStrHash1(const char *pszString
);
3672 * Hashes the given string using algorithm \#1.
3674 * @returns String hash.
3675 * @param pszString The string to hash.
3676 * @param cchString The max length to hash. Hashing will stop if the
3677 * terminator character is encountered first. Passing
3678 * RTSTR_MAX is fine.
3680 RTDECL(uint32_t) RTStrHash1N(const char *pszString
, size_t cchString
);
3683 * Hashes the given strings as if they were concatenated using algorithm \#1.
3685 * @returns String hash.
3686 * @param cPairs The number of string / length pairs in the
3688 * @param ... List of string (const char *) and length
3689 * (size_t) pairs. Passing RTSTR_MAX as the size is
3692 RTDECL(uint32_t) RTStrHash1ExN(size_t cPairs
, ...);
3695 * Hashes the given strings as if they were concatenated using algorithm \#1.
3697 * @returns String hash.
3698 * @param cPairs The number of string / length pairs in the @a va.
3699 * @param va List of string (const char *) and length
3700 * (size_t) pairs. Passing RTSTR_MAX as the size is
3703 RTDECL(uint32_t) RTStrHash1ExNV(size_t cPairs
, va_list va
);
3708 /** @defgroup rt_str_mem Raw memory operations.
3710 * @note Following the memchr/memcpy/memcmp/memset tradition and putting these
3711 * in the string.h header rather than in the mem.h one.
3716 * Searches @a pvHaystack for a 16-bit sized and aligned @a uNeedle.
3718 * @returns Pointer to the first hit if found, NULL if not found.
3719 * @param pvHaystack The memory to search.
3720 * @param uNeedle The 16-bit value to find.
3721 * @param cbHaystack Size of the memory to search.
3722 * @sa memchr, RTStrMemFind32, RTStrMemFind64
3724 RTDECL(uint16_t *) RTStrMemFind16(const void *pvHaystack
, uint16_t uNeedle
, size_t cbHaystack
);
3727 * Searches @a pvHaystack for a 32-bit sized and aligned @a uNeedle.
3729 * @returns Pointer to the first hit if found, NULL if not found.
3730 * @param pvHaystack The memory to search.
3731 * @param uNeedle The 32-bit value to find.
3732 * @param cbHaystack Size of the memory to search.
3733 * @sa memchr, RTStrMemFind16, RTStrMemFind64
3735 RTDECL(uint32_t *) RTStrMemFind32(const void *pvHaystack
, uint32_t uNeedle
, size_t cbHaystack
);
3738 * Searches @a pvHaystack for a 64-bit sized and aligned @a uNeedle.
3740 * @returns Pointer to the first hit if found, NULL if not found.
3741 * @param pvHaystack The memory to search.
3742 * @param uNeedle The 64-bit value to find.
3743 * @param cbHaystack Size of the memory to search.
3744 * @sa memchr, RTStrMemFind16, RTStrMemFind32
3746 RTDECL(uint64_t *) RTStrMemFind64(const void *pvHaystack
, uint64_t uNeedle
, size_t cbHaystack
);
3755 #endif /* !IPRT_INCLUDED_string_h */