atl/string.hpp
StringView, String, toString and format.
Functions
Section titled "Functions"inline String toString(StringView v);Parameters
v(StringView)
Returns String
inline String toString(const String &s);Parameters
s(const String &)
Returns String
inline String toString(const char *s);Parameters
s(const char *)
Returns String
inline String toString(bool b);Parameters
b(bool)
Returns String
inline String toString(char c);Parameters
c(char)
Returns String
inline String toString(long long v);Integers in decimal.
Parameters
v(long long)
Returns String
inline String toString(int v);Integers in decimal.
Parameters
v(int)
Returns String
inline String toString(long v);Integers in decimal.
Parameters
v(long)
Returns String
inline String toString(unsigned v);Integers in decimal.
Parameters
v(unsigned int)
Returns String
inline String toString(unsigned long v);Integers in decimal.
Parameters
v(unsigned long)
Returns String
inline String toString(double v);Doubles: whole numbers print without a fraction, anything else through Lua's tostring, so the output matches what a Lua mod would print.
Parameters
v(double)
Returns String
inline String toString(float v);Floats print like doubles.
Parameters
v(float)
Returns String
template <class... Args> String format(StringView fmt, const Args &...args);Builds a string by replacing each "{}" in fmt with the next argument's toString(), e.g. atl::format("pos {} speed {}", pos, 12.5).
Parameters
fmt(StringView)args(const char *const &)args(const char *const &)args(const char &[7])args(const char *const &)args(const char &[7])
Returns String
StringView
Section titled "StringView"A non-owning view of a run of characters (like std::string_view).
class StringViewconstexpr StringView() = defaul;An empty view.
constexpr StringView(const char *data, size_t size);A view of size bytes at data.
Parameters
data(const char *)size(size_t)
constexpr StringView(const char *cstr);A view of a zero-terminated string.
Parameters
cstr(const char *)
constexpr const char *data() const;Pointer to the first character (not zero-terminated in general).
Returns const char *
constexpr size_t size() const;Number of characters.
Returns size_t
constexpr bool empty() const;True when there are no characters.
Returns bool
constexpr char operator[](size_t i) const;The character at index i (unchecked).
Parameters
i(size_t)
Returns char
constexpr const char *begin() const;Iteration over the characters.
Returns const char *
constexpr const char *end() const;Iteration over the characters.
Returns const char *
constexpr StringView substr(size_t pos, size_t n = size_t(-1)) const;Up to n characters starting at pos; pos past the end gives an empty view.
Parameters
pos(size_t)n(size_t)
Returns StringView
constexpr bool startsWith(StringView p) const;True when the view begins with p.
Parameters
p(StringView)
Returns bool
constexpr bool endsWith(StringView s) const;True when the view ends with s.
Parameters
s(StringView)
Returns bool
constexpr size_t find(char c, size_t from = 0) const;Index of the first c at or after from, or npos.
Parameters
c(char)from(size_t)
Returns size_t
static constexpr size_t npos = size_t(-1);Returned by find when nothing matches.
String
Section titled "String"An owning, growable, zero-terminated string.
class StringString() = defaul;An empty string.
String(StringView v);Copies from a view, a C string, or a pointer and length.
Parameters
v(StringView)
String(const char *cstr);Copies from a view, a C string, or a pointer and length.
Parameters
cstr(const char *)
String(const char *data, size_t size);Copies from a view, a C string, or a pointer and length.
Parameters
data(const char *)size(size_t)
String(const String &o);Copies from a view, a C string, or a pointer and length.
Parameters
o(const String &)
String(String &&o) noexcept;Copies from a view, a C string, or a pointer and length.
Parameters
o(String &&)
String &operator=(const String &o);Assignment copies or moves the contents.
Parameters
o(const String &)
Returns String &
String &operator=(String &&o) noexcept;Assignment copies or moves the contents.
Parameters
o(String &&)
Returns String &
const char *data() const;The characters, always zero-terminated ("" when empty).
Returns const char *
const char *c_str() const;Same as data().
Returns const char *
size_t size() const;Number of characters, not counting the terminator.
Returns size_t
bool empty() const;True when the string has no characters.
Returns bool
char operator[](size_t i) const;The character at index i (unchecked).
Parameters
i(size_t)
Returns char
char &operator[](size_t i);The character at index i (unchecked).
Parameters
i(size_t)
Returns char &
StringView view() const;A view of the whole string.
Returns StringView
operator StringView() const;A view of the whole string.
void reserve(size_t n);Makes room for at least n characters without reallocating.
Parameters
n(size_t)
String &append(StringView v);Appends characters to the end.
Parameters
v(StringView)
Returns String &
String &append(char c);Appends characters to the end.
Parameters
c(char)
Returns String &
String &operator+=(StringView v);Appends characters to the end.
Parameters
v(StringView)
Returns String &
String &operator+=(char c);Appends characters to the end.
Parameters
c(char)
Returns String &
void clear();Empties the string, keeping its capacity.