37class API_AUI_CORE AString: std::u16string
40 friend struct std::hash<AString>;
41 using super = std::u16string;
45 using iterator = super::iterator;
46 using value_type = super::value_type;
47 using const_iterator = super::const_iterator;
48 using reverse_iterator = super::reverse_iterator;
49 using const_reverse_iterator = super::const_reverse_iterator;
50 auto constexpr static NPOS = super::npos;
53 AString(AString&& other) noexcept
54 : std::u16string(
static_cast<basic_string&&
>(other))
61 AString(
const basic_string& other) noexcept
62 : basic_string<char16_t>(other)
69 AString(
const std::string& utf8)
noexcept;
71 AString(
const AString& other) noexcept
72 : super(other.c_str())
76 AString(
const basic_string& rhs,
const std::allocator<char16_t>& allocator) noexcept
77 : basic_string<char16_t>(rhs, allocator)
81 template <
class Iterator>
82 AString(Iterator first, Iterator last) noexcept : super(first, last) {}
88 AString(
char16_t c) noexcept : super(&c, &c + 1)
103 explicit AString(
const std::allocator<char16_t>& allocator) noexcept
104 : basic_string<char16_t>(allocator)
108 AString(
const basic_string& rhs, size_type offset,
const std::allocator<char16_t>& allocator) noexcept
109 : basic_string<char16_t>(rhs, offset, allocator)
113 AString(
const basic_string& rhs, size_type offset, size_type count,
const std::allocator<char16_t>& allocator) noexcept
114 : basic_string<char16_t>(rhs, offset, count, allocator)
118 AString(
const char16_t* cStyleString, size_type count) noexcept
119 : basic_string<char16_t>(cStyleString, count)
123 AString(
const char16_t* cStyleString, size_type count,
const std::allocator<char16_t>& allocator) noexcept
124 : basic_string<char16_t>(cStyleString, count, allocator)
128 AString(
const char16_t* cStyleString) noexcept
129 : basic_string<char16_t>(cStyleString)
133 AString(
const char16_t* cStyleString,
const std::allocator<char16_t>& allocator) noexcept
134 : basic_string<char16_t>(cStyleString, allocator)
138 AString(size_type count,
char16_t _Ch) noexcept
139 : basic_string<char16_t>(count, _Ch)
143 AString(size_type count,
char16_t _Ch,
const std::allocator<char16_t>& allocator) noexcept
144 : basic_string<char16_t>(count, _Ch, allocator)
148 AString(basic_string&& rhs) noexcept
149 : basic_string<char16_t>(std::move(rhs))
153 AString(basic_string&& rhs,
const std::allocator<char16_t>& allocator) noexcept
154 : basic_string<char16_t>(std::move(rhs), allocator)
158 AString(std::initializer_list<char16_t> _Ilist) noexcept
159 : basic_string<char16_t>(_Ilist)
163 ~AString() =
default;
166 void push_back(
char16_t c)
noexcept
170 void pop_back() noexcept
175 AString uppercase()
const;
176 AString lowercase()
const;
178 bool startsWith(
const AString& other)
const noexcept
180 return rfind(other, 0) == 0;
182 bool startsWith(
char16_t c)
const noexcept
184 return rfind(c, 0) == 0;
186 bool endsWith(
const AString& other)
const noexcept
188 if (length() < other.length())
192 size_t offset = length() - other.length();
193 return super::find(other, offset) == offset;
195 bool endsWith(
char16_t c)
const noexcept
197 size_t offset = length() - 1;
198 return super::find(c, offset) == offset;
201 AStringVector split(
char16_t c)
const noexcept;
203 size_type find(
char c, size_type offset = 0) const noexcept
205 return super::find(c, offset);
207 size_type find(
char16_t c, size_type offset = 0) const noexcept
209 return super::find(c, offset);
211 size_type find(
const AString& str, size_type offset = 0) const noexcept
213 return super::find(str, offset);
215 size_type rfind(
char c, size_type offset = NPOS)
const noexcept
217 return super::rfind(c, offset);
219 size_type rfind(
char16_t c, size_type offset = NPOS)
const noexcept
221 return super::rfind(c, offset);
223 size_type rfind(
const AString& str, size_type offset = NPOS)
const noexcept
225 return super::rfind(str, offset);
227 size_type length() const noexcept
229 return super::length();
231 AString trimLeft(
char16_t symbol =
' ') const noexcept;
232 AString trimRight(
char16_t symbol =
' ') const noexcept;
234 AString trim(
char16_t symbol =
' ') const noexcept
236 return trimRight(symbol).trimLeft(symbol);
239 void reserve(
size_t s)
243 void resize(
size_t s)
248 AString restrictLength(
size_t s,
const AString& stringAtEnd =
"...")
const;
250 char16_t* data() noexcept
252 return super::data();
255 const char16_t* data() const noexcept
257 return super::data();
259 AString& replaceAll(
const AString& from,
const AString& to);
260 [[nodiscard]] AString replacedAll(
const AString& from,
const AString& to)
const;
261 [[nodiscard]]
inline AString replacedAll(
char16_t from,
char16_t to)
const noexcept {
263 copy.reserve(length() + 10);
264 for (
auto c : *
this) {
273 [[nodiscard]]
inline AString replacedAll(
const ASet<char16_t>& from,
char16_t to)
const noexcept {
275 copy.reserve(length() + 10);
276 for (
auto c : *
this) {
277 if (from.contains(c)) {
285 AString& replaceAll(
char16_t from,
char16_t to)
noexcept;
293 template<
typename OtherContainer>
295 super::insert(super::end(), c.begin(), c.end());
346 return toInt().valueOrException(fmt::format(
"bad int: {}",
toStdString()).c_str());
368 return toLongInt().valueOrException(fmt::format(
"bad to number conversion: {}",
toStdString()).c_str());
390 return toUInt().valueOrException(fmt::format(
"bad to number conversion: {}",
toStdString()).c_str());
399 return *
this ==
"true";
403 bool contains(
char16_t c)
const noexcept
405 return find(c) != npos;
408 bool contains(
const AString& other)
const noexcept
410 return find(other) != npos;
413 static AString fromLatin1(
const AByteBuffer& buffer);
414 static AString fromUtf8(
const AByteBufferView& buffer);
415 static AString fromUtf8(
const char* buffer,
size_t length);
416 static AString fromLatin1(
const char* buffer);
418 static AString numberHex(
int i)
noexcept;
420 template<
typename T, std::enable_if_t<std::is_
integral_v<std::decay_t<T>> || std::is_
floating_po
int_v<std::decay_t<T>>,
int> = 0>
421 static AString number(T i)
noexcept {
422 if constexpr (std::is_same_v<bool, std::decay_t<T>>) {
427 auto v = std::to_string(i);
428 if constexpr (std::is_floating_point_v<T>) {
430 v.erase(v.find_last_not_of(
'0') + 1, std::u16string::npos);
431 v.erase(v.find_last_not_of(
'.') + 1, std::u16string::npos);
437 static constexpr auto TO_NUMBER_BASE_BIN = 2;
438 static constexpr auto TO_NUMBER_BASE_OCT = 8;
439 static constexpr auto TO_NUMBER_BASE_DEC = 10;
440 static constexpr auto TO_NUMBER_BASE_HEX = 16;
454 return toNumber(base).valueOrException(fmt::format(
"bad to number conversion: {}",
toStdString()).c_str());
463 void resizeToNullTerminator();
465 iterator erase(const_iterator begin, const_iterator end) noexcept
467 return super::erase(begin, end);
469 iterator erase(const_iterator begin)
noexcept
471 return super::erase(begin);
474 AString& erase(size_type offset)
noexcept
476 super::erase(offset);
479 AString& erase(size_type offset, size_type count)
noexcept
481 super::erase(offset, count);
485 AByteBuffer toUtf8() const noexcept;
487 void removeAt(
unsigned at) noexcept
492 AString excessSpacesRemoved() const noexcept;
494 iterator insert(size_type at,
char16_t c) noexcept
497 return super::insert(begin() + at, 1, c);
499 iterator insert(size_type at,
const AString& c)
noexcept
502 return super::insert(begin() + at,
c.begin(),
c.end());
505 template<
typename Iterator>
506 iterator insert(const_iterator at, Iterator begin, Iterator end)
noexcept
508 AUI_ASSERT(std::distance(super::cbegin(), at) <= length());
509 return super::insert(at, begin, end);
512 AString& operator<<(
char c)
noexcept
517 AString& operator<<(
char16_t c)
noexcept
523 inline ::AString& operator+=(
const AString& str)
noexcept
528 inline ::AString& operator+=(
const char* str)
noexcept
530 *
this += AString(str);
534 [[nodiscard]]
bool empty() const noexcept {
535 return super::empty();
537 [[nodiscard]] size_type size() const noexcept {
538 return super::size();
540 char16_t operator[](size_type index)
const
542 return super::at(index);
544 char16_t& operator[](size_type index)
546 return super::at(index);
548 bool operator<(
const AString& other)
const noexcept
550 return compare(other) < 0;
553 void clear() noexcept
558 char16_t& front() noexcept
560 return super::front();
562 char16_t& back() noexcept
564 return super::back();
566 const char16_t& front() const noexcept
568 return super::front();
570 const char16_t& back() const noexcept
572 return super::back();
574 char16_t& first() noexcept
576 return super::front();
578 char16_t& last() noexcept
580 return super::back();
582 const char16_t& first() const noexcept
584 return super::front();
586 const char16_t& last() const noexcept
588 return super::back();
592 AOptional<char16_t> firstOpt() const noexcept
597 return super::front();
601 AOptional<char16_t> lastOpt() const noexcept
606 return super::back();
609 const char16_t* c_str()
const
611 return super::c_str();
614 iterator begin() noexcept
616 return super::begin();
618 iterator end() noexcept
623 const_iterator begin() const noexcept
625 return super::begin();
627 const_iterator end() const noexcept
632 reverse_iterator rbegin() noexcept
634 return super::rbegin();
636 reverse_iterator rend() noexcept
638 return super::rend();
641 const_reverse_iterator rbegin() const noexcept
643 return super::rbegin();
645 const_reverse_iterator rend() const noexcept
647 return super::rend();
650 AString& append(
const AString& s)
noexcept
656 AString& append(
size_t count,
char16_t ch)
noexcept
658 super::append(count, ch);
662 AString& operator=(
const AString& value)
noexcept
664 super::operator=(value);
668 AString& operator=(AString&& value)
noexcept
670 super::operator=(std::move(value));
674 bool operator==(
const AString& other)
const noexcept
676 if (size() != other.size()) {
679 return std::memcmp(data(), other.data(), sizeInBytes()) == 0;
681 bool operator==(
const char16_t* other)
const noexcept
684 for (; it != end(); ++it, ++other) {
688 if (*other ==
'\0') {
692 return *other ==
'\0';
696 size_t sizeInBytes() const noexcept {
697 return size() *
sizeof(super::value_type);
700 bool operator!=(
const AString& other)
const noexcept
702 return !operator==(other);
704 bool operator!=(
const char16_t* other)
const noexcept
706 return !operator==(other);
709 bool operator==(
const char* other)
const noexcept
711 return *
this == AString(other);
714 bool operator!=(
const char* other)
const noexcept
716 return *
this != AString(other);
719 template<
typename... Args>
720 inline AString format(Args&&... args)
const;
722 AString processEscapes()
const;
724 AString& removeAll(
char16_t c)
noexcept {
725 erase(std::remove(begin(), end(), c), end());
730 AString substr(std::size_t offset, std::size_t count = npos)
const {
731 return super::substr(offset, count);
739 AOptional<T> toNumberImpl() const noexcept;