StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
wstring.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This is the base for StormByte Suite libraries.
5 *
6 * StormByte original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte source in this repository.
20 * They do not cover other StormByte modules or any third-party material
21 * shipped with this repository (including everything under thirdparty/),
22 * which remains under its own license.
23 *
24 * Neither license grants any patent rights. Any patent licenses required
25 * to use this software or third-party components must be obtained separately
26 * from the patent holders.
27 *
28 * StormByte is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
32 *
33 * You should have received a copy of the GNU Lesser General Public License
34 * version 3 along with StormByte. If not, see
35 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
36 *
37 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
38 */
39
40#pragma once
41
44#include <StormByte/size.hxx>
49
50#if __has_include(<fmt/xchar.h>)
51#include <fmt/xchar.h>
52#endif
53
54#include <cassert>
55#include <compare>
56#include <cstddef>
57#include <cstdint>
58#include <cwctype>
59#include <format>
60#include <functional>
61#include <initializer_list>
62#include <iterator>
63#include <ostream>
64#include <ranges>
65#include <span>
66#include <string>
67#include <string_view>
68#include <type_traits>
69#include <utility>
70#include <vector>
71
76namespace StormByte {
81 namespace Safe {
105 public:
106 using value_type = wchar_t;
107 using size_type = Size;
108 using difference_type = std::ptrdiff_t;
109 using pointer = wchar_t*;
110 using const_pointer = const wchar_t*;
111 using reference = wchar_t&;
112 using const_reference = const wchar_t&;
113 using iterator = wchar_t*;
114 using const_iterator = const wchar_t*;
115 using reverse_iterator = std::reverse_iterator<iterator>;
116 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
117
118 static constexpr std::size_t SSO_CAPACITY = 11;
119
124
128 WString() noexcept;
129
134 WString(const wchar_t* str);
135
141
148 WString(size_type count, wchar_t character);
149
158 WString(const WString& other, size_type pos, size_type count = npos);
159
167 template<std::input_iterator InputIt>
168 WString(InputIt first, InputIt last): WString() {
169 append(first, last);
170 }
171
176 explicit WString(const String& other);
177
182 WString(const WString& other);
183
188 WString(WString&& other) noexcept;
189
193 ~WString() noexcept;
194
200 WString& operator=(const WString& other);
201
207 WString& operator=(WString&& other) noexcept;
208
214 WString& operator=(std::wstring_view text);
215
217
222
227 inline iterator begin() noexcept {
228 return data();
229 }
230
235 inline const_iterator begin() const noexcept {
236 return data();
237 }
238
243 inline iterator end() noexcept {
244 return data() + static_cast<std::size_t>(size());
245 }
246
251 inline const_iterator end() const noexcept {
252 return data() + static_cast<std::size_t>(size());
253 }
254
259 inline const_iterator cbegin() const noexcept {
260 return begin();
261 }
262
267 inline const_iterator cend() const noexcept {
268 return end();
269 }
270
275 inline reverse_iterator rbegin() noexcept {
276 return reverse_iterator(end());
277 }
278
283 inline const_reverse_iterator rbegin() const noexcept {
284 return const_reverse_iterator(end());
285 }
286
291 inline reverse_iterator rend() noexcept {
292 return reverse_iterator(begin());
293 }
294
299 inline const_reverse_iterator rend() const noexcept {
301 }
302
307 inline const_reverse_iterator crbegin() const noexcept {
308 return rbegin();
309 }
310
315 inline const_reverse_iterator crend() const noexcept {
316 return rend();
317 }
318
323 wchar_t* data() noexcept;
324
329 const wchar_t* data() const noexcept;
330
335 inline const wchar_t* c_str() const noexcept {
336 return data();
337 }
338
343 Size size() const noexcept;
344
349 Size capacity() const noexcept;
350
355 Size max_size() const noexcept;
356
361 inline Size length() const noexcept {
362 return size();
363 }
364
369 inline bool empty() const noexcept {
370 return size() == 0;
371 }
372
378 WString& append(std::wstring_view text);
379
386 WString& append(size_type count, wchar_t character);
387
396 template<std::input_iterator InputIt>
397 WString& append(InputIt first, InputIt last) {
398 for (; first != last; ++first)
399 push_back(static_cast<wchar_t>(*first));
400 return *this;
401 }
402
410 template<std::ranges::input_range R>
411 WString& append_range(R&& range) {
412 return append(std::ranges::begin(range), std::ranges::end(range));
413 }
414
420 WString& assign(std::wstring_view text);
421
428 WString& assign(size_type count, wchar_t character);
429
438 template<std::input_iterator InputIt>
439 WString& assign(InputIt first, InputIt last) {
440 clear();
441 return append(first, last);
442 }
443
451 template<std::ranges::input_range R>
452 WString& assign_range(R&& range) {
453 return assign(std::ranges::begin(range), std::ranges::end(range));
454 }
455
461 WString& operator+=(std::wstring_view text);
462
468 WString& operator+=(wchar_t character);
469
474 void push_back(wchar_t character);
475
479 void pop_back();
480
484 void clear();
485
493 void reserve(size_type new_capacity);
494
499
505 void resize(size_type count, wchar_t character = wchar_t{});
506
513 WString& insert(size_type position, std::wstring_view text);
514
524 WString& insert(size_type position, size_type count, wchar_t character);
525
536 template<std::input_iterator InputIt>
537 iterator insert(const_iterator pos, InputIt first, InputIt last) {
538 const Size index{static_cast<std::size_t>(pos - cbegin())};
539 WString copied;
540 copied.append(first, last);
541 insert(index, static_cast<std::wstring_view>(copied));
542 return begin() + static_cast<std::size_t>(index);
543 }
544
553 iterator insert(const_iterator pos, std::initializer_list<wchar_t> values);
554
564 template<std::ranges::input_range R>
566 return insert(pos, std::ranges::begin(range), std::ranges::end(range));
567 }
568
575 WString& erase(size_type position = {}, size_type count = npos);
576
584
593
601 WString& replace(size_type position, size_type count, std::wstring_view text);
602
612 WString& replace(const_iterator first, const_iterator last, std::wstring_view text);
622 template<class... Args>
623 requires (sizeof...(Args) >= 1)
624 static WString ReplaceToken(std::wstring_view text, Args&&... args) {
625 constexpr std::size_t count = sizeof...(Args);
626 ReplaceTokenPlace<wchar_t> places[count];
627 const std::size_t found = FindReplaceTokens(text, places, count);
628 std::wstring scratch[count];
629 std::wstring_view tokens[count];
630 std::size_t offsets[count];
631 std::size_t lengths[count];
632 std::size_t index = 0;
633 auto store = [&](auto&& value) {
634 if (index >= found)
635 return;
636 using Bare = std::remove_cvref_t<decltype(value)>;
637 if (!FormatReplaceToken<wchar_t>(scratch[index], std::forward<decltype(value)>(value), places[index].spec)) {
639 scratch[index] = static_cast<std::wstring>(std::forward<decltype(value)>(value));
641 const WString owned(static_cast<WString>(std::forward<decltype(value)>(value)));
642 scratch[index].assign(static_cast<std::wstring_view>(owned));
643 } else if constexpr (!ReplaceTokenBuiltin<wchar_t, Bare>)
644 static_assert(sizeof(Bare) == 0, "ReplaceToken argument must be text, a number, a pointer, or convertible to std::wstring");
645 }
646 tokens[index] = scratch[index];
647 offsets[index] = places[index].offset;
648 lengths[index] = places[index].length;
649 ++index;
650 };
651 (store(std::forward<Args>(args)), ...);
652 return ReplaceTokens(text, std::span<const std::wstring_view>(tokens, found), std::span<const std::size_t>(offsets, found), std::span<const std::size_t>(lengths, found));
653 }
654
661 inline wchar_t& operator[](const Size& index) noexcept {
662 assert(index <= size());
663 return data()[static_cast<std::size_t>(index)];
664 }
665
672 inline wchar_t operator[](const Size& index) const noexcept {
673 assert(index <= size());
674 return data()[static_cast<std::size_t>(index)];
675 }
676
683 wchar_t& at(size_type index);
684
691 const wchar_t& at(size_type index) const;
692
701 size_type copy(wchar_t* dest, size_type count, size_type pos = {}) const;
702
707 inline explicit operator bool() const noexcept {
708 return !empty();
709 }
710
712
717
723 inline operator std::wstring_view() const noexcept {
724 return std::wstring_view(data(), static_cast<std::size_t>(size()));
725 }
726
731 STORMBYTE_FORCE_INLINE explicit operator std::wstring() const {
732 return std::wstring(static_cast<std::wstring_view>(*this));
733 }
734
740 inline explicit operator const wchar_t*() const noexcept {
741 return c_str();
742 }
743
748 explicit operator String() const;
749
754 inline const wchar_t* Bytes() const noexcept {
755 return data();
756 }
757
759
764
765 static constexpr size_type npos{~0ull};
766
772 inline bool starts_with(std::wstring_view text) const noexcept {
773 return static_cast<std::wstring_view>(*this).starts_with(text);
774 }
775
781 inline bool starts_with(wchar_t ch) const noexcept {
782 return static_cast<std::wstring_view>(*this).starts_with(ch);
783 }
784
790 inline bool ends_with(std::wstring_view text) const noexcept {
791 return static_cast<std::wstring_view>(*this).ends_with(text);
792 }
793
799 inline bool ends_with(wchar_t ch) const noexcept {
800 return static_cast<std::wstring_view>(*this).ends_with(ch);
801 }
802
808 inline bool contains(std::wstring_view text) const noexcept {
809 return static_cast<std::wstring_view>(*this).contains(text);
810 }
811
817 inline bool contains(wchar_t ch) const noexcept {
818 return static_cast<std::wstring_view>(*this).contains(ch);
819 }
820
827 inline Size find(std::wstring_view text, Size pos = {}) const noexcept {
828 return FindAt(static_cast<std::wstring_view>(*this), text, pos);
829 }
830
837 inline Size find(wchar_t ch, Size pos = {}) const noexcept {
838 return FindAt(static_cast<std::wstring_view>(*this), ch, pos);
839 }
840
848 inline Size find(const wchar_t* text, Size pos, Size count) const noexcept {
849 return find(std::wstring_view(text, static_cast<std::size_t>(count)), pos);
850 }
851
858 inline Size rfind(std::wstring_view text, Size pos = npos) const noexcept {
859 return RFindAt(static_cast<std::wstring_view>(*this), text, pos);
860 }
861
868 inline Size rfind(wchar_t ch, Size pos = npos) const noexcept {
869 return RFindAt(static_cast<std::wstring_view>(*this), ch, pos);
870 }
871
879 inline Size rfind(const wchar_t* text, Size pos, Size count) const noexcept {
880 return rfind(std::wstring_view(text, static_cast<std::size_t>(count)), pos);
881 }
882
889 inline Size find_first_of(std::wstring_view text, Size pos = {}) const noexcept {
890 const std::wstring_view self = *this;
891 if (pos > Size{self.size()})
892 return npos;
893 return FromIndex(self.find_first_of(text, static_cast<std::size_t>(pos)));
894 }
895
902 inline Size find_first_of(wchar_t ch, Size pos = {}) const noexcept {
903 return find(ch, pos);
904 }
905
912 inline Size find_last_of(std::wstring_view text, Size pos = npos) const noexcept {
913 const std::wstring_view self = *this;
914 const std::size_t start = pos == npos ? std::wstring_view::npos : static_cast<std::size_t>(pos);
915 return FromIndex(self.find_last_of(text, start));
916 }
917
924 inline Size find_last_of(wchar_t ch, Size pos = npos) const noexcept {
925 return rfind(ch, pos);
926 }
927
934 inline Size find_first_not_of(std::wstring_view text, Size pos = {}) const noexcept {
935 const std::wstring_view self = *this;
936 if (pos > Size{self.size()})
937 return npos;
938 return FromIndex(self.find_first_not_of(text, static_cast<std::size_t>(pos)));
939 }
940
947 inline Size find_first_not_of(wchar_t ch, Size pos = {}) const noexcept {
948 const std::wstring_view self = *this;
949 if (pos > Size{self.size()})
950 return npos;
951 return FromIndex(self.find_first_not_of(ch, static_cast<std::size_t>(pos)));
952 }
953
960 inline Size find_last_not_of(std::wstring_view text, Size pos = npos) const noexcept {
961 const std::wstring_view self = *this;
962 const std::size_t start = pos == npos ? std::wstring_view::npos : static_cast<std::size_t>(pos);
963 return FromIndex(self.find_last_not_of(text, start));
964 }
965
972 inline Size find_last_not_of(wchar_t ch, Size pos = npos) const noexcept {
973 const std::wstring_view self = *this;
974 const std::size_t start = pos == npos ? std::wstring_view::npos : static_cast<std::size_t>(pos);
975 return FromIndex(self.find_last_not_of(ch, start));
976 }
977
984 inline WString substr(Size pos = {}, Size count = npos) const noexcept {
985 const std::wstring_view text = *this;
986 if (pos > Size{text.size()})
987 return WString();
988 const std::size_t n = count == npos ? std::wstring_view::npos : static_cast<std::size_t>(count);
989 return WString(text.substr(static_cast<std::size_t>(pos), n));
990 }
991
997 inline int compare(std::wstring_view text) const noexcept {
998 return static_cast<std::wstring_view>(*this).compare(text);
999 }
1000
1008 inline int compare(size_type pos, size_type count, std::wstring_view text) const noexcept {
1009 return static_cast<std::wstring_view>(substr(pos, count)).compare(text);
1010 }
1011
1017 inline wchar_t& front() noexcept {
1018 return (*this)[Size{0}];
1019 }
1020
1026 inline wchar_t front() const noexcept {
1027 return (*this)[Size{0}];
1028 }
1029
1035 inline wchar_t& back() noexcept {
1036 return (*this)[size() - Size{1}];
1037 }
1038
1044 inline wchar_t back() const noexcept {
1045 return (*this)[size() - Size{1}];
1046 }
1047
1049
1054
1060 static WString ToLower(std::wstring_view str);
1061
1067 static WString ToUpper(std::wstring_view str);
1068
1074 static WString SanitizeNewlines(std::wstring_view str);
1075
1081 static WString RemoveWhitespace(std::wstring_view str);
1082
1088 static bool IsInteger(std::wstring_view str) noexcept;
1089
1095 static Vector<WString> Split(std::wstring_view str);
1096
1102 static inline Vector<WString> Split(const std::vector<WString>& parts) {
1103 Vector<WString> result;
1104 for (const WString& part : parts)
1105 result.push_back(part);
1106 return result;
1107 }
1108
1115 static Queue<WString> Explode(std::wstring_view str, wchar_t delimiter);
1116
1117
1124 static WString Implode(const Vector<WString>& parts, std::wstring_view delimiter);
1125
1132 static WString Implode(const Queue<WString>& parts, std::wstring_view delimiter);
1133
1138 inline WString ToLower() const {
1139 return ToLower(static_cast<std::wstring_view>(*this));
1140 }
1141
1146 inline WString ToUpper() const {
1147 return ToUpper(static_cast<std::wstring_view>(*this));
1148 }
1149
1154 inline WString SanitizeNewlines() const {
1155 return SanitizeNewlines(static_cast<std::wstring_view>(*this));
1156 }
1157
1162 inline WString RemoveWhitespace() const {
1163 return RemoveWhitespace(static_cast<std::wstring_view>(*this));
1164 }
1165
1170 inline bool IsInteger() const noexcept {
1171 return IsInteger(static_cast<std::wstring_view>(*this));
1172 }
1173
1179
1185 Queue<WString> Explode(wchar_t delimiter) const;
1186
1188
1193
1199 inline bool operator==(const WString& other) const noexcept {
1200 return static_cast<std::wstring_view>(*this) == static_cast<std::wstring_view>(other);
1201 }
1202
1208 inline bool operator!=(const WString& other) const noexcept {
1209 return !(*this == other);
1210 }
1211
1217 inline bool operator==(const wchar_t* str) const noexcept {
1218 return str ? static_cast<std::wstring_view>(*this) == std::wstring_view(str) : empty();
1219 }
1220
1226 inline bool operator!=(const wchar_t* str) const noexcept {
1227 return !(*this == str);
1228 }
1229
1235 STORMBYTE_FORCE_INLINE std::strong_ordering operator<=>(const WString& other) const noexcept {
1236 return static_cast<std::wstring_view>(*this) <=> static_cast<std::wstring_view>(other);
1237 }
1238
1244 STORMBYTE_FORCE_INLINE std::strong_ordering operator<=>(const wchar_t* str) const noexcept {
1245 return str ? static_cast<std::wstring_view>(*this) <=> std::wstring_view(str)
1246 : static_cast<std::wstring_view>(*this) <=> std::wstring_view{};
1247 }
1248
1250
1255 void swap(WString& other) noexcept;
1256
1257 private:
1264 struct alignas(16) Storage {
1265 union {
1266 wchar_t data[SSO_CAPACITY + 1];
1267 void* long_;
1268 };
1269 std::uint8_t m_tag;
1270 };
1271
1272 static_assert(sizeof(Storage) >= SSO_CAPACITY * sizeof(wchar_t));
1273 static_assert(sizeof(Storage) % alignof(void*) == 0);
1274 static_assert(alignof(Storage) == 16);
1275
1280 bool IsLong() const noexcept;
1281
1285 void ReleaseLong() noexcept;
1286
1290 void SetEmpty() noexcept;
1291
1297 void SetShort(const wchar_t* text, std::size_t count) noexcept;
1298
1304 static Size FromIndex(std::size_t index) noexcept {
1305 return index == std::wstring_view::npos ? npos : Size{index};
1306 }
1307
1316 template<typename Needle>
1317 static Size FindAt(std::wstring_view self, Needle needle, Size pos) noexcept {
1318 if (pos > Size{self.size()})
1319 return npos;
1320 return FromIndex(self.find(needle, static_cast<std::size_t>(pos)));
1321 }
1322
1331 template<typename Needle>
1332 static Size RFindAt(std::wstring_view self, Needle needle, Size pos) noexcept {
1333 const std::size_t start = pos == npos ? std::wstring_view::npos : static_cast<std::size_t>(pos);
1334 return FromIndex(self.rfind(needle, start));
1335 }
1336
1337
1347 static WString ReplaceTokens(std::wstring_view text, std::span<const std::wstring_view> tokens, std::span<const std::size_t> offsets, std::span<const std::size_t> lengths);
1348 Storage m_storage{};
1349 };
1350
1357 STORMBYTE_FORCE_INLINE std::wostream& operator<<(std::wostream& stream, const WString& text) {
1358 return stream << static_cast<std::wstring_view>(text);
1359 }
1360
1367 inline bool operator==(const wchar_t* str, const WString& text) noexcept {
1368 return text == str;
1369 }
1370
1377 inline bool operator!=(const wchar_t* str, const WString& text) noexcept {
1378 return text != str;
1379 }
1380
1388 inline WString operator+(const WString& left, const WString& right) {
1389 WString result(left);
1390 result += right;
1391 return result;
1392 }
1393
1399 inline void swap(WString& left, WString& right) noexcept {
1400 left.swap(right);
1401 }
1402 }
1403}
1404
1405template<>
1412 STORMBYTE_FORCE_INLINE std::size_t operator()(const StormByte::Safe::WString& text) const noexcept {
1413 const std::wstring_view view = text;
1414 return HashBytes(std::as_bytes(std::span<const wchar_t>(view.data(), view.size())));
1415 }
1416};
1417
1421template<>
1422struct std::formatter<StormByte::Safe::WString, wchar_t>: std::formatter<std::wstring_view, wchar_t> {
1431 template<typename FormatContext>
1432 STORMBYTE_FORCE_INLINE auto format(const StormByte::Safe::WString& text, FormatContext& context) const {
1433 const std::wstring_view view = text;
1434 return std::formatter<std::wstring_view, wchar_t>::format(view, context);
1435 }
1436};
1437
1438#if __has_include(<fmt/xchar.h>)
1442template<>
1443struct fmt::formatter<StormByte::Safe::WString, wchar_t>: fmt::formatter<std::wstring_view, wchar_t> {
1452 template<typename FormatContext>
1453 STORMBYTE_FORCE_INLINE auto format(const StormByte::Safe::WString& text, FormatContext& context) const {
1454 const std::wstring_view view = text;
1455 return fmt::formatter<std::wstring_view, wchar_t>::format(view, context);
1456 }
1457};
1458#endif
1459
1460template<>
1461struct std::hash<StormByte::Safe::WString> {
1467 std::size_t operator()(const StormByte::Safe::WString& text) const noexcept {
1469 }
1470};
FIFO sequence stored on Base's heap.
Definition queue.hxx:77
Owned UTF-8 text.
Definition string.hxx:113
Contiguous sequence stored on Base's heap.
Definition vector.hxx:81
void push_back(const T &value)
Append a copy.
Wide counterpart of String.
Definition wstring.hxx:104
static WString RemoveWhitespace(std::wstring_view str)
Drops wide space units.
WString & operator+=(wchar_t character)
Append one wide code unit.
const_reverse_iterator rend() const noexcept
Reverse end.
Definition wstring.hxx:299
void resize(size_type count, wchar_t character=wchar_t{})
Resize the unit sequence, filling new units with character.
Size capacity() const noexcept
Allocated unit capacity, excluding the trailing NUL.
Size max_size() const noexcept
Largest representable unit count.
wchar_t & front() noexcept
First unit.
Definition wstring.hxx:1017
static Queue< WString > Explode(std::wstring_view str, wchar_t delimiter)
Tokens on delimiter, including empty ones.
void shrink_to_fit()
Drop unused long-path capacity.
void clear()
Replace the contents with an empty string, retaining long-path capacity.
reverse_iterator rend() noexcept
Reverse end.
Definition wstring.hxx:291
int compare(std::wstring_view text) const noexcept
Same order as std::wstring_view::compare.
Definition wstring.hxx:997
wchar_t & operator[](const Size &index) noexcept
Code unit at index.
Definition wstring.hxx:661
bool empty() const noexcept
Whether Size is zero.
Definition wstring.hxx:369
std::ptrdiff_t difference_type
Iterator distance type.
Definition wstring.hxx:108
Size find_first_of(wchar_t ch, Size pos={}) const noexcept
First ch at or after pos.
Definition wstring.hxx:902
const wchar_t * Bytes() const noexcept
Non-owning view of the owned units.
Definition wstring.hxx:754
static constexpr size_type npos
Not found.
Definition wstring.hxx:765
bool operator!=(const WString &other) const noexcept
Content inequality.
Definition wstring.hxx:1208
const_iterator begin() const noexcept
First unit.
Definition wstring.hxx:235
const_reverse_iterator crend() const noexcept
Reverse end.
Definition wstring.hxx:315
Size find(std::wstring_view text, Size pos={}) const noexcept
First occurrence of text at or after pos.
Definition wstring.hxx:827
wchar_t front() const noexcept
Read the first unit.
Definition wstring.hxx:1026
bool operator==(const wchar_t *str) const noexcept
Content equality with a wide C string.
Definition wstring.hxx:1217
const wchar_t * c_str() const noexcept
Same pointer as data.
Definition wstring.hxx:335
WString substr(Size pos={}, Size count=npos) const noexcept
Copy of a slice.
Definition wstring.hxx:984
iterator end() noexcept
One past the last unit.
Definition wstring.hxx:243
iterator erase(const_iterator first, const_iterator last)
Erase [first, last).
STORMBYTE_FORCE_INLINE std::strong_ordering operator<=>(const wchar_t *str) const noexcept
Content order against a wide C string.
Definition wstring.hxx:1244
bool contains(wchar_t ch) const noexcept
Whether ch occurs.
Definition wstring.hxx:817
Size find(const wchar_t *text, Size pos, Size count) const noexcept
First occurrence of count units of text.
Definition wstring.hxx:848
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:972
wchar_t & at(size_type index)
Unit at index.
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:960
WString & operator+=(std::wstring_view text)
Append a wide view.
WString() noexcept
Empty text.
WString SanitizeNewlines() const
CR LF to LF on this text.
Definition wstring.hxx:1154
WString & assign(size_type count, wchar_t character)
Replace the contents with count copies of a wide code unit.
iterator erase(const_iterator pos)
Erase the unit at pos.
wchar_t operator[](const Size &index) const noexcept
Read-only code unit at index.
Definition wstring.hxx:672
const wchar_t & at(size_type index) const
Read-only unit at index.
reverse_iterator rbegin() noexcept
Reverse begin.
Definition wstring.hxx:275
WString & assign(InputIt first, InputIt last)
Replace the contents with [first, last).
Definition wstring.hxx:439
wchar_t * pointer
Mutable buffer pointer.
Definition wstring.hxx:109
const wchar_t & const_reference
Read-only unit reference.
Definition wstring.hxx:112
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse observer.
Definition wstring.hxx:116
Size rfind(std::wstring_view text, Size pos=npos) const noexcept
Last occurrence of text at or before pos.
Definition wstring.hxx:858
WString ToLower() const
ASCII-letter lower case of this text.
Definition wstring.hxx:1138
WString & replace(size_type position, size_type count, std::wstring_view text)
Replace a wide code-unit range with text.
static WString Implode(const Queue< WString > &parts, std::wstring_view delimiter)
Join parts with delimiter, in queue order.
WString & append(InputIt first, InputIt last)
Append the unit range [first, last).
Definition wstring.hxx:397
Size find(wchar_t ch, Size pos={}) const noexcept
First occurrence of ch at or after pos.
Definition wstring.hxx:837
WString(WString &&other) noexcept
Move constructor.
wchar_t * iterator
Mutable contiguous iterator.
Definition wstring.hxx:113
wchar_t & reference
Mutable unit reference.
Definition wstring.hxx:111
void pop_back()
Remove the final code unit.
void reserve(size_type new_capacity)
Reserve storage for at least new_capacity code units.
WString & append(size_type count, wchar_t character)
Append count copies of a wide code unit.
static Vector< WString > Split(const std::vector< WString > &parts)
Copy caller-owned tokens into Base storage.
Definition wstring.hxx:1102
bool starts_with(std::wstring_view text) const noexcept
Whether the text begins with text.
Definition wstring.hxx:772
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:889
static WString ToUpper(std::wstring_view str)
ASCII-letter upper case; other units copied.
Size rfind(const wchar_t *text, Size pos, Size count) const noexcept
Last occurrence of count units of text.
Definition wstring.hxx:879
const wchar_t * const_pointer
Read-only buffer pointer.
Definition wstring.hxx:110
iterator insert(const_iterator pos, InputIt first, InputIt last)
Insert [first, last) before pos.
Definition wstring.hxx:537
WString & assign_range(R &&range)
Replace the contents with a copy of range.
Definition wstring.hxx:452
Size length() const noexcept
Same as Size.
Definition wstring.hxx:361
Vector< WString > Split() const
Whitespace-separated tokens of this text.
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:912
WString & assign(std::wstring_view text)
Replace the contents with a wide text view.
wchar_t value_type
Code unit type.
Definition wstring.hxx:106
const_reverse_iterator rbegin() const noexcept
Reverse begin.
Definition wstring.hxx:283
WString ToUpper() const
ASCII-letter upper case of this text.
Definition wstring.hxx:1146
bool ends_with(std::wstring_view text) const noexcept
Whether the text ends with text.
Definition wstring.hxx:790
int compare(size_type pos, size_type count, std::wstring_view text) const noexcept
Compare a slice with text.
Definition wstring.hxx:1008
~WString() noexcept
Releases a long buffer.
bool starts_with(wchar_t ch) const noexcept
Whether the text begins with ch.
Definition wstring.hxx:781
static WString ToLower(std::wstring_view str)
ASCII-letter lower case; other units copied.
static bool IsInteger(std::wstring_view str) noexcept
Optional sign plus ASCII digits.
iterator begin() noexcept
First unit.
Definition wstring.hxx:227
bool ends_with(wchar_t ch) const noexcept
Whether the text ends with ch.
Definition wstring.hxx:799
WString & replace(const_iterator first, const_iterator last, std::wstring_view text)
Replace [first, last) with text.
Size find_first_not_of(wchar_t ch, Size pos={}) const noexcept
First unit other than ch, at or after pos.
Definition wstring.hxx:947
const_iterator cend() const noexcept
One past the last unit.
Definition wstring.hxx:267
const_iterator cbegin() const noexcept
First unit.
Definition wstring.hxx:259
bool operator!=(const wchar_t *str) const noexcept
Content inequality with a wide C string.
Definition wstring.hxx:1226
std::reverse_iterator< iterator > reverse_iterator
Mutable reverse observer.
Definition wstring.hxx:115
void swap(WString &other) noexcept
Swaps storage with other.
void push_back(wchar_t character)
Append one wide code unit.
static constexpr std::size_t SSO_CAPACITY
Short capacity, excluding the trailing NUL.
Definition wstring.hxx:118
WString & insert(size_type position, size_type count, wchar_t character)
Insert count copies of character at position.
WString(const String &other)
Wide text from UTF-8, including an empty source.
WString & append_range(R &&range)
Append a copy of range.
Definition wstring.hxx:411
wchar_t & back() noexcept
Last unit.
Definition wstring.hxx:1035
Size size_type
Unit count and position type.
Definition wstring.hxx:107
WString & erase(size_type position={}, size_type count=npos)
Erase wide code units starting at position.
Queue< WString > Explode(wchar_t delimiter) const
Tokens of this text on delimiter, including empty ones.
size_type copy(wchar_t *dest, size_type count, size_type pos={}) const
Copy at most count units into dest, starting at pos.
STORMBYTE_FORCE_INLINE std::strong_ordering operator<=>(const WString &other) const noexcept
Content order.
Definition wstring.hxx:1235
wchar_t back() const noexcept
Read the last unit.
Definition wstring.hxx:1044
Size rfind(wchar_t ch, Size pos=npos) const noexcept
Last occurrence of ch at or before pos.
Definition wstring.hxx:868
iterator insert_range(const_iterator pos, R &&range)
Insert a copy of range before pos.
Definition wstring.hxx:565
const_iterator end() const noexcept
One past the last unit.
Definition wstring.hxx:251
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:934
const wchar_t * const_iterator
Contiguous observer.
Definition wstring.hxx:114
WString RemoveWhitespace() const
Drops wide space units from this text.
Definition wstring.hxx:1162
iterator insert(const_iterator pos, std::initializer_list< wchar_t > values)
Insert an initializer list before pos.
static WString Implode(const Vector< WString > &parts, std::wstring_view delimiter)
Join parts with delimiter.
wchar_t * data() noexcept
Contiguous pointer to the first unit, or to the trailing NUL when empty.
static WString SanitizeNewlines(std::wstring_view str)
Turns CR LF into LF.
const_reverse_iterator crbegin() const noexcept
Reverse begin.
Definition wstring.hxx:307
bool contains(std::wstring_view text) const noexcept
Whether text occurs.
Definition wstring.hxx:808
operator std::wstring_view() const noexcept
Non-owning view of the text.
Definition wstring.hxx:723
WString & insert(size_type position, std::wstring_view text)
Insert wide code units at a code-unit position.
static Vector< WString > Split(std::wstring_view str)
Whitespace-separated tokens.
WString(const WString &other)
Copy constructor.
bool operator==(const WString &other) const noexcept
Content equality.
Definition wstring.hxx:1199
Size size() const noexcept
Unit count, excluding the trailing NUL.
static WString ReplaceToken(std::wstring_view text, Args &&... args)
Copy text with each field replaced, in order, by one argument.
Definition wstring.hxx:624
Size find_last_of(wchar_t ch, Size pos=npos) const noexcept
Last ch at or before pos.
Definition wstring.hxx:924
WString & append(std::wstring_view text)
Append wide code units.
bool IsInteger() const noexcept
Whether this text is an integer token.
Definition wstring.hxx:1170
Count of abstract units (uint64_t storage).
Definition size.hxx:107
True when FormatReplaceToken always writes T and never asks for a string conversion.
Definition replace_token.hxx:258
From may be explicitly converted to To with static_cast.
Definition conversions.hxx:86
Owned values that cross a DLL without the caller's CRT.
bool FormatReplaceToken(std::basic_string< Char > &out, T &&value, const ReplaceTokenSpec &spec)
Render one argument when it does not need an owned-string conversion.
Definition replace_token.hxx:279
bool operator==(std::span< const std::byte > bytes, const Binary &data) noexcept
Equality of a span against a sequence.
Definition binary.hxx:770
STORMBYTE_FORCE_INLINE std::ostream & operator<<(std::ostream &stream, const String &text)
Writes text to stream.
Definition string.hxx:1365
std::size_t FindReplaceTokens(std::basic_string_view< Char > text, ReplaceTokenPlace< Char > *places, std::size_t capacity) noexcept
Collect up to capacity fields, in order.
Definition replace_token.hxx:155
bool operator!=(std::span< const std::byte > bytes, const Binary &data) noexcept
Inequality of a span against a sequence.
Definition binary.hxx:780
void swap(Binary &left, Binary &right) noexcept
Exchange two sequences.
Definition binary.hxx:760
String operator+(const String &left, const String &right)
Concatenate two texts.
Definition string.hxx:1396
STORMBYTE_FORCE_INLINE std::size_t HashBytes(std::span< const std::byte > bytes) noexcept
Mix a byte range with FNV-1a.
Definition hash.hxx:66
Root namespace of the StormByte suite.
STL namespace.
#define STORMBYTE_FORCE_INLINE
Definition platform.h:134
Host-width-stable count (uint64_t), implicit only to std::size_t.
STORMBYTE_FORCE_INLINE std::size_t operator()(const StormByte::Safe::WString &text) const noexcept
Hash text.
Definition wstring.hxx:1412
Cross-module hash.
Definition hash.hxx:95
Where a field sits in the pattern, and how to render its argument.
Definition replace_token.hxx:81
std::size_t offset
Definition replace_token.hxx:82
std::size_t length
Definition replace_token.hxx:83
STORMBYTE_FORCE_INLINE auto format(const StormByte::Safe::WString &text, FormatContext &context) const
Formats the borrowed view without copying the owned text.
Definition wstring.hxx:1432
std::size_t operator()(const StormByte::Safe::WString &text) const noexcept
Hashes text.
Definition wstring.hxx:1467
#define STORMBYTE_PUBLIC
Definition visibility.h:52