62 #include <string_view>
99 [[nodiscard]]
VLINK_EXPORT int64_t
to_long(const std::
string& str, int64_t dv = 0,
int offset = 0) noexcept;
139 long double value) noexcept;
153 int precision,
bool alt) noexcept;
168 int precision,
bool alt) noexcept;
267 [[nodiscard]]
VLINK_EXPORT std::vector<std::
string>
split(const std::
string& str,
char f = ',') noexcept;
289 std::string_view delimiters = " ,") noexcept;
302 std::string_view delimiters = " ,") noexcept;
420 template <uint8_t SizeT>
421 [[nodiscard]]
bool has_startwith(const std::
string& str, const
char (&target)[SizeT]) noexcept;
431 template <uint8_t SizeT>
432 [[nodiscard]]
bool has_endwith(const std::
string& str, const
char (&target)[SizeT]) noexcept;
441 [[nodiscard]] constexpr
bool has_startwith(std::string_view str, std::string_view target) noexcept;
450 [[nodiscard]] constexpr
bool has_endwith(std::string_view str, std::string_view target) noexcept;
459 [[nodiscard]] constexpr
bool contains_substring(std::string_view sv, std::string_view needle) noexcept;
465 template <uint8_t SizeT>
466 inline
bool has_startwith(const std::
string& str, const
char (&target)[SizeT]) noexcept {
467 if constexpr (SizeT == 0) {
472 return str.compare(0, SizeT - 1, target) == 0;
475 template <u
int8_t SizeT>
476 inline bool has_endwith(
const std::string& str,
const char (&target)[SizeT]) noexcept {
477 if constexpr (SizeT == 0) {
486 return str.compare(str.size() - (SizeT - 1), SizeT - 1, target) == 0;
489 inline constexpr
bool has_startwith(std::string_view str, std::string_view target) noexcept {
490 #if __cplusplus >= 202002L
491 return str.starts_with(target);
493 return target.size() <= str.size() && str.substr(0, target.size()) == target;
497 inline constexpr
bool has_endwith(std::string_view str, std::string_view target) noexcept {
498 #if __cplusplus >= 202002L
499 return str.ends_with(target);
501 return target.size() <= str.size() && str.substr(str.size() - target.size(), target.size()) == target;
510 return sv.find(needle) != std::string_view::npos;
Cross-platform macros for visibility, branch hints, copy prevention, singletons and string helpers.
#define VUNLIKELY(...)
Short alias for VLINK_UNLIKELY.
Definition: macros.h:292
#define VLINK_EXPORT
Definition: macros.h:81
VLINK_EXPORT std::string trim_string(const std::string &str) noexcept
Returns str with leading and trailing whitespace removed.
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.
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_view trim_string_view(std::string_view str) noexcept
Trims whitespace from both sides of a string_view without allocating.
bool has_startwith(const std::string &str, const char(&target)[SizeT]) noexcept
Compile-time prefix check against a string literal.
Definition: helpers.h:466
constexpr bool contains_substring(std::string_view sv, std::string_view needle) noexcept
Constexpr substring search.
Definition: helpers.h:505
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 wstring_to_string(const std::wstring &input) noexcept
Converts a wide-character string to UTF-8.
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 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 uint32_t get_hash_code(const std::string &str) noexcept
Maps a string to a 32-bit code.
VLINK_EXPORT size_t format_floating_to(char *buf, size_t buflen, float value) noexcept
Formats a float into a caller-provided buffer using default "%g" precision.
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::wstring string_to_wstring(const std::string &input) noexcept
Converts UTF-8 to a wide-character string.
VLINK_EXPORT std::string double_to_string(double value, int precision=2) noexcept
Formats a double with the requested decimal precision.
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::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::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_file_size(size_t size) noexcept
Renders a byte count as a KB / MB / GB string with two decimal places.
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 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::string unescape_field(std::string_view value) noexcept
Reverses escape_field encoding.
VLINK_EXPORT size_t format_floating_spec_to(char *buf, size_t buflen, double value, char type, int precision, bool alt) noexcept
Formats a double using a std::format style floating-point presentation.
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 format_time_diff(int32_t milliseconds) noexcept
Renders a millisecond time delta as "HH:MM:SS:mmm".
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 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 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 path_to_string(const std::filesystem::path &path) noexcept
Converts a filesystem path to a portable UTF-8 string.
bool has_endwith(const std::string &str, const char(&target)[SizeT]) noexcept
Compile-time suffix check against a string literal.
Definition: helpers.h:476