common_util 1.1.0
|
String format functions. this file defines a series of string-formatted functions. More...
Go to the source code of this file.
Functions | |
std::string | cutl::fmt_uint (uint64_t val, uint8_t width=0, char fill='0') |
Format uint64 value to a string with a given width and fill character. | |
std::string | cutl::fmt_double (double val, int precision=2) |
Format double value to a string with a given precision. | |
std::string | cutl::fmt_filesize (uint64_t size, bool simplify=true, int precision=1) |
Format a file size to a human-readable string with a given precision. | |
std::string | cutl::fmt_timeduration_s (uint64_t seconds) |
Format a time duration to a human-readable string. | |
std::string | cutl::fmt_timeduration_ms (uint64_t microseconds) |
Format a time duration to a human-readable string. | |
std::string | cutl::fmt_timeduration_us (uint64_t nanoseconds) |
Format a time duration to a human-readable string. | |
std::string | cutl::fmt_timestamp (uint64_t second, bool local, const std::string &fmt) |
Format a timestamp to a human-readable string with a given format. | |
std::string | cutl::fmt_timestamp_s (uint64_t second, bool local=true) |
Format a timestamp to a human-readable string. | |
std::string | cutl::fmt_timestamp_ms (uint64_t ms, bool local=true) |
Format a timestamp to a human-readable string. | |
std::string | cutl::fmt_timestamp_us (uint64_t us, bool local=true) |
Format a timestamp to a human-readable string. | |
std::string | cutl::to_hex (const uint8_t *data, size_t len, bool upper=true, char separator=' ') |
Format data to a hex string. | |
std::string | cutl::to_hex (uint8_t value, bool upper=true, const std::string &prefix="") |
Format a uint8_t value to a hex string. | |
std::string | cutl::to_hex (uint16_t value, bool upper=true, const std::string &prefix="") |
Format a uint16_t value to a hex string. | |
std::string | cutl::to_hex (uint32_t value, bool upper=true, const std::string &prefix="") |
Format a uint32_t value to a hex string. | |
std::string | cutl::to_hex (uint64_t value, bool upper=true, const std::string &prefix="") |
Format a uint64_t value to a hex string. | |
std::string | cutl::to_bin (uint8_t value, char separator=',') |
Format uint8_t value to a binary string. | |
std::string | cutl::to_bin (uint16_t value, char separator=' ') |
Format uint16_t value to a binary string. | |
std::string | cutl::to_bin (uint32_t value, char separator=' ') |
Format uint32_t value to a binary string. | |
std::string | cutl::to_bin (uint64_t value, char separator=' ') |
Format uint64_t value to a binary string. | |
String format functions. this file defines a series of string-formatted functions.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations.
std::string cutl::fmt_double | ( | double | val, |
int | precision = 2 |
||
) |
Format double value to a string with a given precision.
val | the value to be formatted. |
precision | the precision of the formatted string, default is 2. |
std::string cutl::fmt_filesize | ( | uint64_t | size, |
bool | simplify = true , |
||
int | precision = 1 |
||
) |
Format a file size to a human-readable string with a given precision.
size | the size to be formatted. |
simplify | whether to use a simplify unit. |
precision | the precision of the formatted string, default is 1. |
std::string cutl::fmt_timeduration_ms | ( | uint64_t | microseconds | ) |
Format a time duration to a human-readable string.
microseconds | the duration in microseconds. |
std::string cutl::fmt_timeduration_s | ( | uint64_t | seconds | ) |
Format a time duration to a human-readable string.
seconds | the duration in seconds. |
std::string cutl::fmt_timeduration_us | ( | uint64_t | nanoseconds | ) |
Format a time duration to a human-readable string.
nanoseconds | the duration in nanoseconds. |
std::string cutl::fmt_timestamp | ( | uint64_t | second, |
bool | local, | ||
const std::string & | fmt | ||
) |
Format a timestamp to a human-readable string with a given format.
second | the timestamp in seconds. |
local | whether to use local time or UTC time, default is local time. If local is true, the function will format the timestamp to local time, otherwise, it will format the timestamp to UTC time. |
fmt | the format of the formatted string. useage like std::put_time, see https://en.cppreference.com/w/cpp/io/manip/put_time |
std::string cutl::fmt_timestamp_ms | ( | uint64_t | ms, |
bool | local = true |
||
) |
Format a timestamp to a human-readable string.
ms | the timestamp in milliseconds. |
local | whether to use local time or UTC time, default is local time. If local is true, the function will format the timestamp to local time, otherwise, it will format the timestamp to UTC time. |
std::string cutl::fmt_timestamp_s | ( | uint64_t | second, |
bool | local = true |
||
) |
Format a timestamp to a human-readable string.
second | the timestamp in seconds. |
local | whether to use local time or UTC time, default is local time. If local is true, the function will format the timestamp to local time, otherwise, it will format the timestamp to UTC time. |
std::string cutl::fmt_timestamp_us | ( | uint64_t | us, |
bool | local = true |
||
) |
Format a timestamp to a human-readable string.
us | the timestamp in microseconds. |
local | whether to use local time or UTC time, default is local time. If local is true, the function will format the timestamp to local time, otherwise, it will format the timestamp to UTC time. |
std::string cutl::fmt_uint | ( | uint64_t | val, |
uint8_t | width = 0 , |
||
char | fill = '0' |
||
) |
Format uint64 value to a string with a given width and fill character.
val | the value to be formatted. |
width | the width of the formatted string. |
fill | the fill character of the formatted string, default is '0'. |
std::string cutl::to_bin | ( | uint16_t | value, |
char | separator = ' ' |
||
) |
Format uint16_t value to a binary string.
value | the value to be formatted. |
separator | the separator between each pair of binary characters, default is space. |
std::string cutl::to_bin | ( | uint32_t | value, |
char | separator = ' ' |
||
) |
Format uint32_t value to a binary string.
value | the value to be formatted. |
separator | the separator between each pair of binary characters, default is space. |
std::string cutl::to_bin | ( | uint64_t | value, |
char | separator = ' ' |
||
) |
Format uint64_t value to a binary string.
value | the value to be formatted. |
separator | the separator between each pair of binary characters, default is space. |
std::string cutl::to_bin | ( | uint8_t | value, |
char | separator = ',' |
||
) |
Format uint8_t value to a binary string.
value | the value to be formatted. |
separator | the separator between each pair of binary characters, default is comma. |
std::string cutl::to_hex | ( | const uint8_t * | data, |
size_t | len, | ||
bool | upper = true , |
||
char | separator = ' ' |
||
) |
Format data to a hex string.
data | the data to be formatted. |
len | the length of the data. |
upper | whether to use upper case or lower case for hex characters, default is upper case. |
separator | the separator between each pair of hex characters, default is space. |
std::string cutl::to_hex | ( | uint16_t | value, |
bool | upper = true , |
||
const std::string & | prefix = "" |
||
) |
Format a uint16_t value to a hex string.
value | the value to be formatted. |
upper | whether to use upper case or lower case for hex characters, default is upper case. |
prefix | the prefix of the formatted string, default is empty. |
std::string cutl::to_hex | ( | uint32_t | value, |
bool | upper = true , |
||
const std::string & | prefix = "" |
||
) |
Format a uint32_t value to a hex string.
value | the value to be formatted. |
upper | whether to use upper case or lower case for hex characters, default is upper case. |
prefix | the prefix of the formatted string, default is empty. |
std::string cutl::to_hex | ( | uint64_t | value, |
bool | upper = true , |
||
const std::string & | prefix = "" |
||
) |
Format a uint64_t value to a hex string.
value | the value to be formatted. |
upper | whether to use upper case or lower case for hex characters, default is upper case. |
prefix | the prefix of the formatted string, default is empty. |
std::string cutl::to_hex | ( | uint8_t | value, |
bool | upper = true , |
||
const std::string & | prefix = "" |
||
) |
Format a uint8_t value to a hex string.
value | the value to be formatted. |
upper | whether to use upper case or lower case for hex characters, default is upper case. |
prefix | the prefix of the formatted string, default is empty. |