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