BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
String utilities
Collaboration diagram for String utilities:

Files

file  Strings.hpp
file  TextTable.hpp

Namespaces

namespace  util
namespace  util::strings

Classes

struct  util::strings::TextTable

Typedefs

using util::strings::StringViewPair = std::pair<string_view, string_view>
auto util::strings::trim (string_view text) -> string_view
auto util::strings::split_at_first_space (string_view input) -> StringViewPair
auto util::strings::split_at_first_space_or_newline (string_view input) -> StringViewPair
auto util::strings::find_matching_close_paren (string_view input) -> std::expected< size_t, std::string >
template<std::integral Int>
constexpr auto util::strings::int_from_string (string_view text, Int defaultValue=0) noexcept -> Int
template<size_t MaxLen = 5uz>
void util::strings::write_integer (std::integral auto value, std::string &output)
auto util::strings::split_by_delim (string_view text, char delim)
auto util::strings::lines_view (string_view text)
auto util::strings::words_view (string_view text)

Detailed Description

String handling utility functions used throughout the code.

Typedef Documentation

◆ StringViewPair

using util::strings::StringViewPair = std::pair<string_view, string_view>

Utility typedef for a pair of string views.

Definition at line 52 of file Strings.hpp.

Function Documentation

◆ find_matching_close_paren()

auto util::strings::find_matching_close_paren ( string_view input) -> std::expected< size_t, std::string >
nodiscard

For a string beginning with (, finds the index of the matching ) character, taking nested () pairs into account. This function asserts if the input does not begin with (.

If a matching close parentheses character isn't found, returns an explanatory error string.

◆ int_from_string()

template<std::integral Int>
auto util::strings::int_from_string ( string_view text,
Int defaultValue = 0 ) -> Int
nodiscardconstexprnoexcept

Reads an integer from the input string using std::from_chars.

See also
write_integer()

Definition at line 153 of file Strings.hpp.

◆ lines_view()

auto util::strings::lines_view ( string_view text)
inlinenodiscard

Returns a range of string_views, each representing a line from the input string.

See also
words_view(), split_by_delim()

Definition at line 192 of file Strings.hpp.

◆ split_at_first_space()

auto util::strings::split_at_first_space ( string_view input) -> StringViewPair
nodiscard

Splits the input string into segments before and after the first whitespace character. If there is no whitespace in the input string, the returned pair contains a copy of the input string and an empty string_view. If the first character of the input string is a space, the first element of the returned pair is an empty string_view.

See also
split_at_first_space_or_newline()

◆ split_at_first_space_or_newline()

auto util::strings::split_at_first_space_or_newline ( string_view input) -> StringViewPair
nodiscard

Similar to split_at_first_space(), but also splits on newlines.

See also
split_at_first_space()

◆ split_by_delim()

auto util::strings::split_by_delim ( string_view text,
char delim )
inlinenodiscard

Returns a range of string_views created by splitting the input text at the given delimiter.

See also
lines_view(), words_view()

Definition at line 185 of file Strings.hpp.

◆ trim()

auto util::strings::trim ( string_view text) -> string_view
nodiscard

Trims any whitespace characters from the beginning and ending of the string, including space and newline characters.

◆ words_view()

auto util::strings::words_view ( string_view text)
inlinenodiscard

Returns a range of string_views, each representing a word from the input string.

See also
lines_view(), split_by_delim()

Definition at line 197 of file Strings.hpp.

◆ write_integer()

template<size_t MaxLen = 5uz>
void util::strings::write_integer ( std::integral auto value,
std::string & output )

Appends an integer to the output string using std::to_chars. This function uses stack memory for to_chars() to write into. If to_chars() returns an error, output is not changed.

Template Parameters
MaxLenThe maximum number of characters that will be written to output.
See also
int_from_string()

Definition at line 165 of file Strings.hpp.