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