117 explicit
String(const
char* str) noexcept;
188 const char* text = data();
189 return text ? text + size() :
nullptr;
244 inline const char*
data() const noexcept {
245 return static_cast<const char*
>(m_text);
253 return m_text.Length();
268 inline bool empty() const noexcept {
279 return m_text[index];
286 inline explicit operator bool() const noexcept {
287 return static_cast<bool>(m_text);
302 inline operator std::string_view() const noexcept {
303 return static_cast<std::string_view
>(m_text);
311 return static_cast<std::string
>(m_text);
319 inline explicit operator const char*()
const noexcept {
320 return static_cast<const char*
>(m_text);
333 inline const
CString& Bytes() const noexcept {
344 static constexpr Size npos{~0ull};
352 return static_cast<std::string_view
>(*this).starts_with(text);
361 return static_cast<std::string_view
>(*this).starts_with(ch);
369 inline bool ends_with(std::string_view text)
const noexcept {
370 return static_cast<std::string_view
>(*this).ends_with(text);
379 return static_cast<std::string_view
>(*this).ends_with(ch);
387 inline bool contains(std::string_view text)
const noexcept {
388 return static_cast<std::string_view
>(*this).contains(text);
397 return static_cast<std::string_view
>(*this).contains(ch);
406 inline Size find(std::string_view text,
Size pos = {})
const noexcept {
407 return FindAt(
static_cast<std::string_view
>(*
this), text, pos);
417 return FindAt(
static_cast<std::string_view
>(*
this), ch, pos);
428 return find(std::string_view(text,
static_cast<std::size_t
>(count)), pos);
438 return RFindAt(
static_cast<std::string_view
>(*
this), text, pos);
448 return RFindAt(
static_cast<std::string_view
>(*
this), ch, pos);
459 return rfind(std::string_view(text,
static_cast<std::size_t
>(count)), pos);
469 const std::string_view self = *
this;
470 if (pos >
Size{self.size()})
472 return FromIndex(self.find_first_of(text,
static_cast<std::size_t
>(pos)));
482 return find(ch, pos);
492 const std::string_view self = *
this;
493 const std::size_t start = pos == npos ? std::string_view::npos :
static_cast<std::size_t
>(pos);
494 return FromIndex(self.find_last_of(text, start));
504 return rfind(ch, pos);
514 const std::string_view self = *
this;
515 if (pos >
Size{self.size()})
517 return FromIndex(self.find_first_not_of(text,
static_cast<std::size_t
>(pos)));
527 const std::string_view self = *
this;
528 if (pos >
Size{self.size()})
530 return FromIndex(self.find_first_not_of(ch,
static_cast<std::size_t
>(pos)));
540 const std::string_view self = *
this;
541 const std::size_t start = pos == npos ? std::string_view::npos :
static_cast<std::size_t
>(pos);
542 return FromIndex(self.find_last_not_of(text, start));
552 const std::string_view self = *
this;
553 const std::size_t start = pos == npos ? std::string_view::npos :
static_cast<std::size_t
>(pos);
554 return FromIndex(self.find_last_not_of(ch, start));
564 const std::string_view text = *
this;
565 if (pos >
Size{text.size()})
567 const std::size_t n = count == npos ? std::string_view::npos :
static_cast<std::size_t
>(count);
568 return String(text.substr(
static_cast<std::size_t
>(pos), n));
576 inline int compare(std::string_view text)
const noexcept {
577 return static_cast<std::string_view
>(*this).compare(text);
585 inline char front() const noexcept {
586 return (*
this)[
Size{0}];
594 inline char back() const noexcept {
595 return (*
this)[size() -
Size{1}];
649 while (i < str.size()) {
650 while (i < str.size() && std::isspace(
static_cast<unsigned char>(str[i])) != 0)
655 while (j < str.size() && std::isspace(
static_cast<unsigned char>(str[j])) == 0)
657 out.emplace_back(str.substr(i, j - i));
672 std::size_t start = 0;
673 for (std::size_t i = 0; i <= str.size(); ++i) {
674 if (i == str.size() || str[i] == delimiter) {
675 out.emplace(str.substr(start, i - start));
686 return ToLower(
static_cast<std::string_view
>(*
this));
694 return ToUpper(
static_cast<std::string_view
>(*
this));
702 return SanitizeNewlines(
static_cast<std::string_view
>(*
this));
710 return RemoveWhitespace(
static_cast<std::string_view
>(*
this));
718 return IsInteger(
static_cast<std::string_view
>(*
this));
726 std::vector<String> out;
727 Split(
static_cast<std::string_view
>(*
this), out);
737 std::queue<String> out;
738 Explode(
static_cast<std::string_view
>(*
this), delimiter, out);
755 return m_text == other.m_text;
764 return !(*
this == other);
773 return m_text == str;
782 return !(*
this == str);
791 return m_text <=> other.m_text;
799 inline std::strong_ordering
operator<=>(
const char* str)
const noexcept {
800 return m_text <=> str;
812 static Size FromIndex(std::size_t index)
noexcept {
813 return index == std::string_view::npos ? npos :
Size{index};
816 template<
typename Needle>
817 static Size FindAt(std::string_view self, Needle needle,
Size pos)
noexcept {
818 if (pos >
Size{self.size()})
820 return FromIndex(self.find(needle,
static_cast<std::size_t
>(pos)));
823 template<
typename Needle>
824 static Size RFindAt(std::string_view self, Needle needle, Size pos)
noexcept {
825 const std::size_t start = pos == npos ? std::string_view::npos :
static_cast<std::size_t
>(pos);
826 return FromIndex(self.rfind(needle, start));
839 return stream << text.Bytes();
884 return std::hash<std::string_view>{}(
static_cast<std::string_view
>(text));
Owned UTF-8 text composed of StormByte::CString.
Definition string.hxx:97
std::strong_ordering operator<=>(const String &other) const noexcept
Content order.
Definition string.hxx:790
Size find_last_not_of(std::string_view text, Size pos=npos) const noexcept
Last byte that is not in text, at or before pos.
Definition string.hxx:539
char value_type
Byte type.
Definition string.hxx:99
char operator[](const Size &index) const noexcept
Character at index.
Definition string.hxx:278
String substr(Size pos={}, Size count=npos) const noexcept
Copy of a slice.
Definition string.hxx:563
Size size() const noexcept
Character count; 0 when null or empty.
Definition string.hxx:252
bool ends_with(char ch) const noexcept
Whether the text ends with ch.
Definition string.hxx:378
Size length() const noexcept
Same as size.
Definition string.hxx:260
const_iterator cbegin() const noexcept
First character, or null.
Definition string.hxx:196
String ToUpper() const noexcept
ASCII-letter upper case of this text.
Definition string.hxx:693
Size find_first_not_of(char ch, Size pos={}) const noexcept
First byte other than ch, at or after pos.
Definition string.hxx:526
bool operator!=(const String &other) const noexcept
Content inequality.
Definition string.hxx:763
Size find(const char *text, Size pos, Size count) const noexcept
First occurrence of count bytes of text.
Definition string.hxx:427
static String RemoveWhitespace(std::string_view str) noexcept
Drops isspace bytes.
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse observer.
Definition string.hxx:101
bool contains(char ch) const noexcept
Whether ch occurs.
Definition string.hxx:396
bool empty() const noexcept
Whether size is zero.
Definition string.hxx:268
char back() const noexcept
Last byte.
Definition string.hxx:594
bool starts_with(char ch) const noexcept
Whether the text begins with ch.
Definition string.hxx:360
static String ToLower(std::string_view str) noexcept
ASCII-letter lower case; UTF-8 otherwise copied.
Size find(std::string_view text, Size pos={}) const noexcept
First occurrence of text at or after pos.
Definition string.hxx:406
void swap(String &other) noexcept
Swaps buffers with other.
int compare(std::string_view text) const noexcept
Same order as std::string_view::compare.
Definition string.hxx:576
static String ToUpper(std::string_view str) noexcept
ASCII-letter upper case; UTF-8 otherwise copied.
bool operator==(const String &other) const noexcept
Content equality.
Definition string.hxx:754
const_reverse_iterator rbegin() const noexcept
Reverse begin.
Definition string.hxx:212
Size find_last_not_of(char ch, Size pos=npos) const noexcept
Last byte other than ch, at or before pos.
Definition string.hxx:551
String ToLower() const noexcept
ASCII-letter lower case of this text.
Definition string.hxx:685
Size find(char ch, Size pos={}) const noexcept
First occurrence of ch at or after pos.
Definition string.hxx:416
const_iterator end() const noexcept
One past the last character, or null.
Definition string.hxx:187
char front() const noexcept
First byte.
Definition string.hxx:585
static STORMBYTE_FORCE_INLINE void Explode(std::string_view str, char delimiter, std::queue< String > &out) noexcept
Tokens on delimiter.
Definition string.hxx:669
static bool IsInteger(std::string_view str) noexcept
Optional sign plus ASCII digits.
bool operator==(const char *str) const noexcept
Content equality with a C string.
Definition string.hxx:772
String() noexcept
Null text.
Size rfind(char ch, Size pos=npos) const noexcept
Last occurrence of ch at or before pos.
Definition string.hxx:447
String RemoveWhitespace() const noexcept
Drops isspace bytes from this text.
Definition string.hxx:709
bool starts_with(std::string_view text) const noexcept
Whether the text begins with text.
Definition string.hxx:351
STORMBYTE_FORCE_INLINE std::queue< String > Explode(char delimiter) const noexcept
Tokens on delimiter.
Definition string.hxx:736
STORMBYTE_FORCE_INLINE std::vector< String > Split() const noexcept
Whitespace-separated tokens.
Definition string.hxx:725
bool ends_with(std::string_view text) const noexcept
Whether the text ends with text.
Definition string.hxx:369
String SanitizeNewlines() const noexcept
CR LF to LF on this text.
Definition string.hxx:701
Size rfind(std::string_view text, Size pos=npos) const noexcept
Last occurrence of text at or before pos.
Definition string.hxx:437
Size find_last_of(std::string_view text, Size pos=npos) const noexcept
Last byte that is in text, at or before pos.
Definition string.hxx:491
Size find_first_not_of(std::string_view text, Size pos={}) const noexcept
First byte that is not in text, at or after pos.
Definition string.hxx:513
const_iterator cend() const noexcept
One past the last character, or null.
Definition string.hxx:204
std::strong_ordering operator<=>(const char *str) const noexcept
Content order against a C string.
Definition string.hxx:799
const char * const_iterator
Contiguous observer.
Definition string.hxx:100
static String SanitizeNewlines(std::string_view str) noexcept
Turns CR LF into LF.
Size find_first_of(char ch, Size pos={}) const noexcept
First ch at or after pos.
Definition string.hxx:481
bool contains(std::string_view text) const noexcept
Whether text occurs.
Definition string.hxx:387
Size rfind(const char *text, Size pos, Size count) const noexcept
Last occurrence of count bytes of text.
Definition string.hxx:458
const char * data() const noexcept
Contiguous pointer; null when the buffer is null.
Definition string.hxx:244
Size find_last_of(char ch, Size pos=npos) const noexcept
Last ch at or before pos.
Definition string.hxx:503
static STORMBYTE_FORCE_INLINE void Split(std::string_view str, std::vector< String > &out) noexcept
Whitespace-separated tokens.
Definition string.hxx:646
const_reverse_iterator rend() const noexcept
Reverse end.
Definition string.hxx:220
bool operator!=(const char *str) const noexcept
Content inequality with a C string.
Definition string.hxx:781
bool IsInteger() const noexcept
Whether this text is an integer token.
Definition string.hxx:717
Size find_first_of(std::string_view text, Size pos={}) const noexcept
First byte that is in text, at or after pos.
Definition string.hxx:468
const_reverse_iterator crend() const noexcept
Reverse end.
Definition string.hxx:236
const_reverse_iterator crbegin() const noexcept
Reverse begin.
Definition string.hxx:228
Wide counterpart of String.
Definition wstring.hxx:96
void swap(String &left, String &right) noexcept
Swaps two texts.
Definition string.hxx:867
std::ostream & operator<<(std::ostream &stream, const String &text)
Writes text to stream.
Definition string.hxx:838
bool operator==(const char *str, const String &text) noexcept
Content equality.
Definition string.hxx:848
bool operator!=(const char *str, const String &text) noexcept
Content inequality.
Definition string.hxx:858
Root namespace of the StormByte suite.
String module: owned UTF-8 and wide text on top of StormByte::CString / StormByte::WCString.
std::size_t operator()(const StormByte::String::String &text) const noexcept
Hashes text.
Definition string.hxx:883
#define STORMBYTE_STRING_PUBLIC
Definition visibility.h:53