116 explicit
WString(const
wchar_t* str) noexcept;
187 const wchar_t* text = data();
188 return text ? text + size() :
nullptr;
243 inline const wchar_t*
data() const noexcept {
244 return static_cast<const wchar_t*
>(m_text);
252 return m_text.Length();
267 inline bool empty() const noexcept {
278 return m_text[index];
285 inline explicit operator bool() const noexcept {
286 return static_cast<bool>(m_text);
301 inline operator std::wstring_view() const noexcept {
302 return static_cast<std::wstring_view
>(m_text);
310 return static_cast<std::wstring
>(m_text);
318 inline explicit operator const wchar_t*()
const noexcept {
319 return static_cast<const wchar_t*
>(m_text);
326 explicit operator String() const noexcept;
343 static constexpr Size npos{~0ull};
351 return static_cast<std::wstring_view
>(*this).starts_with(text);
360 return static_cast<std::wstring_view
>(*this).starts_with(ch);
368 inline bool ends_with(std::wstring_view text)
const noexcept {
369 return static_cast<std::wstring_view
>(*this).ends_with(text);
378 return static_cast<std::wstring_view
>(*this).ends_with(ch);
386 inline bool contains(std::wstring_view text)
const noexcept {
387 return static_cast<std::wstring_view
>(*this).contains(text);
396 return static_cast<std::wstring_view
>(*this).contains(ch);
405 inline Size find(std::wstring_view text,
Size pos = {})
const noexcept {
406 return FindAt(
static_cast<std::wstring_view
>(*
this), text, pos);
416 return FindAt(
static_cast<std::wstring_view
>(*
this), ch, pos);
427 return find(std::wstring_view(text,
static_cast<std::size_t
>(count)), pos);
437 return RFindAt(
static_cast<std::wstring_view
>(*
this), text, pos);
447 return RFindAt(
static_cast<std::wstring_view
>(*
this), ch, pos);
458 return rfind(std::wstring_view(text,
static_cast<std::size_t
>(count)), pos);
468 const std::wstring_view self = *
this;
469 if (pos >
Size{self.size()})
471 return FromIndex(self.find_first_of(text,
static_cast<std::size_t
>(pos)));
481 return find(ch, pos);
491 const std::wstring_view self = *
this;
492 const std::size_t start = pos == npos ? std::wstring_view::npos :
static_cast<std::size_t
>(pos);
493 return FromIndex(self.find_last_of(text, start));
503 return rfind(ch, pos);
513 const std::wstring_view self = *
this;
514 if (pos >
Size{self.size()})
516 return FromIndex(self.find_first_not_of(text,
static_cast<std::size_t
>(pos)));
526 const std::wstring_view self = *
this;
527 if (pos >
Size{self.size()})
529 return FromIndex(self.find_first_not_of(ch,
static_cast<std::size_t
>(pos)));
539 const std::wstring_view self = *
this;
540 const std::size_t start = pos == npos ? std::wstring_view::npos :
static_cast<std::size_t
>(pos);
541 return FromIndex(self.find_last_not_of(text, start));
551 const std::wstring_view self = *
this;
552 const std::size_t start = pos == npos ? std::wstring_view::npos :
static_cast<std::size_t
>(pos);
553 return FromIndex(self.find_last_not_of(ch, start));
563 const std::wstring_view text = *
this;
564 if (pos >
Size{text.size()})
566 const std::size_t n = count == npos ? std::wstring_view::npos :
static_cast<std::size_t
>(count);
567 return WString(text.substr(
static_cast<std::size_t
>(pos), n));
575 inline int compare(std::wstring_view text)
const noexcept {
576 return static_cast<std::wstring_view
>(*this).compare(text);
584 inline wchar_t front() const noexcept {
585 return (*
this)[
Size{0}];
593 inline wchar_t back() const noexcept {
594 return (*
this)[size() -
Size{1}];
648 while (i < str.size()) {
649 while (i < str.size() && std::iswspace(
static_cast<wint_t
>(str[i])) != 0)
654 while (j < str.size() && std::iswspace(
static_cast<wint_t
>(str[j])) == 0)
656 out.emplace_back(str.substr(i, j - i));
671 std::size_t start = 0;
672 for (std::size_t i = 0; i <= str.size(); ++i) {
673 if (i == str.size() || str[i] == delimiter) {
674 out.emplace(str.substr(start, i - start));
685 return ToLower(
static_cast<std::wstring_view
>(*
this));
693 return ToUpper(
static_cast<std::wstring_view
>(*
this));
701 return SanitizeNewlines(
static_cast<std::wstring_view
>(*
this));
709 return RemoveWhitespace(
static_cast<std::wstring_view
>(*
this));
717 return IsInteger(
static_cast<std::wstring_view
>(*
this));
725 std::vector<WString> out;
726 Split(
static_cast<std::wstring_view
>(*
this), out);
736 std::queue<WString> out;
737 Explode(
static_cast<std::wstring_view
>(*
this), delimiter, out);
754 return m_text == other.m_text;
763 return !(*
this == other);
772 return m_text == str;
781 return !(*
this == str);
790 return m_text <=> other.m_text;
798 inline std::strong_ordering
operator<=>(
const wchar_t* str)
const noexcept {
799 return m_text <=> str;
811 static Size FromIndex(std::size_t index)
noexcept {
812 return index == std::wstring_view::npos ? npos :
Size{index};
815 template<
typename Needle>
816 static Size FindAt(std::wstring_view self, Needle needle,
Size pos)
noexcept {
817 if (pos >
Size{self.size()})
819 return FromIndex(self.find(needle,
static_cast<std::size_t
>(pos)));
822 template<
typename Needle>
823 static Size RFindAt(std::wstring_view self, Needle needle, Size pos)
noexcept {
824 const std::size_t start = pos == npos ? std::wstring_view::npos :
static_cast<std::size_t
>(pos);
825 return FromIndex(self.rfind(needle, start));
838 return stream << text.
Bytes();
883 return std::hash<std::wstring_view>{}(
static_cast<std::wstring_view
>(text));
Wide counterpart of String.
Definition wstring.hxx:96
STORMBYTE_FORCE_INLINE std::queue< WString > Explode(wchar_t delimiter) const noexcept
Tokens on delimiter.
Definition wstring.hxx:735
Size find(std::wstring_view text, Size pos={}) const noexcept
First occurrence of text at or after pos.
Definition wstring.hxx:405
const_reverse_iterator rbegin() const noexcept
Reverse begin.
Definition wstring.hxx:211
const_iterator cend() const noexcept
One past the last character, or null.
Definition wstring.hxx:203
int compare(std::wstring_view text) const noexcept
Same order as std::wstring_view::compare.
Definition wstring.hxx:575
bool contains(std::wstring_view text) const noexcept
Whether text occurs.
Definition wstring.hxx:386
Size find_last_not_of(std::wstring_view text, Size pos=npos) const noexcept
Last unit that is not in text, at or before pos.
Definition wstring.hxx:538
const wchar_t * data() const noexcept
Contiguous pointer; null when the buffer is null.
Definition wstring.hxx:243
WString ToUpper() const noexcept
ASCII-letter upper case of this text.
Definition wstring.hxx:692
Size find_first_not_of(std::wstring_view text, Size pos={}) const noexcept
First unit that is not in text, at or after pos.
Definition wstring.hxx:512
std::strong_ordering operator<=>(const WString &other) const noexcept
Content order.
Definition wstring.hxx:789
WString ToLower() const noexcept
ASCII-letter lower case of this text.
Definition wstring.hxx:684
static bool IsInteger(std::wstring_view str) noexcept
Optional sign plus ASCII digits.
bool operator!=(const WString &other) const noexcept
Content inequality.
Definition wstring.hxx:762
bool operator==(const wchar_t *str) const noexcept
Content equality with a wide C string.
Definition wstring.hxx:771
bool operator!=(const wchar_t *str) const noexcept
Content inequality with a wide C string.
Definition wstring.hxx:780
const_reverse_iterator rend() const noexcept
Reverse end.
Definition wstring.hxx:219
bool contains(wchar_t ch) const noexcept
Whether ch occurs.
Definition wstring.hxx:395
WString substr(Size pos={}, Size count=npos) const noexcept
Copy of a slice.
Definition wstring.hxx:562
std::strong_ordering operator<=>(const wchar_t *str) const noexcept
Content order against a wide C string.
Definition wstring.hxx:798
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse observer.
Definition wstring.hxx:100
WString SanitizeNewlines() const noexcept
CR LF to LF on this text.
Definition wstring.hxx:700
bool empty() const noexcept
Whether size is zero.
Definition wstring.hxx:267
Size find(const wchar_t *text, Size pos, Size count) const noexcept
First occurrence of count units of text.
Definition wstring.hxx:426
bool operator==(const WString &other) const noexcept
Content equality.
Definition wstring.hxx:753
static WString ToLower(std::wstring_view str) noexcept
ASCII-letter lower case; other code points copied.
void swap(WString &other) noexcept
Swaps buffers with other.
static STORMBYTE_FORCE_INLINE void Explode(std::wstring_view str, wchar_t delimiter, std::queue< WString > &out) noexcept
Tokens on delimiter.
Definition wstring.hxx:668
STORMBYTE_FORCE_INLINE std::vector< WString > Split() const noexcept
Whitespace-separated tokens.
Definition wstring.hxx:724
const wchar_t * const_iterator
Contiguous observer.
Definition wstring.hxx:99
wchar_t back() const noexcept
Last code unit.
Definition wstring.hxx:593
wchar_t operator[](const Size &index) const noexcept
Code unit at index.
Definition wstring.hxx:277
const_reverse_iterator crbegin() const noexcept
Reverse begin.
Definition wstring.hxx:227
Size find_first_of(std::wstring_view text, Size pos={}) const noexcept
First unit that is in text, at or after pos.
Definition wstring.hxx:467
static WString SanitizeNewlines(std::wstring_view str) noexcept
Turns CR LF into LF.
Size find(wchar_t ch, Size pos={}) const noexcept
First occurrence of ch at or after pos.
Definition wstring.hxx:415
Size find_last_not_of(wchar_t ch, Size pos=npos) const noexcept
Last unit other than ch, at or before pos.
Definition wstring.hxx:550
Size find_last_of(std::wstring_view text, Size pos=npos) const noexcept
Last unit that is in text, at or before pos.
Definition wstring.hxx:490
bool starts_with(std::wstring_view text) const noexcept
Whether the text begins with text.
Definition wstring.hxx:350
static WString RemoveWhitespace(std::wstring_view str) noexcept
Drops iswspace code units.
const WCString & Bytes() const noexcept
Owned code units.
Definition wstring.hxx:332
wchar_t front() const noexcept
First code unit.
Definition wstring.hxx:584
WString RemoveWhitespace() const noexcept
Drops iswspace code units from this text.
Definition wstring.hxx:708
const_reverse_iterator crend() const noexcept
Reverse end.
Definition wstring.hxx:235
Size rfind(const wchar_t *text, Size pos, Size count) const noexcept
Last occurrence of count units of text.
Definition wstring.hxx:457
static WString ToUpper(std::wstring_view str) noexcept
ASCII-letter upper case; other code points copied.
const_iterator cbegin() const noexcept
First character, or null.
Definition wstring.hxx:195
Size rfind(std::wstring_view text, Size pos=npos) const noexcept
Last occurrence of text at or before pos.
Definition wstring.hxx:436
Size find_first_not_of(wchar_t ch, Size pos={}) const noexcept
First unit other than ch, at or after pos.
Definition wstring.hxx:525
bool starts_with(wchar_t ch) const noexcept
Whether the text begins with ch.
Definition wstring.hxx:359
Size size() const noexcept
Code-unit count; 0 when null or empty.
Definition wstring.hxx:251
static STORMBYTE_FORCE_INLINE void Split(std::wstring_view str, std::vector< WString > &out) noexcept
Whitespace-separated tokens.
Definition wstring.hxx:645
bool IsInteger() const noexcept
Whether this text is an integer token.
Definition wstring.hxx:716
Size rfind(wchar_t ch, Size pos=npos) const noexcept
Last occurrence of ch at or before pos.
Definition wstring.hxx:446
bool ends_with(wchar_t ch) const noexcept
Whether the text ends with ch.
Definition wstring.hxx:377
Size find_first_of(wchar_t ch, Size pos={}) const noexcept
First ch at or after pos.
Definition wstring.hxx:480
wchar_t value_type
Code unit type.
Definition wstring.hxx:98
Size length() const noexcept
Same as size.
Definition wstring.hxx:259
WString() noexcept
Null text.
const_iterator end() const noexcept
One past the last character, or null.
Definition wstring.hxx:186
Size find_last_of(wchar_t ch, Size pos=npos) const noexcept
Last ch at or before pos.
Definition wstring.hxx:502
bool ends_with(std::wstring_view text) const noexcept
Whether the text ends with text.
Definition wstring.hxx:368
void swap(WCString &other) noexcept
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::WString &text) const noexcept
Hashes text.
Definition wstring.hxx:882
#define STORMBYTE_STRING_PUBLIC
Definition visibility.h:53