VLink  2.0.0
A high-performance communication middleware
helpers.h 文件参考

Stateless string, number, hash and formatting helpers used throughout VLink. 更多...

#include <cstdint>
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>
#include "./macros.h"
helpers.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

命名空间

 
 

函数

VLINK_EXPORT int vlink::Helpers::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 vlink::Helpers::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 vlink::Helpers::double_to_string (double value, int precision=2) noexcept
 Formats a double with the requested decimal precision. 更多...
 
VLINK_EXPORT uint64_t vlink::Helpers::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 vlink::Helpers::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 vlink::Helpers::trim_string (const std::string &str) noexcept
 Returns str with leading and trailing whitespace removed. 更多...
 
VLINK_EXPORT std::string_view vlink::Helpers::trim_string_view (std::string_view str) noexcept
 Trims whitespace from both sides of a string_view without allocating. 更多...
 
VLINK_EXPORT std::wstring vlink::Helpers::string_to_wstring (const std::string &input) noexcept
 Converts UTF-8 to a wide-character string. 更多...
 
VLINK_EXPORT std::string vlink::Helpers::wstring_to_string (const std::wstring &input) noexcept
 Converts a wide-character string to UTF-8. 更多...
 
VLINK_EXPORT std::string vlink::Helpers::string_local_to_utf8 (const std::string &local_str) noexcept
 Converts a system-locale string to UTF-8. 更多...
 
VLINK_EXPORT std::string vlink::Helpers::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 vlink::Helpers::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 > vlink::Helpers::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 > vlink::Helpers::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 > vlink::Helpers::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 > vlink::Helpers::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 vlink::Helpers::escape_field (std::string_view value) noexcept
 Percent-encodes one field of a delimiter-separated text frame. 更多...
 
VLINK_EXPORT std::string vlink::Helpers::unescape_field (std::string_view value) noexcept
 Reverses escape_field encoding. 更多...
 
VLINK_EXPORT uint32_t vlink::Helpers::get_hash_code (const std::string &str) noexcept
 Maps a string to a 32-bit code. 更多...
 
VLINK_EXPORT std::string vlink::Helpers::format_milliseconds (int64_t milliseconds, bool show_millis) noexcept
 Renders a millisecond duration as a human-readable time string. 更多...
 
VLINK_EXPORT std::string vlink::Helpers::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 vlink::Helpers::format_time_diff (int32_t milliseconds) noexcept
 Renders a millisecond time delta as "HH:MM:SS:mmm". 更多...
 
VLINK_EXPORT std::string vlink::Helpers::format_hex_number (int64_t hex_number) noexcept
 Renders a signed 64-bit integer as a "0x..." hex literal. 更多...
 
VLINK_EXPORT std::string vlink::Helpers::format_hex_number (uint64_t hex_number) noexcept
 Renders an unsigned 64-bit integer as a "0x..." hex literal. 更多...
 
VLINK_EXPORT std::string vlink::Helpers::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 vlink::Helpers::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 vlink::Helpers::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 vlink::Helpers::has_startwith (const std::string &str, const char(&target)[SizeT]) noexcept
 Compile-time prefix check against a string literal. 更多...
 
template<uint8_t SizeT>
bool vlink::Helpers::has_endwith (const std::string &str, const char(&target)[SizeT]) noexcept
 Compile-time suffix check against a string literal. 更多...
 
constexpr bool vlink::Helpers::has_startwith (std::string_view str, std::string_view target) noexcept
 Constexpr prefix check for two string_view values. 更多...
 
constexpr bool vlink::Helpers::has_endwith (std::string_view str, std::string_view target) noexcept
 Constexpr suffix check for two string_view values. 更多...
 
constexpr bool vlink::Helpers::contains_substring (std::string_view sv, std::string_view needle) noexcept
 Constexpr substring search. 更多...
 

详细描述

Stateless string, number, hash and formatting helpers used throughout VLink.

Functions in this header are portable, allocation-free where possible, and never throw; bad input is reported via empty / default return values. Encoding conversion routines fall back to a pass-through on POSIX where the input is assumed to already be UTF-8.

Helper categories
Category Representative entry points
Number parsing to_int, to_long, double_to_string
Hashing hash_combine, get_hash_code
String editing replace_string, trim_string, trim_string_view
Wide / locale string_to_wstring, wstring_to_string, string_local_to_utf8, string_utf8_to_local
Filesystem path_to_string
Splitting split, split_view, split_any, split_any_view
Field encoding escape_field, unescape_field
Time formatting format_milliseconds, format_date, format_time_diff
Number formatting format_hex_number, format_file_size, format_rate_size
Date parsing convert_date_to_timestamp
Prefix / suffix has_startwith, has_endwith, contains_substring
Example
auto parts = vlink::Helpers::split("a,b,c", ','); // {"a", "b", "c"}
std::string size = vlink::Helpers::format_file_size(1536); // "1.50KB"
bool startsWith = vlink::Helpers::has_startwith("vlink://hello", "vlink://");