Formatting functions
Used to output the given values in newly formatted text using functions.
More...
Formatting functions
Used to output the given values in newly formatted text using functions.
◆ BinaryStringToString()
static std::string kodi::tools::StringUtils::BinaryStringToString |
( |
const std::string & | in | ) |
|
|
inlinestatic |
Convert the string of binary chars to the actual string.
Convert the string representation of binary chars to the actual string. For example \1\2\3
is converted to a string with binary char \1
, \2
and \3
- Parameters
-
- Returns
- Converted string
◆ Format() [1/2]
static std::string kodi::tools::StringUtils::Format |
( |
const char * | fmt, |
|
|
| ... ) |
|
inlinestatic |
Returns the C++ string pointed by given format. If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.
After the format parameter, the function expects at least as many additional arguments as specified by format.
- Parameters
-
[in] | fmt | The format of the text to process for output. C string that contains the text to be written to the stream. It can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatted as requested.
specifier | Output | Example |
d or i | Signed decimal integer | 392 |
u | Unsigned decimal integer | 7235 |
o | Unsigned octal | 610 |
x | Unsigned hexadecimal integer | 7fa |
X | Unsigned hexadecimal integer (uppercase) | 7FA |
f | Decimal floating point, lowercase | 392.65 |
F | Decimal floating point, uppercase | 392.65 |
e | Scientific notation (mantissa/exponent), lowercase | 3.9265e+2 |
E | Scientific notation (mantissa/exponent), uppercase | 3.9265E+2 |
g | Use the shortest representation: e or f | 392.65 |
G | Use the shortest representation: E or F | 392.65 |
a | Hexadecimal floating point, lowercase | -0xc.90fep-2 |
A | Hexadecimal floating point, uppercase | -0XC.90FEP-2 |
c | Character | a |
s | String of characters | sample |
p | Pointer address | b8000000 |
% | A % followed by another % character will write a single % to the stream. | % |
The length sub-specifier modifies the length of the data type. This is a chart showing the types used to interpret the corresponding arguments with and without length specifier (if a different type is used, the proper type promotion or conversion is performed, if allowed):
length | d i | u o x X | f F e E g G a A | c | s | p | n |
(none) | int | unsigned int | double | int | char* | void* | int* |
hh | signed char | unsigned char | | | | | signed char* |
h | short int | unsigned short int | | | | | short int* |
l | long int | unsigned long int | | wint_t | wchar_t* | | long int* |
ll | long long int | unsigned long long int | | | | | long long int* |
j | intmax_t | uintmax_t | | | | | intmax_t* |
z | size_t | size_t | | | | | size_t* |
t | ptrdiff_t | ptrdiff_t | | | | | ptrdiff_t* |
L | | | long double | | | | |
Note: that the c specifier takes an int (or wint_t) as argument, but performs the proper conversion to a char value (or a wchar_t) before formatting it for output. |
[in] | ... | (additional arguments)
Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string (or a pointer to a storage location, for n).
There should be at least as many of these arguments as the number of values specified in the format specifiers. Additional arguments are ignored by the function. |
- Returns
- Formatted string
Example:
◆ Format() [2/2]
static std::wstring kodi::tools::StringUtils::Format |
( |
const wchar_t * | fmt, |
|
|
| ... ) |
|
inlinestatic |
Returns the C++ wide string pointed by given format.
- Parameters
-
[in] | fmt | The format of the text to process for output (see Format(const char* fmt, ...) for details). |
[in] | ... | (additional arguments)
Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string (or a pointer to a storage location, for n).
There should be at least as many of these arguments as the number of values specified in the format specifiers. Additional arguments are ignored by the function. |
- Returns
- Formatted string
◆ FormatFileSize()
static std::string kodi::tools::StringUtils::FormatFileSize |
( |
uint64_t | bytes | ) |
|
|
inlinestatic |
Returns bytes in a human readable format using the smallest unit that will fit bytes
in at most three digits. The number of decimals are adjusted with significance such that 'small' numbers will have more decimals than larger ones.
For example: 1024 bytes will be formatted as "1.00kB", 10240 bytes as "10.0kB" and 102400 bytes as "100kB". See TestStringUtils for more examples.
Supported file sizes:
Value | Short | Metric |
1 | B | byte |
1024¹ | kB | kilobyte |
1024² | MB | megabyte |
1024³ | GB | gigabyte |
1024 exp 4 | TB | terabyte |
1024 exp 5 | PB | petabyte |
1024 exp 6 | EB | exabyte |
1024 exp 7 | ZB | zettabyte |
1024 exp 8 | YB | yottabyte |
- Parameters
-
[in] | bytes | Bytes amount to return as human readable string |
- Returns
- Size as string
Example:
◆ FormatV() [1/2]
static std::string kodi::tools::StringUtils::FormatV |
( |
PRINTF_FORMAT_STRING const char * | fmt, |
|
|
va_list | args ) |
|
inlinestatic |
Returns the C++ string pointed by given format list.
- Parameters
-
[in] | fmt | The format of the text to process for output (see Format(const char* fmt, ...) for details). |
[in] | args | A value identifying a variable arguments list initialized with va_start . |
- Returns
- Formatted string
◆ FormatV() [2/2]
static std::wstring kodi::tools::StringUtils::FormatV |
( |
PRINTF_FORMAT_STRING const wchar_t * | fmt, |
|
|
va_list | args ) |
|
inlinestatic |
Returns the C++ wide string pointed by given format list.
- Parameters
-
[in] | fmt | The format of the text to process for output (see Format(const char* fmt, ...) for details). |
[in] | args | A value identifying a variable arguments list initialized with va_start . |
- Returns
- Formatted string
◆ ToHexadecimal()
static std::string kodi::tools::StringUtils::ToHexadecimal |
( |
const std::string & | in | ) |
|
|
inlinestatic |
Convert each character in the string to its hexadecimal representation and return the concatenated result.
Example: "abc\n" -> "6162630a"
- Parameters
-
- Returns
- Converted string
Example:
std::string a{"a\0b\n", 4};
std::string nul{"\0", 1};
std::string ff{"\xFF", 1};