string_utils.h¶
| File Path | engine/include/conjure/core/string_utils.h |
| API ↗ | Strings and identifiers |
ASCII-oriented string helpers used throughout the engine for identifiers, paths, config values and log output. Case conversion and classification are ASCII only on purpose: engine identifiers are ASCII, and locale-aware behaviour would make builds non-deterministic. UTF-8 is treated as opaque bytes everywhere except the explicit UTF-8 <-> UTF-16/UTF-32 conversions.
Constants¶
Functions¶
Public¶
str::contains¶
str::contains¶[[nodiscard]] constexpr bool contains(std::string_view text, std::string_view needle) noexcept;True when needle occurs in text. Every string contains "".
[[nodiscard]] constexpr bool contains(std::string_view text, char character) noexcept;True when character occurs in text.
str::detail::parse_unsigned_digits¶
str::detail::parse_unsigned_digits¶[[nodiscard]] CONJURE_API bool parse_unsigned_digits( std::string_view text, int base, bool allowNegative, u64 limitPositive, u64 limitNegative, u64 &magnitude, bool &negative ) noexcept;Shared body of parse_integer: strips the sign and prefix, then converts the digits. negative is only accepted when allowNegative is set. Returns false on any error.
str::ends_with¶
str::ends_with¶[[nodiscard]] constexpr bool ends_with(std::string_view text, std::string_view suffix) noexcept;True when text ends with suffix (byte-wise). Every string ends with "".
str::format_bytes¶
str::format_bytes¶[[nodiscard]] CONJURE_API std::string format_bytes(u64 bytes);Human readable byte count with binary units: "512 B", "1.0 KiB", "1.5 MiB", "2.0 GiB". Values below 1 KiB print as whole bytes; larger values print one decimal.
str::from_utf16¶
str::from_utf16¶[[nodiscard]] CONJURE_API std::string from_utf16(std::u16string_view utf16);Encodes UTF-16 as UTF-8. Unpaired surrogates become U+FFFD; the function never fails.
str::from_utf32¶
str::from_utf32¶[[nodiscard]] CONJURE_API std::string from_utf32(std::u32string_view utf32);Encodes UTF-32 as UTF-8. Surrogate code points and values above U+10FFFF become U+FFFD; the function never fails.
str::from_wide¶
str::from_wide¶[[nodiscard]] CONJURE_API std::string from_wide(std::wstring_view wide);Platform wide string to UTF-8. Inverse of to_wide(); unpaired surrogates and invalid UTF-32 code points become U+FFFD, as in from_utf16()/from_utf32().
str::iends_with¶
str::iends_with¶[[nodiscard]] constexpr bool iends_with(std::string_view text, std::string_view suffix) noexcept;ends_with() ignoring ASCII case.
str::iequals¶
str::iequals¶[[nodiscard]] constexpr bool iequals(std::string_view left, std::string_view right) noexcept;True when the two strings are equal ignoring ASCII case.
str::is_alnum¶
str::is_alnum¶[[nodiscard]] constexpr bool is_alnum(char character) noexcept;True for ASCII letters and digits.
str::is_alpha¶
str::is_alpha¶[[nodiscard]] constexpr bool is_alpha(char character) noexcept;True for 'a'..'z' and 'A'..'Z'.
str::is_space¶
str::is_space¶[[nodiscard]] constexpr bool is_space(char character) noexcept;True for the characters in WHITESPACE.
str::is_valid_identifier¶
str::is_valid_identifier¶[[nodiscard]] constexpr bool is_valid_identifier(std::string_view text) noexcept;True when text is a C-style identifier: non-empty, starts with an ASCII letter or '_', and continues with ASCII letters, digits or '_'.
str::is_valid_utf8¶
str::is_valid_utf8¶[[nodiscard]] CONJURE_API bool is_valid_utf8(std::string_view text) noexcept;True when text is a valid UTF-8 byte sequence (no overlong forms, surrogates or code points above U+10FFFF). The empty string is valid.
str::istarts_with¶
str::istarts_with¶[[nodiscard]] constexpr bool istarts_with(std::string_view text, std::string_view prefix) noexcept;starts_with() ignoring ASCII case.
str::join¶
str::join¶template <typename Range> requires std::convertible_to<std::ranges::range_value_t<Range>, std::string_view> [[nodiscard]] std::string join(const Range &pieces, std::string_view separator);Concatenates the pieces with separator between them. Accepts any range whose elements convert to std::string_view (std::vector<std::string>, std::span<std::string_view>, ...).
str::parse_bool¶
str::parse_bool¶[[nodiscard]] CONJURE_API std::optional<bool> parse_bool(std::string_view text) noexcept;Parses "true"/"false", "yes"/"no", "on"/"off" and "1"/"0", ignoring ASCII case.
str::parse_double¶
str::parse_double¶[[nodiscard]] CONJURE_API std::optional<f64> parse_double(std::string_view text) noexcept;Parses the whole of text as a decimal floating-point number: optional sign, digits, optional fraction and exponent ("1", "-2.5", "1e-3", ".5", "7."), plus "inf"/"nan" in any case. Hexadecimal floats, whitespace and trailing characters are rejected.
str::parse_float¶
str::parse_float¶[[nodiscard]] CONJURE_API std::optional<f32> parse_float(std::string_view text) noexcept;parse_double() narrowed to f32. Finite values that overflow f32 are rejected.
str::parse_int¶
str::parse_int¶[[nodiscard]] CONJURE_API std::optional<i64> parse_int(std::string_view text, int base = 10) noexcept;parse_integer<i64>.
str::parse_integer¶
str::parse_integer¶template <std::integral T> requires(!std::same_as<T, bool>) [[nodiscard]] std::optional<T> parse_integer(std::string_view text, int base = 10) noexcept;Parses the whole of text as an integer of type T in base (2..36). Accepts an optional leading '+' or (for signed types) '-', and for base 16 an optional "0x"/"0X" prefix. No whitespace, no trailing characters, no digits outside the base; out-of-range values fail.
template <std::integral T> requires(!std::same_as<T, bool>) std::optional<T> parse_integer(std::string_view text, int base) noexcept;str::parse_uint¶
str::parse_uint¶[[nodiscard]] CONJURE_API std::optional<u64> parse_uint(std::string_view text, int base = 10) noexcept;parse_integer<u64>. A leading '-' is rejected.
str::replace_all¶
str::replace_all¶[[nodiscard]] CONJURE_API std::string replace_all( std::string_view text, std::string_view from, std::string_view to );Copy of text with every non-overlapping occurrence of from replaced by to, scanning left to right. An empty from returns text unchanged.
str::split¶
str::split¶[[nodiscard]] CONJURE_API std::vector<std::string_view> split( std::string_view text, char delimiter, bool keepEmpty = true );Splits text at every delimiter. The pieces are views into text. With keepEmpty the result has exactly one more piece than there are delimiters (so "" yields [""] and "a,,b" yields ["a", "", "b"]); without it empty pieces are dropped.
[[nodiscard]] CONJURE_API std::vector<std::string_view> split( std::string_view text, std::string_view delimiter, bool keepEmpty = true );Splits text at every occurrence of the multi-character delimiter. An empty delimiter yields the whole text as a single piece. Same keepEmpty rules as the char overload.
str::split_lines¶
str::split_lines¶[[nodiscard]] CONJURE_API std::vector<std::string_view> split_lines(std::string_view text);Splits text into lines at "\n", "\r\n" or a lone "\r". Line terminators are not part of the pieces; a trailing terminator does not produce an extra empty line.
str::starts_with¶
str::starts_with¶[[nodiscard]] constexpr bool starts_with(std::string_view text, std::string_view prefix) noexcept;True when text begins with prefix (byte-wise). Every string starts with "".
str::to_lower¶
str::to_lower¶[[nodiscard]] constexpr char to_lower(char character) noexcept;Lower-cases one ASCII letter; every other byte is returned unchanged.
[[nodiscard]] CONJURE_API std::string to_lower(std::string_view text);Copy of text with ASCII letters lower-cased. Other bytes (including UTF-8) are untouched.
str::to_lower_in_place¶
str::to_lower_in_place¶CONJURE_API void to_lower_in_place(std::string &text) noexcept;Lower-cases the ASCII letters of text in place.
str::to_upper¶
str::to_upper¶[[nodiscard]] constexpr char to_upper(char character) noexcept;Upper-cases one ASCII letter; every other byte is returned unchanged.
[[nodiscard]] CONJURE_API std::string to_upper(std::string_view text);Copy of text with ASCII letters upper-cased. Other bytes (including UTF-8) are untouched.
str::to_upper_in_place¶
str::to_upper_in_place¶CONJURE_API void to_upper_in_place(std::string &text) noexcept;Upper-cases the ASCII letters of text in place.
str::to_utf16¶
str::to_utf16¶[[nodiscard]] CONJURE_API std::u16string to_utf16(std::string_view utf8);Decodes UTF-8 to UTF-16. Malformed bytes (truncated sequences, overlong forms, encoded surrogates, code points above U+10FFFF) each become U+FFFD; the function never fails.
str::to_utf32¶
str::to_utf32¶[[nodiscard]] CONJURE_API std::u32string to_utf32(std::string_view utf8);Decodes UTF-8 to UTF-32 (one code point per element). Same error handling as to_utf16().
str::to_wide¶
str::to_wide¶[[nodiscard]] CONJURE_API std::wstring to_wide(std::string_view utf8);UTF-8 to the platform wide string: UTF-16 where wchar_t is 16 bits (Windows paths and Win32 calls), UTF-32 where it is 32 bits. Same error handling as to_utf16()/to_utf32().
str::trim¶
str::trim¶[[nodiscard]] constexpr std::string_view trim( std::string_view text, std::string_view characters = WHITESPACE ) noexcept;text without leading and trailing characters from characters. Returns a view into text; when nothing remains, an empty view at the end of text.
str::trim_left¶
str::trim_left¶[[nodiscard]] constexpr std::string_view trim_left( std::string_view text, std::string_view characters = WHITESPACE ) noexcept;text without leading characters from characters. Returns a view into text; when nothing remains, an empty view at the end of text.
str::trim_right¶
str::trim_right¶[[nodiscard]] constexpr std::string_view trim_right( std::string_view text, std::string_view characters = WHITESPACE ) noexcept;text without trailing characters from characters. Returns a view into text; when nothing remains, an empty view at the start of text.