|
VLink 2.0.0
A high-performance communication middleware
|
Stateless string, number, hash and formatting helper functions. More...
Functions | |
| VLINK_EXPORT int | to_int (const std::string &str, int dv=0) noexcept |
Converts a decimal string to int. | |
| VLINK_EXPORT int64_t | to_long (const std::string &str, int64_t dv=0, int offset=0) noexcept |
Converts a decimal string to int64_t with an optional byte offset. | |
| VLINK_EXPORT std::string | double_to_string (double value, int precision=2) noexcept |
Converts a double to a string with a specified number of decimal places. | |
| VLINK_EXPORT uint64_t | hash_combine (uint64_t a, uint64_t b) noexcept |
| Combines two 64-bit hash values into one using a mixing function. | |
| VLINK_EXPORT void | replace_string (std::string &str, const std::string &from, const std::string &to) noexcept |
Replaces all occurrences of from in str with to in-place. | |
| VLINK_EXPORT std::string | trim_string (const std::string &str) noexcept |
| Strips leading and trailing whitespace from a string. | |
| VLINK_EXPORT std::wstring | string_to_wstring (const std::string &input) noexcept |
Converts a UTF-8 std::string to a std::wstring. | |
| VLINK_EXPORT std::string | wstring_to_string (const std::wstring &input) noexcept |
Converts a std::wstring to a UTF-8 std::string. | |
| VLINK_EXPORT std::string | string_local_to_utf8 (const std::string &local_str) noexcept |
| Converts a locally-encoded string to UTF-8. | |
| VLINK_EXPORT std::string | string_utf8_to_local (const std::string &utf8_str) noexcept |
| Converts a UTF-8 string to the locally-encoded system string. | |
| VLINK_EXPORT std::string | path_to_string (const std::filesystem::path &path) noexcept |
Converts a std::filesystem::path to a UTF-8 std::string portably. | |
| VLINK_EXPORT std::vector< std::string > | get_split_string (const std::string &str, char f) noexcept |
| Splits a string by a delimiter character and returns the parts as a vector. | |
| VLINK_EXPORT std::vector< std::string_view > | get_split_string_view (std::string_view str, char f) noexcept |
Splits a string_view by a delimiter character returning non-owning views. | |
| VLINK_EXPORT std::pair< std::string, std::string > | get_pair_string (const std::string &str, char f) noexcept |
| Splits a string at the first occurrence of a delimiter and returns a pair. | |
| VLINK_EXPORT std::pair< std::string_view, std::string_view > | get_pair_string_view (std::string_view str, char f) noexcept |
Splits a string_view at the first occurrence of a delimiter returning non-owning views. | |
| VLINK_EXPORT uint32_t | get_hash_code (const std::string &str) noexcept |
| Computes a 32-bit FNV-1a-style hash code for a string. | |
| VLINK_EXPORT std::string | format_milliseconds (int64_t milliseconds, bool show_millis) noexcept |
| Formats a duration in milliseconds as a human-readable time string. | |
| VLINK_EXPORT std::string | format_date (int64_t nanoseconds_since_epoch) noexcept |
| Formats a nanosecond-precision epoch timestamp as a date-time string. | |
| VLINK_EXPORT std::string | format_time_diff (int32_t milliseconds) noexcept |
| Formats a time difference in milliseconds as a human-readable string. | |
| VLINK_EXPORT std::string | format_hex_number (int64_t hex_number) noexcept |
Formats a signed 64-bit integer as a "0x..." hexadecimal string. | |
| VLINK_EXPORT std::string | format_hex_number (uint64_t hex_number) noexcept |
Formats an unsigned 64-bit integer as a "0x..." hexadecimal string. | |
| VLINK_EXPORT std::string | format_file_size (size_t size) noexcept |
| Formats a byte count as a human-readable size string. | |
| VLINK_EXPORT std::string | format_rate_size (size_t size) noexcept |
| Formats a byte-per-second rate as a human-readable string. | |
| VLINK_EXPORT int64_t | convert_date_to_timestamp (const std::string &date) noexcept |
| Converts a date string to a Unix millisecond timestamp. | |
| template<uint8_t SizeT> | |
| bool | has_startwith (const std::string &str, const char(&target)[SizeT]) noexcept |
Compile-time check whether str starts with the literal target. | |
| template<uint8_t SizeT> | |
| bool | has_endwith (const std::string &str, const char(&target)[SizeT]) noexcept |
Compile-time check whether str ends with the literal target. | |
| constexpr bool | has_startwith (std::string_view str, std::string_view target) noexcept |
Checks whether a string_view starts with a given prefix (constexpr-friendly). | |
| constexpr bool | has_endwith (std::string_view str, std::string_view target) noexcept |
Checks whether a string_view ends with a given suffix (constexpr-friendly). | |
| constexpr bool | contains_substring (std::string_view sv, std::string_view needle) noexcept |
Checks whether a string_view contains a given substring. | |
Stateless string, number, hash and formatting helper functions.
|
inlinenodiscardconstexprnoexcept |
Checks whether a string_view contains a given substring.
| sv | String to search. |
| needle | Substring to find. |
true if sv contains needle. Returns true if needle is empty.
|
nodiscardnoexcept |
Converts a date string to a Unix millisecond timestamp.
Accepts ISO 8601 style dates such as "2026-03-18" or "2026-03-18 12:00:00".
| date | Date string to parse. |
|
nodiscardnoexcept |
Converts a double to a string with a specified number of decimal places.
| value | Value to convert. |
| precision | Number of decimal places. Default: 2. |
|
nodiscardnoexcept |
Formats a nanosecond-precision epoch timestamp as a date-time string.
Output format: "YYYY-MM-DD HH:MM:SS.mmm".
| nanoseconds_since_epoch | Unix timestamp in nanoseconds. |
|
nodiscardnoexcept |
Formats a byte count as a human-readable size string.
Selects the appropriate unit (B, KB, MB, GB, TB) and formats to 2 decimal places. Example: 1536 -> "1.50KB".
| size | Size in bytes. |
|
nodiscardnoexcept |
Formats a signed 64-bit integer as a "0x..." hexadecimal string.
| hex_number | Value to format. |
"0x".
|
nodiscardnoexcept |
Formats an unsigned 64-bit integer as a "0x..." hexadecimal string.
| hex_number | Value to format. |
"0x".
|
nodiscardnoexcept |
Formats a duration in milliseconds as a human-readable time string.
Example: 125000 ms -> "00:02:05" or "00:02:05:000" when show_millis is true.
| milliseconds | Duration in milliseconds. |
| show_millis | If true, append the sub-second milliseconds component. |
|
nodiscardnoexcept |
Formats a byte-per-second rate as a human-readable string.
Selects the appropriate unit (B/s, KB/s, MB/s, GB/s) and formats to 2 decimal places. Example: 1048576 -> "1.00MB/s".
| size | Rate in bytes per second. |
|
nodiscardnoexcept |
Formats a time difference in milliseconds as a human-readable string.
Produces strings such as "01:23:45:000" or "00:00:00:250".
| milliseconds | Time difference in milliseconds. |
|
nodiscardnoexcept |
Computes a 32-bit FNV-1a-style hash code for a string.
| str | Input string. |
|
nodiscardnoexcept |
Splits a string at the first occurrence of a delimiter and returns a pair.
Returns {"", ""} if the delimiter is not found.
| str | Input string. |
| f | Delimiter character. |
|
nodiscardnoexcept |
Splits a string_view at the first occurrence of a delimiter returning non-owning views.
Each element is a string_view into the original str. The caller must ensure str outlives all returned views. Returns {"", ""} if str is empty. If the delimiter is not found, the entire string is returned as first with an empty second.
| str | Input string view. |
| f | Delimiter character. |
string_view over the left and right substrings around the first delimiter.
|
nodiscardnoexcept |
Splits a string by a delimiter character and returns the parts as a vector.
| str | Input string. |
| f | Delimiter character. |
|
nodiscardnoexcept |
Splits a string_view by a delimiter character returning non-owning views.
Each element is a string_view into the original str. The caller must ensure str outlives all returned views.
| str | Input string view. |
| f | Delimiter character. |
string_view over the substrings.
|
inlinenodiscardnoexcept |
Compile-time check whether str ends with the literal target.
| SizeT | Size of the string literal target (deduced; includes null terminator). |
| str | String to test. |
| target | String literal suffix to check for. |
true if str ends with target.
|
inlinenodiscardconstexprnoexcept |
Checks whether a string_view ends with a given suffix (constexpr-friendly).
Falls back to std::string_view::ends_with on C++20; otherwise uses manual comparison.
| str | String to test. |
| target | Suffix to check for. |
true if str ends with target.
|
inlinenodiscardnoexcept |
Compile-time check whether str starts with the literal target.
Details.
| SizeT | Size of the string literal target (deduced; includes null terminator). |
| str | String to test. |
| target | String literal prefix to check for. |
true if str begins with target.
|
inlinenodiscardconstexprnoexcept |
Checks whether a string_view starts with a given prefix (constexpr-friendly).
Falls back to std::string_view::starts_with on C++20; otherwise uses manual comparison.
| str | String to test. |
| target | Prefix to check for. |
true if str starts with target.
|
nodiscardnoexcept |
Combines two 64-bit hash values into one using a mixing function.
Based on a Murmur-inspired mix to spread entropy across both inputs. Suitable for building composite hash keys.
| a | First hash value. |
| b | Second hash value. |
|
nodiscardnoexcept |
Converts a std::filesystem::path to a UTF-8 std::string portably.
On Windows, path::string() returns the ANSI path. This function always returns a UTF-8 string regardless of platform.
| path | File-system path. |
|
noexcept |
Replaces all occurrences of from in str with to in-place.
| str | String to modify. |
| from | Substring to search for. |
| to | Replacement substring. |
|
nodiscardnoexcept |
Converts a locally-encoded string to UTF-8.
On POSIX, uses the current locale's iconv to convert from the system encoding. On Windows, reads the active ANSI code page and converts via Win32 APIs.
| local_str | Locally-encoded (system locale) string. |
|
nodiscardnoexcept |
Converts a UTF-8 std::string to a std::wstring.
| input | UTF-8 encoded string. |
|
nodiscardnoexcept |
Converts a UTF-8 string to the locally-encoded system string.
| utf8_str | UTF-8 encoded string. |
|
nodiscardnoexcept |
Converts a decimal string to int.
| str | Decimal integer string. |
| dv | Default value returned when conversion fails. Default: 0. |
dv on failure.
|
nodiscardnoexcept |
Converts a decimal string to int64_t with an optional byte offset.
| str | Decimal integer string. |
| dv | Default value returned when conversion fails. Default: 0. |
| offset | Starting character offset within str. Default: 0. |
dv on failure.
|
nodiscardnoexcept |
Strips leading and trailing whitespace from a string.
| str | Input string. |
|
nodiscardnoexcept |
Converts a std::wstring to a UTF-8 std::string.
| input | Wide-character string. |