|
VLink
2.0.0
A high-performance communication middleware
|
Stateless utility functions shared across VLink subsystems. 更多...
函数 | |
| VLINK_EXPORT int | to_int (const std::string &str, int dv=0) noexcept |
Parses an integer string with auto base detection (0x -> hex, leading 0 -> octal, otherwise decimal). 更多... | |
| VLINK_EXPORT int64_t | to_long (const std::string &str, int64_t dv=0, int offset=0) noexcept |
| Parses a 64-bit integer string with optional trailing-character allowance. 更多... | |
| VLINK_EXPORT std::string | double_to_string (double value, int precision=2) noexcept |
Formats a double with the requested decimal precision. 更多... | |
| VLINK_EXPORT uint64_t | hash_combine (uint64_t a, uint64_t b) noexcept |
| Combines two 64-bit hash values into one via a Murmur-style mix. 更多... | |
| 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 |
Returns str with leading and trailing whitespace removed. 更多... | |
| VLINK_EXPORT std::string_view | trim_string_view (std::string_view str) noexcept |
Trims whitespace from both sides of a string_view without allocating. 更多... | |
| VLINK_EXPORT std::wstring | string_to_wstring (const std::string &input) noexcept |
| Converts UTF-8 to a wide-character string. 更多... | |
| VLINK_EXPORT std::string | wstring_to_string (const std::wstring &input) noexcept |
| Converts a wide-character string to UTF-8. 更多... | |
| VLINK_EXPORT std::string | string_local_to_utf8 (const std::string &local_str) noexcept |
| Converts a system-locale string to UTF-8. 更多... | |
| VLINK_EXPORT std::string | string_utf8_to_local (const std::string &utf8_str) noexcept |
| Converts UTF-8 to the active system locale on Windows; pass-through on POSIX. 更多... | |
| VLINK_EXPORT std::string | path_to_string (const std::filesystem::path &path) noexcept |
| Converts a filesystem path to a portable UTF-8 string. 更多... | |
| VLINK_EXPORT std::vector< std::string > | split (const std::string &str, char f=',') noexcept |
| Splits a string by a single-character delimiter; empty parts are skipped. 更多... | |
| VLINK_EXPORT std::vector< std::string_view > | split_view (std::string_view str, char f=',') noexcept |
Splits a string_view by a delimiter and returns non-owning views. 更多... | |
| VLINK_EXPORT std::vector< std::string > | split_any (const std::string &str, std::string_view delimiters=" ,") noexcept |
Splits a string by any delimiter in delimiters; each token is trimmed and empty tokens are skipped. 更多... | |
| VLINK_EXPORT std::vector< std::string_view > | split_any_view (std::string_view str, std::string_view delimiters=" ,") noexcept |
Splits a view by any delimiter in delimiters and returns non-owning trimmed views. 更多... | |
| VLINK_EXPORT std::string | escape_field (std::string_view value) noexcept |
| Percent-encodes one field of a delimiter-separated text frame. 更多... | |
| VLINK_EXPORT std::string | unescape_field (std::string_view value) noexcept |
Reverses escape_field encoding. 更多... | |
| VLINK_EXPORT uint32_t | get_hash_code (const std::string &str) noexcept |
| Maps a string to a 32-bit code. 更多... | |
| VLINK_EXPORT std::string | format_milliseconds (int64_t milliseconds, bool show_millis) noexcept |
| Renders a millisecond duration as a human-readable time string. 更多... | |
| VLINK_EXPORT std::string | format_date (int64_t nanoseconds_since_epoch) noexcept |
Renders a nanosecond Unix timestamp as "YYYY-MM-DD @c HH:MM:SS.mmm" in UTC. 更多... | |
| VLINK_EXPORT std::string | format_time_diff (int32_t milliseconds) noexcept |
Renders a millisecond time delta as "HH:MM:SS:mmm". 更多... | |
| VLINK_EXPORT std::string | format_hex_number (int64_t hex_number) noexcept |
Renders a signed 64-bit integer as a "0x..." hex literal. 更多... | |
| VLINK_EXPORT std::string | format_hex_number (uint64_t hex_number) noexcept |
Renders an unsigned 64-bit integer as a "0x..." hex literal. 更多... | |
| VLINK_EXPORT std::string | format_file_size (size_t size) noexcept |
| Renders a byte count as a KB / MB / GB string with two decimal places. 更多... | |
| VLINK_EXPORT std::string | format_rate_size (size_t size) noexcept |
| Renders a byte-per-second rate as a B/s, KB/s, MB/s or GB/s string. 更多... | |
| VLINK_EXPORT int64_t | convert_date_to_timestamp (const std::string &date) noexcept |
Parses a "%Y/%m/%d @c %H:%M:%S" (optionally ":<ms>") date into a Unix nanosecond timestamp. 更多... | |
| template<uint8_t SizeT> | |
| bool | has_startwith (const std::string &str, const char(&target)[SizeT]) noexcept |
| Compile-time prefix check against a string literal. 更多... | |
| template<uint8_t SizeT> | |
| bool | has_endwith (const std::string &str, const char(&target)[SizeT]) noexcept |
| Compile-time suffix check against a string literal. 更多... | |
| constexpr bool | has_startwith (std::string_view str, std::string_view target) noexcept |
Constexpr prefix check for two string_view values. 更多... | |
| constexpr bool | has_endwith (std::string_view str, std::string_view target) noexcept |
Constexpr suffix check for two string_view values. 更多... | |
| constexpr bool | contains_substring (std::string_view sv, std::string_view needle) noexcept |
| Constexpr substring search. 更多... | |
Stateless utility functions shared across VLink subsystems.
|
inlineconstexprnoexcept |
Constexpr substring search.
| sv | String to search. |
| needle | Substring to look for; an empty needle returns true. |
true when sv contains needle.
|
noexcept |
Parses a "%Y/%m/%d @c %H:%M:%S" (optionally ":<ms>") date into a Unix nanosecond timestamp.
Interpreted in the local timezone via std::mktime. ISO-8601 dashes are not accepted.
| date | Source date string. |
-1 on parse failure.
|
noexcept |
Formats a double with the requested decimal precision.
| value | Source value. |
| precision | Number of digits after the decimal point. Default: 2. |
|
noexcept |
Percent-encodes one field of a delimiter-separated text frame.
Encodes %, space, :, LF and CR as uppercase XX sequences; other bytes pass through.
| value | Field to encode. |
|
noexcept |
Renders a nanosecond Unix timestamp as "YYYY-MM-DD @c HH:MM:SS.mmm" in UTC.
| nanoseconds_since_epoch | Source timestamp. |
|
noexcept |
Renders a byte count as a KB / MB / GB string with two decimal places.
| size | Source value in bytes. |
|
noexcept |
Renders a signed 64-bit integer as a "0x..." hex literal.
| hex_number | Source value. |
|
noexcept |
Renders an unsigned 64-bit integer as a "0x..." hex literal.
| hex_number | Source value. |
|
noexcept |
Renders a millisecond duration as a human-readable time string.
| milliseconds | Source duration. |
| show_millis | When true the millisecond field is appended. |
|
noexcept |
Renders a byte-per-second rate as a B/s, KB/s, MB/s or GB/s string.
| size | Source rate in bytes per second. |
|
noexcept |
Renders a millisecond time delta as "HH:MM:SS:mmm".
| milliseconds | Source delta. |
|
noexcept |
Maps a string to a 32-bit code.
If str parses as an integer it is returned as its numeric value; otherwise the result is std::hash<std::string> truncated to 32 bits. An empty string yields 0.
| str | Source string. |
|
inlinenoexcept |
Compile-time suffix check against a string literal.
| SizeT | Size of target including the null terminator (deduced). |
| str | String to test. |
| target | Literal suffix. |
true when str ends with target.
|
inlineconstexprnoexcept |
Constexpr suffix check for two string_view values.
| str | String to test. |
| target | Suffix to check for. |
true when str ends with target.
|
inlinenoexcept |
Compile-time prefix check against a string literal.
Details
| SizeT | Size of target including the null terminator (deduced). |
| str | String to test. |
| target | Literal prefix. |
true when str starts with target.
|
inlineconstexprnoexcept |
Constexpr prefix check for two string_view values.
| str | String to test. |
| target | Prefix to check for. |
true when str starts with target.
|
noexcept |
Combines two 64-bit hash values into one via a Murmur-style mix.
| a | First hash value. |
| b | Second hash value. |
|
noexcept |
Converts a filesystem path to a portable UTF-8 string.
| path | Source path. |
|
noexcept |
Replaces all occurrences of from in str with to in place.
| str | String mutated in place. |
| from | Substring to search for. |
| to | Replacement substring. |
|
noexcept |
Splits a string by a single-character delimiter; empty parts are skipped.
| str | Source string. |
| f | Delimiter character. Defaults to ','. |
|
noexcept |
Splits a string by any delimiter in delimiters; each token is trimmed and empty tokens are skipped.
| str | Source string. |
| delimiters | Delimiter character set. Defaults to " ,". |
|
noexcept |
Splits a view by any delimiter in delimiters and returns non-owning trimmed views.
The caller must keep str alive while the returned views are used.
| str | Source view. |
| delimiters | Delimiter character set. Defaults to " ,". |
|
noexcept |
Splits a string_view by a delimiter and returns non-owning views.
The caller must keep str alive while the returned views are used.
| str | Source view. |
| f | Delimiter character. Defaults to ','. |
|
noexcept |
Converts a system-locale string to UTF-8.
Performs Windows ANSI-code-page conversion; returns the input unchanged on POSIX.
| local_str | Locally encoded string. |
|
noexcept |
Converts UTF-8 to a wide-character string.
| input | UTF-8 source. |
|
noexcept |
Converts UTF-8 to the active system locale on Windows; pass-through on POSIX.
| utf8_str | UTF-8 source. |
|
noexcept |
Parses an integer string with auto base detection (0x -> hex, leading 0 -> octal, otherwise decimal).
| str | Source string. |
| dv | Default value returned on parse failure. Default: 0. |
int or dv on failure.
|
noexcept |
Parses a 64-bit integer string with optional trailing-character allowance.
Calls std::stoll with auto base detection (0x -> hex, leading 0 -> octal, otherwise decimal). Parsing always starts at index 0; offset is the number of trailing characters the parser may leave unconsumed (for example to skip a unit suffix such as "100s" with offset == 1). Mismatched consumption returns dv.
| str | Source string. |
| dv | Default value on failure. Default: 0. |
| offset | Number of trailing characters allowed to remain unconsumed. Default: 0. |
int64_t or dv on failure.
|
noexcept |
Returns str with leading and trailing whitespace removed.
| str | Source string. |
|
noexcept |
Trims whitespace from both sides of a string_view without allocating.
The returned view references the same storage as str; callers must keep the original character storage alive while using the result.
| str | Source view. |
str is empty or all whitespace.
|
noexcept |
Reverses escape_field encoding.
Decodes valid XX sequences; preserves invalid or truncated sequences verbatim so legacy frames remain parseable.
| value | Encoded field. |
|
noexcept |
Converts a wide-character string to UTF-8.
| input | Wide source. |