37
37
#if defined(RT_OS_LINUX) && defined(__KERNEL__)
38
38
# include <linux/string.h>
39
39
#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
40
# include <sys/libkern.h>
41
* Kludge for the FreeBSD kernel:
42
* Some of the string.h stuff clashes with sys/libkern.h, so just wrap
43
* it up while including string.h to keep things quiet. It's nothing
44
* important that's clashing, after all.
42
* No memmove on versions < 7.2
43
* Defining a macro using bcopy here
46
# define strdup strdup_string_h
45
# define memmove(dst, src, size) bcopy(src, dst, size)
49
46
#elif defined(RT_OS_SOLARIS) && defined(_KERNEL)
51
48
* Same case as with FreeBSD kernel:
265
263
* will be allocated to hold the translated string.
266
264
* If a buffer was requested it must be freed using RTUtf16Free().
267
265
* @param cCps The number of code points in the unicode string. This includes the terminator.
268
* @param pcCps Where to store the length of the translated string. (Optional)
269
* This field will be updated even on failure, however the value is only
270
* specified for the following two error codes. On VERR_BUFFER_OVERFLOW
271
* and VERR_NO_STR_MEMORY it contains the required buffer space.
266
* @param pcCps Where to store the length of the translated string,
267
* excluding the terminator. (Optional)
269
* This may be set under some error conditions,
270
* however, only for VERR_BUFFER_OVERFLOW and
271
* VERR_NO_STR_MEMORY will it contain a valid string
272
* length that can be used to resize the buffer.
273
274
RTDECL(int) RTStrToUniEx(const char *pszString, size_t cchString, PRTUNICP *ppaCps, size_t cCps, size_t *pcCps);
324
325
* will be allocated to hold the translated string.
325
326
* If a buffer was requested it must be freed using RTUtf16Free().
326
327
* @param cwc The buffer size in RTUTF16s. This includes the terminator.
327
* @param pcwc Where to store the length of the translated string. (Optional)
328
* This field will be updated even on failure, however the value is only
329
* specified for the following two error codes. On VERR_BUFFER_OVERFLOW
330
* and VERR_NO_STR_MEMORY it contains the required buffer space.
328
* @param pcwc Where to store the length of the translated string,
329
* excluding the terminator. (Optional)
331
* This may be set under some error conditions,
332
* however, only for VERR_BUFFER_OVERFLOW and
333
* VERR_NO_STR_MEMORY will it contain a valid string
334
* length that can be used to resize the buffer.
332
336
RTDECL(int) RTStrToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc);
793
797
RTDECL(int) RTStrAPrintf(char **ppszBuffer, const char *pszFormat, ...);
800
* Allocating string printf, version 2.
802
* @returns Formatted string. Use RTStrFree() to free it. NULL when out of
804
* @param pszFormat The format string.
805
* @param args The format argument.
807
RTDECL(char *) RTStrAPrintf2V(const char *pszFormat, va_list args);
810
* Allocating string printf, version2.
812
* @returns Formatted string. Use RTStrFree() to free it. NULL when out of
814
* @param pszFormat The format string.
815
* @param ... The format argument.
817
RTDECL(char *) RTStrAPrintf2(const char *pszFormat, ...);
797
820
* Strips blankspaces from both ends of the string.
1028
1051
const char *pszString, size_t cchString,
1029
1052
size_t *poffPattern);
1055
* Compares two version strings RTStrICmp fashion.
1057
* The version string is split up into sections at punctuation, spaces,
1058
* underscores, dashes and pluss signs. The sections are then split up into
1059
* numeric and string sub-sections. Finally, the sub-sections are compared
1060
* in a numeric or case insesntivie fashion depending on what they are.
1062
* The following strings are considered to be equal: "1.0.0", "1.00.0", "1.0",
1063
* "1". These aren't: "1.0.0r993", "1.0", "1.0r993", "1.0_Beta3", "1.1"
1065
* @returns < 0 if the first string less than the second string.
1066
* @returns 0 if the first string identical to the second string.
1067
* @returns > 0 if the first string greater than the second string.
1069
* @param pszVer1 First version string to compare.
1070
* @param pszVer2 Second version string to compare first version with.
1072
RTDECL(int) RTStrVersionCompare(const char *pszVer1, const char *pszVer2);
1032
1075
/** @defgroup rt_str_conv String To/From Number Conversions
1033
1076
* @ingroup grp_rt_str
1426
1469
RTDECL(int8_t) RTStrToInt8(const char *pszValue);
1472
* Formats a buffer stream as hex bytes.
1474
* The default is no separating spaces or line breaks or anything.
1476
* @returns IPRT status code.
1477
* @retval VERR_INVALID_POINTER if any of the pointers are wrong.
1478
* @retval VERR_BUFFER_OVERFLOW if the buffer is insufficent to hold the bytes.
1480
* @param pszBuf Output string buffer.
1481
* @param cchBuf The size of the output buffer.
1482
* @param pv Pointer to the bytes to stringify.
1483
* @param cb The number of bytes to stringify.
1484
* @param fFlags Must be zero, reserved for future use.
1486
RTDECL(int) RTStrPrintHexBytes(char *pszBuf, size_t cchBuf, void const *pv, size_t cb, uint32_t fFlags);
1489
* Converts a string of hex bytes back into binary data.
1491
* @returns IPRT status code.
1492
* @retval VERR_INVALID_POINTER if any of the pointers are wrong.
1493
* @retval VERR_BUFFER_OVERFLOW if the string contains too many hex bytes.
1494
* @retval VERR_BUFFER_UNDERFLOW if there aren't enough hex bytes to fill up
1495
* the output buffer.
1496
* @retval VERR_UNEVEN_INPUT if the input contains a half byte.
1497
* @retval VERR_NO_DIGITS
1498
* @retval VWRN_TRAILING_CHARS
1499
* @retval VWRN_TRAILING_SPACES
1501
* @param pszHex The string containing the hex bytes.
1502
* @param pv Output buffer.
1503
* @param cb The size of the output buffer.
1504
* @param fFlags Must be zero, reserved for future use.
1506
RTDECL(int) RTStrConvertHexBytes(char const *pszHex, void *pv, size_t cb, uint32_t fFlags);
1680
1760
* will be allocated to hold the translated string.
1681
1761
* If a buffer was requested it must be freed using RTUtf16Free().
1682
1762
* @param cch The buffer size in chars (the type). This includes the terminator.
1683
* @param pcch Where to store the length of the translated string. (Optional)
1684
* This field will be updated even on failure, however the value is only
1685
* specified for the following two error codes. On VERR_BUFFER_OVERFLOW
1686
* and VERR_NO_STR_MEMORY it contains the required buffer space.
1763
* @param pcch Where to store the length of the translated string,
1764
* excluding the terminator. (Optional)
1766
* This may be set under some error conditions,
1767
* however, only for VERR_BUFFER_OVERFLOW and
1768
* VERR_NO_STR_MEMORY will it contain a valid string
1769
* length that can be used to resize the buffer.
1688
1771
RTDECL(int) RTUtf16ToUtf8Ex(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch);
1716
1799
RTDECL(int) RTUtf16CalcUtf8LenEx(PCRTUTF16 pwsz, size_t cwc, size_t *pcch);
1802
* Translate a UTF-16 string into a Latin-1 (ISO-8859-1) allocating the result
1805
* @returns iprt status code.
1806
* @param pwszString UTF-16 string to convert.
1807
* @param ppszString Receives pointer of allocated Latin1 string on
1808
* success, and is always set to NULL on failure.
1809
* The returned pointer must be freed using RTStrFree().
1811
RTDECL(int) RTUtf16ToLatin1(PCRTUTF16 pwszString, char **ppszString);
1814
* Translates UTF-16 to Latin-1 (ISO-8859-1) using buffer provided by the caller
1815
* or a fittingly sized buffer allocated by the function.
1817
* @returns iprt status code.
1818
* @param pwszString The UTF-16 string to convert.
1819
* @param cwcString The number of RTUTF16 items to translate from
1820
* pwszString. The translation will stop when reaching
1821
* cwcString or the terminator ('\\0'). Use RTSTR_MAX
1822
* to translate the entire string.
1823
* @param ppsz Pointer to the pointer to the Latin-1 string. The
1824
* buffer can optionally be preallocated by the caller.
1826
* If cch is zero, *ppsz is undefined.
1828
* If cch is non-zero and *ppsz is not NULL, then this
1829
* will be used as the output buffer.
1830
* VERR_BUFFER_OVERFLOW will be returned if this is
1833
* If cch is zero or *ppsz is NULL, then a buffer of
1834
* sufficent size is allocated. cch can be used to
1835
* specify a minimum size of this buffer. Use
1836
* RTUtf16Free() to free the result.
1838
* @param cch The buffer size in chars (the type). This includes
1840
* @param pcch Where to store the length of the translated string,
1841
* excluding the terminator. (Optional)
1843
* This may be set under some error conditions,
1844
* however, only for VERR_BUFFER_OVERFLOW and
1845
* VERR_NO_STR_MEMORY will it contain a valid string
1846
* length that can be used to resize the buffer.
1848
RTDECL(int) RTUtf16ToLatin1Ex(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch);
1851
* Calculates the length of the UTF-16 string in Latin-1 (ISO-8859-1) chars.
1853
* This function will validate the string, and incorrectly encoded UTF-16
1854
* strings will be rejected. The primary purpose of this function is to
1855
* help allocate buffers for RTUtf16ToLatin1() of the correct size. For most
1856
* other purposes RTUtf16ToLatin1Ex() should be used.
1858
* @returns Number of char (bytes).
1859
* @returns 0 if the string was incorrectly encoded.
1860
* @param pwsz The UTF-16 string.
1862
RTDECL(size_t) RTUtf16CalcLatin1Len(PCRTUTF16 pwsz);
1865
* Calculates the length of the UTF-16 string in Latin-1 (ISO-8859-1) chars.
1867
* This function will validate the string, and incorrectly encoded UTF-16
1868
* strings will be rejected.
1870
* @returns iprt status code.
1871
* @param pwsz The string.
1872
* @param cwc The max string length. Use RTSTR_MAX to process the
1874
* @param pcch Where to store the string length (in bytes). Optional.
1875
* This is undefined on failure.
1877
RTDECL(int) RTUtf16CalcLatin1LenEx(PCRTUTF16 pwsz, size_t cwc, size_t *pcch);
1719
1880
* Get the unicode code point at the given string position.
1721
1882
* @returns unicode code point.
2058
/** @defgroup rt_str_latin1 Latin-1 (ISO-8859-1) String Manipulation
2059
* @ingroup grp_rt_str
2064
* Calculates the length of the Latin-1 (ISO-8859-1) string in RTUTF16 items.
2066
* @returns Number of RTUTF16 items.
2067
* @param psz The Latin-1 string.
2069
RTDECL(size_t) RTLatin1CalcUtf16Len(const char *psz);
2072
* Calculates the length of the Latin-1 (ISO-8859-1) string in RTUTF16 items.
2074
* @returns iprt status code.
2075
* @param psz The Latin-1 string.
2076
* @param cch The max string length. Use RTSTR_MAX to process the
2078
* @param pcwc Where to store the string length. Optional.
2079
* This is undefined on failure.
2081
RTDECL(int) RTLatin1CalcUtf16LenEx(const char *psz, size_t cch, size_t *pcwc);
2084
* Translate a Latin-1 (ISO-8859-1) string into a UTF-16 allocating the result
2087
* @returns iprt status code.
2088
* @param pszString The Latin-1 string to convert.
2089
* @param ppwszString Receives pointer to the allocated UTF-16 string. The
2090
* returned string must be freed using RTUtf16Free().
2092
RTDECL(int) RTLatin1ToUtf16(const char *pszString, PRTUTF16 *ppwszString);
2095
* Translates pszString from Latin-1 (ISO-8859-1) to UTF-16, allocating the
2096
* result buffer if requested.
2098
* @returns iprt status code.
2099
* @param pszString The Latin-1 string to convert.
2100
* @param cchString The maximum size in chars (the type) to convert.
2101
* The conversion stops when it reaches cchString or
2102
* the string terminator ('\\0').
2103
* Use RTSTR_MAX to translate the entire string.
2104
* @param ppwsz If cwc is non-zero, this must either be pointing
2105
* to pointer to a buffer of the specified size, or
2106
* pointer to a NULL pointer.
2107
* If *ppwsz is NULL or cwc is zero a buffer of at
2108
* least cwc items will be allocated to hold the
2109
* translated string. If a buffer was requested it
2110
* must be freed using RTUtf16Free().
2111
* @param cwc The buffer size in RTUTF16s. This includes the
2113
* @param pcwc Where to store the length of the translated string,
2114
* excluding the terminator. (Optional)
2116
* This may be set under some error conditions,
2117
* however, only for VERR_BUFFER_OVERFLOW and
2118
* VERR_NO_STR_MEMORY will it contain a valid string
2119
* length that can be used to resize the buffer.
2121
RTDECL(int) RTLatin1ToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc);