VirtualBox

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

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

IPRT/string.h: Document status code formatting in IN_RT_STATIC builds and adjusted the formatter to make the best of it.

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

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