From 52f3ca8026bd4f6d826ae8ec2d76b0e4a89ec8ed Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sat, 31 Aug 2024 21:34:49 +0100 Subject: [PATCH] [+] AuUTF8Iterator [+] AuReverseIterator [*] Move AuRONString [*] Move AuROString --- Include/auROXTL/Iterators/auRONString.hpp | 694 ++++++++ Include/auROXTL/Iterators/auROString.hpp | 790 +++++++++ .../auROXTL/Iterators/auReverseIterator.hpp | 71 + .../auROXTL/Iterators/auReverseIterator.ipp | 122 ++ Include/auROXTL/Iterators/auUTF8Iterator.hpp | 80 + Include/auROXTL/Iterators/auUTF8Iterator.ipp | 289 ++++ Include/auROXTL/auUTF8StringView.hpp | 1465 +---------------- Include/auROXTLTypes.hpp | 2 + Include/auROXTLUtils.hpp | 2 + 9 files changed, 2052 insertions(+), 1463 deletions(-) create mode 100644 Include/auROXTL/Iterators/auRONString.hpp create mode 100644 Include/auROXTL/Iterators/auROString.hpp create mode 100644 Include/auROXTL/Iterators/auReverseIterator.hpp create mode 100644 Include/auROXTL/Iterators/auReverseIterator.ipp create mode 100644 Include/auROXTL/Iterators/auUTF8Iterator.hpp create mode 100644 Include/auROXTL/Iterators/auUTF8Iterator.ipp diff --git a/Include/auROXTL/Iterators/auRONString.hpp b/Include/auROXTL/Iterators/auRONString.hpp new file mode 100644 index 0000000..cab697f --- /dev/null +++ b/Include/auROXTL/Iterators/auRONString.hpp @@ -0,0 +1,694 @@ +/*** + Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: auRONString.hpp + Date: 2024-04-30 + Author: Reece + Notes: Null terminated read only string view +***/ +#pragma once + + + +/* read-only, null terminated, utf-8 *byte* view */ +struct AuRONString +{ + using traits_type = typename AuROString::traits_type; + using value_type = typename AuROString::value_type; + using pointer = typename AuROString::pointer; + using const_pointer = typename AuROString::const_pointer; + using reference = typename AuROString::reference; + using const_reference = typename AuROString::const_reference; + using const_iterator = typename AuROString::const_iterator; + using iterator = const_iterator; + using const_reverse_iterator = typename AuROString::const_reverse_iterator; + using reverse_iterator = const_reverse_iterator; + using size_type = typename AuROString::size_type; + using difference_type = typename AuROString::difference_type; + + // using basic_string_view = AuROString; + using basic_string_view = std::basic_string_view; + + cstatic constexpr size_type npos = size_type(-1); + + + inline AuRONString(const AuString &str) : + view(str) + { + + } + + inline AuRONString(const std::string &str) : + view(str) + { + + } + + inline AuRONString(const char *str) : + view(str) + { + + } + + inline constexpr const_iterator begin() const noexcept + { + return this->cbegin(); + } + + inline constexpr const_iterator cbegin() const noexcept + { + return this->view.cbegin(); + } + + inline constexpr const_iterator end() const noexcept + { + return this->cend(); + } + + inline constexpr const_iterator cend() const noexcept + { + return this->cbegin() + this->length(); + } + + inline constexpr const_reverse_iterator rbegin() const noexcept + { + return this->crbegin(); + } + + inline constexpr const_reverse_iterator crbegin() const noexcept + { + return const_reverse_iterator(this->cend()); + } + + inline constexpr const_reverse_iterator rend() const noexcept + { + return this->crend(); + } + + inline constexpr const_reverse_iterator crend() const noexcept + { + return const_reverse_iterator(this->cbegin()); + } + + inline constexpr int compare(AuROString v) const noexcept + { + if (size() < v.size()) + { + return -1; + } + + int iRet = AuMemcmp(data(), v.data(), v.size()); + + if (size() > v.size() && + iRet == 0) + { + return 1; + } + + return iRet; + } + + inline constexpr int compare(size_type pos1, size_type count1, + AuROString v) const + { + return this->view.substr(pos1, count1).compare(v); + } + + inline constexpr int compare(size_type pos1, size_type count1, AuROString v, + size_type pos2, size_type count2) const + { + return this->view.substr(pos1, count1).compare(v.substr(pos2, count2)); + } + + inline constexpr int compare(const char *s) const + { + return this->compare(AuROString(s)); + } + + inline constexpr int compare(size_type pos1, size_type count1, + const char *s) const + { + return this->view.substr(pos1, count1).compare(AuROString(s)); + } + + inline constexpr int compare(size_type pos1, size_type count1, + const char *s, size_type count2) const + { + return this->view.substr(pos1, count1).compare(AuROString(s, count2)); + } + + inline constexpr bool starts_with(AuROString sv) const noexcept + { + return AuStartsWith(*this, sv); + } + + inline constexpr bool starts_with(char ch) const noexcept + { + return AuStartsWith(*this, AuROString(&ch, 1)); + } + + inline constexpr bool starts_with(const char *s) const + { + return AuStartsWith(*this, s); + } + + inline constexpr bool ends_with(AuROString sv) const noexcept + { + return AuEndsWith(*this, sv); + } + + inline constexpr bool ends_with(char ch) const noexcept + { + return AuEndsWith(*this, AuROString(&ch, 1)); + } + + inline constexpr bool ends_with(const char *s) const + { + return AuEndsWith(*this, s); + } + + inline constexpr bool contains(AuROString sv) const noexcept + { + #if 0 + return AuCodepointsContains(*this, sv); + #else + return AuCodepointsFindByteOffsetUnsafe(*this, sv, 0) != AuROString::npos; + #endif + } + + inline constexpr bool contains(char c) const noexcept + { + return this->contains(AuROString(&c, 1)); + } + + inline constexpr bool contains(const char *s) const + { + return this->contains(AuROString(s)); + } + + inline constexpr const_reference operator[](size_type pos) const + { + return *(this->begin() + pos); + } + + inline constexpr const_reference at(size_type pos) const + { + return this->view.at(pos); + } + + inline constexpr const_reference front() const + { + return this->operator[](0); + } + + inline constexpr const_reference back() const + { + return this->operator[](size() - 1); + } + + inline constexpr const_pointer data() const noexcept + { + return &this->operator[](0); + } + + inline constexpr const_pointer c_str() const noexcept + { + return this->data(); + } + + inline constexpr size_type max_size() const noexcept + { + return this->view.max_size(); + } + + inline constexpr size_type size() const noexcept + { + return this->view.size(); + } + + inline constexpr size_type length() const noexcept + { + return this->size(); + } + + inline constexpr bool empty() const noexcept + { + return this->size() == 0 || !this->view.data(); + } + + inline constexpr AuROString substr(size_type pos1, size_type count1 = npos) const noexcept + { + if (pos1 >= this->size()) + { + return {}; + } + + if (count1 == npos) + { + return AuROString {this->data() + pos1, this->size() - pos1 }; + } + + if (pos1 + count1 > this->size()) + { + return {}; + } + + return AuROString { this->data() + pos1, count1 }; + } + + inline constexpr size_type find(AuROString v, size_type pos = 0) const noexcept + { + return AuCodepointsFindByteOffsetUnsafe(*this, v, pos); + } + + inline constexpr size_type find(char ch, size_type pos = 0) const noexcept + { + return this->find(AuROString(&ch, 1), pos); + } + + inline constexpr size_type find(const char *s, size_type pos, size_type count) const + { + return this->find(AuROString(s, count), pos); + } + + inline constexpr size_type find(const char *s, size_type pos = 0) const + { + return this->find(AuROString(s), pos); + } + + inline constexpr size_type rfind(AuROString v, size_type pos = npos) const noexcept + { + return this->view.rfind(v, pos); + } + + inline constexpr size_type rfind(char ch, size_type pos = npos) const noexcept + { + return this->find(AuROString(&ch, 1), pos); + } + + inline constexpr size_type rfind(const char *s, size_type pos, size_type count) const + { + return this->rfind(AuROString(s, count), pos); + } + + inline constexpr size_type rfind(const char *s, size_type pos = npos) const + { + return this->rfind(AuROString(s), pos); + } + + inline constexpr size_type find_first_not_of(AuROString right, const size_type offset = 0) const noexcept + { + return this->view.find_first_not_of(right, offset); + } + + inline constexpr size_type find_last_not_of(AuROString right, const size_type offset = npos) const noexcept + { + return this->view.find_last_not_of(right, offset); + } + + inline constexpr size_type find_last_of(AuROString right, const size_type offset = npos) const noexcept + { + return this->view.find_last_of(right, offset); + } + + inline constexpr size_type find_first_of(AuROString right, const size_type offset = 0) const noexcept + { + if (right.size() == 0) + { + return npos; + } + + return this->find(right, offset); + } + + inline constexpr size_type find_first_of(const char c, const size_type offset = 0) const noexcept + { + return this->find_first_of(AuROString(&c, 1), offset); + } + + inline constexpr size_type find_first_of(const char *const s, const size_type offset, const size_type count) const + { + return this->find_first_of(AuROString(s, count), offset); + } + + inline constexpr size_type find_first_of(const char *const s, const size_type offset = 0) const + { + return this->find_first_of(AuROString(s), offset); + } + + inline constexpr size_type find_last_of(const char c, const size_type offset = npos) const noexcept + { + return this->find_last_of(AuROString(&c, 1), offset); + } + + inline constexpr size_type find_last_of(const char *const s, const size_type offset, const size_type count) const + { + return this->find_last_of(AuROString(s, count), offset); + } + + inline constexpr size_type find_last_of(const char *const s, const size_type offset = npos) const + { + return this->find_last_of(AuROString(s), offset); + } + + inline constexpr size_type find_first_not_of(const char c, const size_type offset = 0) const noexcept + { + return this->find_first_not_of(AuROString(&c, 1), offset); + } + + inline constexpr size_type find_first_not_of(const char *const s, const size_type offset, const size_type count) const + { + return this->find_first_not_of(AuROString(s, count), offset); + } + + inline constexpr size_type find_first_not_of(const char *const s, const size_type offset = 0) const + { + return this->find_first_not_of(AuROString(s), offset); + } + + inline constexpr size_type find_last_not_of(const char c, const size_type offset = npos) const noexcept + { + return this->find_last_not_of(AuROString(&c, 1), offset); + } + + inline constexpr size_type find_last_not_of(const char *const s, const size_type offset, const size_type count) const + { + return this->find_last_not_of(AuROString(s, count), offset); + } + + inline constexpr size_type find_last_not_of(const char *const s, const size_type offset = npos) const + { + return this->find_last_not_of(AuROString(s), offset); + } + + inline constexpr operator AuROString() const + { + return this->view; + } + + inline operator bool() const + { + return this->view; + } + + inline constexpr const_iterator Begin() const noexcept + { + return this->begin(); + } + + inline constexpr const_iterator CBegin() const noexcept + { + return this->cbegin(); + } + + inline constexpr const_iterator End() const noexcept + { + return this->end(); + } + + inline constexpr const_iterator CEnd() const noexcept + { + return this->cend(); + } + + inline constexpr const_reverse_iterator RBegin() const noexcept + { + return this->rbegin(); + } + + inline constexpr const_reverse_iterator CRBegin() const noexcept + { + return this->crbegin(); + } + + inline constexpr const_reverse_iterator REnd() const noexcept + { + return this->rend(); + } + + inline constexpr const_reverse_iterator CREnd() const noexcept + { + return this->crend(); + } + + inline constexpr AuROString Substr(size_type pos1, size_type count1 = npos) const noexcept + { + return this->substr(pos1, count1); + } + + inline constexpr AuROString SubStr(size_type pos1, size_type count1 = npos) const noexcept + { + return this->substr(pos1, count1); + } + + inline constexpr int Compare(AuROString v) const noexcept + { + return this->compare(v); + } + + inline constexpr int Compare(const AuROString &v) const noexcept + { + return this->compare(v); + } + + inline constexpr int Compare(size_type pos1, size_type count1, + AuROString v) const + { + return this->compare(pos1, count1, v); + } + + inline constexpr int Compare(size_type pos1, size_type count1, AuROString v, + size_type pos2, size_type count2) const + { + return this->compare(pos1, count1, v, pos2, count2); + } + + inline constexpr int Compare(const char *s) const + { + return this->compare(s); + } + + inline constexpr int Compare(size_type pos1, size_type count1, + const char *s) const + { + return this->compare(pos1, count1, s); + } + + inline constexpr int Compare(size_type pos1, size_type count1, + const char *s, size_type count2) const + { + return this->compare(pos1, count1, s, count2); + } + + inline constexpr bool StartsWith(AuROString sv) const noexcept + { + return this->starts_with(sv); + } + + inline constexpr bool StartsWith(char ch) const noexcept + { + return this->starts_with(ch); + } + + inline constexpr bool StartsWith(const char *s) const + { + return this->starts_with(s); + } + + inline constexpr bool EndsWith(AuROString sv) const noexcept + { + return this->ends_with(sv); + } + + inline constexpr bool EndsWith(char ch) const noexcept + { + return this->ends_with(ch); + } + + inline constexpr bool EndsWith(const char *s) const + { + return this->ends_with(s); + } + + inline constexpr bool Contains(AuROString sv) const noexcept + { + return this->contains(sv); + } + + inline constexpr bool Contains(char C) const noexcept + { + return this->contains(C); + } + + inline constexpr bool Contains(const char *s) const + { + return this->contains(s); + } + + inline constexpr const_reference At(size_type pos) const + { + return this->at(pos); + } + + inline constexpr const_reference Front() const + { + return this->front(); + } + + inline constexpr const_reference Back() const + { + return this->back(); + } + + inline constexpr const_pointer Data() const noexcept + { + return this->data(); + } + + inline constexpr const_pointer CStr() const noexcept + { + return this->c_str(); + } + + inline constexpr size_type MaxSize() const noexcept + { + return this->max_size(); + } + + inline constexpr size_type Size() const noexcept + { + return this->size(); + } + + inline constexpr size_type Length() const noexcept + { + return this->length(); + } + + inline constexpr bool Empty() const noexcept + { + return this->empty(); + } + + inline constexpr size_type Find(AuROString v, size_type pos = 0) const noexcept + { + return this->find(v, pos); + } + + inline constexpr size_type Find(char ch, size_type pos = 0) const noexcept + { + return this->find(ch, pos); + } + + inline constexpr size_type Find(const char *s, size_type pos, size_type count) const + { + return this->find(s, pos, count); + } + + inline constexpr size_type Find(const char *s, size_type pos = 0) const + { + return this->find(s, pos); + } + + inline constexpr size_type RFind(AuROString v, size_type pos = npos) const noexcept + { + return this->rfind(v, pos); + } + + inline constexpr size_type RFind(char ch, size_type pos = npos) const noexcept + { + return this->rfind(ch, pos); + } + + inline constexpr size_type Rfind(const char *s, size_type pos, size_type count) const + { + return this->rfind(s, pos, count); + } + + inline constexpr size_type Rfind(const char *s, size_type pos = npos) const + { + return this->rfind(s, pos); + } + + inline constexpr size_type FindFirstNotOf(const AuROString right, const size_type offset = 0) const noexcept + { + return this->find_first_not_of(right, offset); + } + + inline constexpr size_type FindLastNotOf(const AuROString right, const size_type offset = npos) const noexcept + { + return this->find_last_not_of(right, offset); + } + + inline constexpr size_type FindLastOf(const AuROString right, const size_type offset = npos) const noexcept + { + return this->find_last_of(right, offset); + } + + inline constexpr size_type FindFirstOf(const AuROString right, const size_type offset = 0) const noexcept + { + return this->find_first_of(right, offset); + } + + inline constexpr size_type Find_first_of(const char c, const size_type offset = 0) const noexcept + { + return this->find_first_of(c, offset); + } + + inline constexpr size_type FindFirstOf(const char *const s, const size_type offset, const size_type count) const + { + return this->find_first_of(s, offset, count); + } + + inline constexpr size_type FindFirstOf(const char *const s, const size_type offset = 0) const + { + return this->find_first_of(s, offset); + } + + inline constexpr size_type FindLastOf(const char c, const size_type offset = npos) const noexcept + { + return this->find_last_of(c, offset); + } + + inline constexpr size_type FindLastOf(const char *const s, const size_type offset, const size_type count) const + { + return this->find_last_of(s, offset, count); + } + + inline constexpr size_type FindLastOf(const char *const s, const size_type offset = npos) const + { + return this->find_last_of(s, offset); + } + + inline constexpr size_type FindFirstNotOf(const char c, const size_type offset = 0) const noexcept + { + return this->find_first_not_of(c, offset); + } + + inline constexpr size_type FindFirstNotOf(const char *const s, const size_type offset, const size_type count) const + { + return this->find_first_not_of(s, offset, count); + } + + inline constexpr size_type FindFirstNotOf(const char *const s, const size_type offset = 0) const + { + return this->find_first_not_of(s, offset); + } + + inline constexpr size_type FindLastNotOf(const char c, const size_type offset = npos) const noexcept + { + return this->find_last_not_of(c, offset); + } + + inline constexpr size_type FindLastNotOf(const char *const s, const size_type offset, const size_type count) const + { + return this->find_last_not_of(s, offset, count); + } + + inline constexpr size_type FindLastNotOf(const char *const s, const size_type offset = npos) const + { + return this->find_last_not_of(s, offset); + } +private: + AuROString view; +}; \ No newline at end of file diff --git a/Include/auROXTL/Iterators/auROString.hpp b/Include/auROXTL/Iterators/auROString.hpp new file mode 100644 index 0000000..41f1421 --- /dev/null +++ b/Include/auROXTL/Iterators/auROString.hpp @@ -0,0 +1,790 @@ +/*** + Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: auROString.hpp + Date: 2024-04-19 + Author: Reece + Notes: Null terminated read only string view +***/ +#pragma once + +/* read-only, null terminated, utf-8 *byte* view */ +struct AuROString +{ + // using basic_string_view = AuROString; + using basic_string_view = std::basic_string_view; + + using traits_type = typename basic_string_view::traits_type; + + using value_type = char; + using pointer = char *; + using const_pointer = const char *; + using reference = char &; + using const_reference = const char &; + using const_iterator = const char *; + using iterator = char *; + using const_reverse_iterator = typename std::reverse_iterator; + using reverse_iterator = typename std::reverse_iterator; + using size_type = AuUInt; + using difference_type = AuSInt; + + cstatic constexpr size_type npos = size_type(-1); + + inline constexpr AuROString() + { + + } + + AU_COPY_MOVE(AuROString); + + inline constexpr AuROString(const AuString &str) : + pPointer(str.data()), + uLength(str.length()) + { + + } + + inline constexpr AuROString(const std::string &str) : + pPointer(str.data()), + uLength(str.length()) + { + + } + + inline constexpr AuROString(const char *str) : + pPointer(str), + uLength(traits_type::length(str)) + { + + } + + inline constexpr AuROString(const char *str, + AuUInt uLength) : + pPointer(str), + uLength(uLength) + { + + } + inline constexpr AuROString(const char *str, + const char *strEnd) : + pPointer(str), + uLength(strEnd - str) + { + + } + + inline constexpr AuROString(basic_string_view strView) : + pPointer(strView.data()), + uLength(strView.size()) + { + + } + + inline constexpr const_iterator begin() const noexcept + { + return this->cbegin(); + } + + inline constexpr const_iterator cbegin() const noexcept + { + return this->pPointer; + } + + inline constexpr const_iterator end() const noexcept + { + return this->cend(); + } + + inline constexpr const_iterator cend() const noexcept + { + return this->cbegin() + this->length(); + } + + inline constexpr const_reverse_iterator rbegin() const noexcept + { + return this->crbegin(); + } + + inline constexpr const_reverse_iterator crbegin() const noexcept + { + return const_reverse_iterator(this->cend()); + } + + inline constexpr const_reverse_iterator rend() const noexcept + { + return this->crend(); + } + + inline constexpr const_reverse_iterator crend() const noexcept + { + return const_reverse_iterator(this->cbegin()); + } + + inline constexpr AuROString substr(size_type pos1, size_type count1 = npos) const noexcept + { + if (pos1 >= this->uLength) + { + return {}; + } + + if (count1 == npos) + { + return AuROString {this->pPointer + pos1, this->uLength - pos1 }; + } + + if (pos1 + count1 > this->uLength) + { + return {}; + } + + return AuROString { this->pPointer + pos1, count1 }; + } + + inline constexpr void stl_remove_suffix(size_type n) + { + if (this->uLength < n) + { + *this = AuROString { }; + } + else + { + *this = AuROString { this->pPointer, this->uLength - n }; + } + } + + inline constexpr void stl_remove_prefix(size_type n) + { + if (this->uLength < n) + { + *this = AuROString { }; + } + else + { + *this = AuROString { this->pPointer + n, this->uLength - n }; + } + } + + inline constexpr AuROString remove_suffix(size_type n) const + { + if (this->uLength < n) + { + return {}; + } + + return AuROString { this->pPointer, this->uLength - n }; + } + + inline constexpr AuROString remove_prefix(size_type n) const + { + if (this->uLength < n) + { + return {}; + } + + return AuROString { this->pPointer + n, this->uLength - n }; + } + + inline constexpr AuROString RemoveSuffix(size_type n) const + { + return remove_suffix(n); + } + + inline constexpr AuROString RemovePrefix(size_type n) const + { + return remove_prefix(n); + } + + inline constexpr int compare(basic_string_view v) const noexcept + { + if (size() < v.size()) + { + return -1; + } + + int iRet = AuMemcmp(data(), v.data(), v.size()); + + if (size() > v.size() && + iRet == 0) + { + return 1; + } + + return iRet; + } + + inline constexpr int compare(const AuROString &v) const noexcept + { + if (size() < v.size()) + { + return -1; + } + + int iRet = AuMemcmp(data(), v.data(), v.size()); + + if (size() > v.size() && + iRet == 0) + { + return 1; + } + + return iRet; + } + + inline constexpr int compare(size_type pos1, size_type count1, + AuROString v) const + { + return this->substr(pos1, count1).compare(v); + } + + inline constexpr int compare(size_type pos1, size_type count1, AuROString v, + size_type pos2, size_type count2) const + { + return this->substr(pos1, count1).compare(v.substr(pos2, count2)); + } + + inline constexpr int compare(const char *s) const + { + return this->compare(AuROString(s)); + } + + inline constexpr int compare(size_type pos1, size_type count1, + const char *s) const + { + return this->substr(pos1, count1).compare(AuROString(s)); + } + + inline constexpr int compare(size_type pos1, size_type count1, + const char *s, size_type count2) const + { + return this->substr(pos1, count1).compare(AuROString(s, count2)); + } + + inline constexpr bool starts_with(AuROString sv) const noexcept + { + return AuStartsWith(*this, sv); + } + + inline constexpr bool starts_with(char ch) const noexcept + { + return AuStartsWith(*this, AuROString(&ch, 1)); + } + + inline constexpr bool starts_with(const char *s) const + { + return AuStartsWith(*this, s); + } + + inline constexpr bool ends_with(AuROString sv) const noexcept + { + return AuEndsWith(*this, sv); + } + + inline constexpr bool ends_with(char ch) const noexcept + { + return AuEndsWith(*this, AuROString(&ch, 1)); + } + + inline constexpr bool ends_with(const char *s) const + { + return AuEndsWith(*this, s); + } + + inline constexpr bool contains(AuROString sv) const noexcept + { + #if 0 + return AuCodepointsContains(*this, sv); + #else + return AuCodepointsFindByteOffsetUnsafe(*this, sv, 0) != AuROString::npos; + #endif + } + + inline constexpr bool contains(char c) const noexcept + { + return this->contains(AuROString(&c, 1)); + } + + inline constexpr bool contains(const char *s) const + { + return this->contains(AuROString(s)); + } + + inline constexpr const_reference operator[](size_type pos) const + { + return *(this->begin() + pos); + } + + inline constexpr const_reference at(size_type pos) const + { + return this->pPointer[pos]; + } + + inline constexpr const_reference front() const + { + return this->operator[](0); + } + + inline constexpr const_reference back() const + { + return this->operator[](size() - 1); + } + + inline constexpr const_pointer data() const noexcept + { + return &this->operator[](0); + } + + inline constexpr size_type max_size() const noexcept + { + return SIZE_MAX; + //return AuNumericLimits().max(); + } + + inline constexpr size_type size() const noexcept + { + return this->uLength; + } + + inline constexpr size_type length() const noexcept + { + return this->size(); + } + + inline constexpr bool empty() const noexcept + { + return this->size() == 0 || !this->pPointer; + } + + inline constexpr size_type find(AuROString v, size_type pos = 0) const noexcept + { + return AuCodepointsFindByteOffsetUnsafe(*this, v, pos); + } + + inline constexpr size_type find(char ch, size_type pos = 0) const noexcept + { + return this->find(AuROString(&ch, 1), pos); + } + + inline constexpr size_type find(const char *s, size_type pos, size_type count) const + { + return this->find(AuROString(s, count), pos); + } + + inline constexpr size_type find(const char *s, size_type pos = 0) const + { + return this->find(AuROString(s), pos); + } + + inline constexpr size_type rfind(AuROString v, size_type pos = npos) const noexcept + { + return basic_string_view(*this).rfind(basic_string_view { v }, pos); + } + + inline constexpr size_type rfind(char ch, size_type pos = npos) const noexcept + { + return this->find(AuROString(&ch, 1), pos); + } + + inline constexpr size_type rfind(const char *s, size_type pos, size_type count) const + { + return this->rfind(AuROString(s, count), pos); + } + + inline constexpr size_type rfind(const char *s, size_type pos = npos) const + { + return this->rfind(AuROString(s), pos); + } + + inline constexpr size_type find_first_not_of(const AuROString right, const size_type offset = 0) const noexcept + { + return basic_string_view(*this).find_first_not_of(basic_string_view { right }, offset); + } + + inline constexpr size_type find_last_not_of(const AuROString right, const size_type offset = npos) const noexcept + { + return basic_string_view(*this).find_last_not_of(basic_string_view { right }, offset); + } + + inline constexpr size_type find_last_of(const AuROString right, const size_type offset = npos) const noexcept + { + return basic_string_view(*this).find_last_of(basic_string_view { right }, offset); + } + + inline constexpr size_type find_first_of(const AuROString right, const size_type offset = 0) const noexcept + { + if (right.size() == 0) + { + return npos; + } + + return this->find(right, offset); + } + + inline constexpr size_type find_first_of(const char c, const size_type offset = 0) const noexcept + { + return this->find_first_of(AuROString(&c, 1), offset); + } + + inline constexpr size_type find_first_of(const char *const s, const size_type offset, const size_type count) const + { + return this->find_first_of(AuROString(s, count), offset); + } + + inline constexpr size_type find_first_of(const char *const s, const size_type offset = 0) const + { + return this->find_first_of(AuROString(s), offset); + } + + inline constexpr size_type find_last_of(const char c, const size_type offset = npos) const noexcept + { + return this->find_last_of(AuROString(&c, 1), offset); + } + + inline constexpr size_type find_last_of(const char *const s, const size_type offset, const size_type count) const + { + return this->find_last_of(AuROString(s, count), offset); + } + + inline constexpr size_type find_last_of(const char *const s, const size_type offset = npos) const + { + return this->find_last_of(AuROString(s), offset); + } + + inline constexpr size_type find_first_not_of(const char c, const size_type offset = 0) const noexcept + { + return this->find_first_not_of(AuROString(&c, 1), offset); + } + + inline constexpr size_type find_first_not_of(const char *const s, const size_type offset, const size_type count) const + { + return this->find_first_not_of(AuROString(s, count), offset); + } + + inline constexpr size_type find_first_not_of(const char *const s, const size_type offset = 0) const + { + return this->find_first_not_of(AuROString(s), offset); + } + + inline constexpr size_type find_last_not_of(const char c, const size_type offset = npos) const noexcept + { + return this->find_last_not_of(AuROString(&c, 1), offset); + } + + inline constexpr size_type find_last_not_of(const char *const s, const size_type offset, const size_type count) const + { + return this->find_last_not_of(AuROString(s, count), offset); + } + + inline constexpr size_type find_last_not_of(const char *const s, const size_type offset = npos) const + { + return this->find_last_not_of(AuROString(s), offset); + } + + inline constexpr operator std::string_view() const + { + return std::string_view { pPointer, uLength }; + } + + inline constexpr const_iterator Begin() const noexcept + { + return this->begin(); + } + + inline constexpr const_iterator CBegin() const noexcept + { + return this->cbegin(); + } + + inline constexpr const_iterator End() const noexcept + { + return this->end(); + } + + inline constexpr const_iterator CEnd() const noexcept + { + return this->cend(); + } + + inline constexpr const_reverse_iterator RBegin() const noexcept + { + return this->rbegin(); + } + + inline constexpr const_reverse_iterator CRBegin() const noexcept + { + return this->crbegin(); + } + + inline constexpr const_reverse_iterator REnd() const noexcept + { + return this->rend(); + } + + inline constexpr const_reverse_iterator CREnd() const noexcept + { + return this->crend(); + } + + inline constexpr AuROString Substr(size_type pos1, size_type count1 = npos) const noexcept + { + return this->substr(pos1, count1); + } + + inline constexpr AuROString SubStr(size_type pos1, size_type count1 = npos) const noexcept + { + return this->substr(pos1, count1); + } + + inline constexpr int Compare(basic_string_view v) const noexcept + { + return this->compare(v); + } + + inline constexpr int Compare(const AuROString &v) const noexcept + { + return this->compare(v); + } + + inline constexpr int Compare(size_type pos1, size_type count1, + AuROString v) const + { + return this->compare(pos1, count1, v); + } + + inline constexpr int Compare(size_type pos1, size_type count1, AuROString v, + size_type pos2, size_type count2) const + { + return this->compare(pos1, count1, v, pos2, count2); + } + + inline constexpr int Compare(const char *s) const + { + return this->compare(s); + } + + inline constexpr int Compare(size_type pos1, size_type count1, + const char *s) const + { + return this->compare(pos1, count1, s); + } + + inline constexpr int Compare(size_type pos1, size_type count1, + const char *s, size_type count2) const + { + return this->compare(pos1, count1, s, count2); + } + + inline constexpr bool StartsWith(AuROString sv) const noexcept + { + return this->starts_with(sv); + } + + inline constexpr bool StartsWith(char ch) const noexcept + { + return this->starts_with(ch); + } + + inline constexpr bool StartsWith(const char *s) const + { + return this->starts_with(s); + } + + inline constexpr bool EndsWith(AuROString sv) const noexcept + { + return this->ends_with(sv); + } + + inline constexpr bool EndsWith(char ch) const noexcept + { + return this->ends_with(ch); + } + + inline constexpr bool EndsWith(const char *s) const + { + return this->ends_with(s); + } + + inline constexpr bool Contains(AuROString sv) const noexcept + { + return this->contains(sv); + } + + inline constexpr bool Contains(char C) const noexcept + { + return this->contains(C); + } + + inline constexpr bool Contains(const char *s) const + { + return this->contains(s); + } + + inline constexpr const_reference At(size_type pos) const + { + return this->at(pos); + } + + inline constexpr const_reference Front() const + { + return this->front(); + } + + inline constexpr const_reference Back() const + { + return this->back(); + } + + inline constexpr const_pointer Data() const noexcept + { + return this->data(); + } + + inline constexpr size_type MaxSize() const noexcept + { + return this->max_size(); + } + + inline constexpr size_type Size() const noexcept + { + return this->size(); + } + + inline constexpr size_type Length() const noexcept + { + return this->length(); + } + + inline constexpr bool Empty() const noexcept + { + return this->empty(); + } + + inline constexpr size_type Find(AuROString v, size_type pos = 0) const noexcept + { + return this->find(v, pos); + } + + inline constexpr size_type Find(char ch, size_type pos = 0) const noexcept + { + return this->find(ch, pos); + } + + inline constexpr size_type Find(const char *s, size_type pos, size_type count) const + { + return this->find(s, pos, count); + } + + inline constexpr size_type Find(const char *s, size_type pos = 0) const + { + return this->find(s, pos); + } + + inline constexpr size_type RFind(AuROString v, size_type pos = npos) const noexcept + { + return this->rfind(v, pos); + } + + inline constexpr size_type RFind(char ch, size_type pos = npos) const noexcept + { + return this->rfind(ch, pos); + } + + inline constexpr size_type Rfind(const char *s, size_type pos, size_type count) const + { + return this->rfind(s, pos, count); + } + + inline constexpr size_type Rfind(const char *s, size_type pos = npos) const + { + return this->rfind(s, pos); + } + + inline constexpr size_type FindFirstNotOf(const AuROString right, const size_type offset = 0) const noexcept + { + return this->find_first_not_of(right, offset); + } + + inline constexpr size_type FindLastNotOf(const AuROString right, const size_type offset = npos) const noexcept + { + return this->find_last_not_of(right, offset); + } + + inline constexpr size_type FindLastOf(const AuROString right, const size_type offset = npos) const noexcept + { + return this->find_last_of(right, offset); + } + + inline constexpr size_type FindFirstOf(const AuROString right, const size_type offset = 0) const noexcept + { + return this->find_first_of(right, offset); + } + + inline constexpr size_type Find_first_of(const char c, const size_type offset = 0) const noexcept + { + return this->find_first_of(c, offset); + } + + inline constexpr size_type FindFirstOf(const char *const s, const size_type offset, const size_type count) const + { + return this->find_first_of(s, offset, count); + } + + inline constexpr size_type FindFirstOf(const char *const s, const size_type offset = 0) const + { + return this->find_first_of(s, offset); + } + + inline constexpr size_type FindLastOf(const char c, const size_type offset = npos) const noexcept + { + return this->find_last_of(c, offset); + } + + inline constexpr size_type FindLastOf(const char *const s, const size_type offset, const size_type count) const + { + return this->find_last_of(s, offset, count); + } + + inline constexpr size_type FindLastOf(const char *const s, const size_type offset = npos) const + { + return this->find_last_of(s, offset); + } + + inline constexpr size_type FindFirstNotOf(const char c, const size_type offset = 0) const noexcept + { + return this->find_first_not_of(c, offset); + } + + inline constexpr size_type FindFirstNotOf(const char *const s, const size_type offset, const size_type count) const + { + return this->find_first_not_of(s, offset, count); + } + + inline constexpr size_type FindFirstNotOf(const char *const s, const size_type offset = 0) const + { + return this->find_first_not_of(s, offset); + } + + inline constexpr size_type FindLastNotOf(const char c, const size_type offset = npos) const noexcept + { + return this->find_last_not_of(c, offset); + } + + inline constexpr size_type FindLastNotOf(const char *const s, const size_type offset, const size_type count) const + { + return this->find_last_not_of(s, offset, count); + } + + inline constexpr size_type FindLastNotOf(const char *const s, const size_type offset = npos) const + { + return this->find_last_not_of(s, offset); + } + + inline operator bool() const + { + return this->pPointer && + this->uLength; + } + +private: + const char *pPointer {}; + AuUInt uLength {}; +}; \ No newline at end of file diff --git a/Include/auROXTL/Iterators/auReverseIterator.hpp b/Include/auROXTL/Iterators/auReverseIterator.hpp new file mode 100644 index 0000000..38adfa7 --- /dev/null +++ b/Include/auROXTL/Iterators/auReverseIterator.hpp @@ -0,0 +1,71 @@ +/*** + Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: auReverseIterator.hpp + Date: 2024-08-31 + Author: Reece +***/ +#pragma once + +template +struct AuReverseIterator +{ + using iterator_type = Iterator; + + using iterator_category = std::iterator_traits; + using value_type = typename std::iterator_traits::value_type; + using difference_type = typename std::iterator_traits::difference_type; + using pointer = typename std::iterator_traits::pointer; + using reference = typename std::iterator_traits::reference; + + template + friend struct AuReverseIterator; + + constexpr AuReverseIterator() = default; + + constexpr explicit AuReverseIterator(Iterator that); + + template + constexpr AuReverseIterator(const AuReverseIterator &that); + + template + constexpr AuReverseIterator &operator=(const AuReverseIterator &that); + + constexpr Iterator base() const; + constexpr Iterator Base() const; + + constexpr reference operator*() const; + + constexpr pointer operator->() const; + + constexpr AuReverseIterator &operator++(); + + constexpr AuReverseIterator operator++(int); + + constexpr AuReverseIterator &operator--(); + + constexpr AuReverseIterator operator--(int); + + constexpr AuReverseIterator operator+(const difference_type offset) const; + + constexpr AuReverseIterator &operator+=(const difference_type offset); + + constexpr AuReverseIterator operator-(const difference_type offset) const; + + constexpr AuReverseIterator &operator-=(const difference_type offset); + + constexpr reference operator[](const difference_type offset) const; + + constexpr friend bool operator!=(AuReverseIterator a, AuReverseIterator b) + { + return a.base() != b.base(); + } + + constexpr friend bool operator==(AuReverseIterator a, AuReverseIterator b) + { + return a.base() == b.base(); + } + +protected: + Iterator iterator; +}; diff --git a/Include/auROXTL/Iterators/auReverseIterator.ipp b/Include/auROXTL/Iterators/auReverseIterator.ipp new file mode 100644 index 0000000..0b2e15f --- /dev/null +++ b/Include/auROXTL/Iterators/auReverseIterator.ipp @@ -0,0 +1,122 @@ +/*** + Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: auReverseIterator.ipp + Date: 2024-08-31 + Author: Reece +***/ +#pragma once + +template +constexpr AuReverseIterator::AuReverseIterator(Iterator that) + : iterator(AuMove(that)) +{ } + +template +template +constexpr AuReverseIterator::AuReverseIterator(const AuReverseIterator &that) : + iterator(that.iterator) +{ } + +template +template +constexpr AuReverseIterator &AuReverseIterator::operator=(const AuReverseIterator &that) +{ + iterator = that.iterator; + return *this; +} + +template +constexpr Iterator AuReverseIterator::base() const +{ + return iterator; +} + +template +constexpr Iterator AuReverseIterator::Base() const +{ + return iterator; +} + +template +constexpr AuReverseIterator::reference AuReverseIterator::operator*() const +{ + Iterator ret = iterator; + return *--ret; +} + +template +constexpr AuReverseIterator::pointer AuReverseIterator::operator->() const +{ + Iterator ret = iterator; + --ret; + if constexpr (AuIsPointer_v) + { + return ret; + } + else + { + return ret.operator->(); + } +} + +template +constexpr AuReverseIterator &AuReverseIterator::operator++() +{ + --iterator; + return *this; +} + +template +constexpr AuReverseIterator AuReverseIterator::operator++(int) +{ + AuReverseIterator ret = *this; + --iterator; + return ret; +} + +template +constexpr AuReverseIterator &AuReverseIterator::operator--() +{ + ++iterator; + return *this; +} + +template +constexpr AuReverseIterator AuReverseIterator::operator--(int) +{ + AuReverseIterator ret = *this; + ++iterator; + return ret; +} + +template +constexpr AuReverseIterator AuReverseIterator::operator+(const difference_type offset) const +{ + return AuReverseIterator(iterator - offset); +} + +template +constexpr AuReverseIterator &AuReverseIterator::operator+=(const difference_type offset) +{ + iterator -= offset; + return *this; +} + +template +constexpr AuReverseIterator AuReverseIterator::operator-(const difference_type offset) const +{ + return AuReverseIterator(iterator + offset); +} + +template +constexpr AuReverseIterator &AuReverseIterator::operator-=(const difference_type offset) +{ + return *this; +} + +template +constexpr AuReverseIterator::reference AuReverseIterator::operator[](const difference_type offset) const +{ + return iterator[static_cast(-offset - 1)]; +} \ No newline at end of file diff --git a/Include/auROXTL/Iterators/auUTF8Iterator.hpp b/Include/auROXTL/Iterators/auUTF8Iterator.hpp new file mode 100644 index 0000000..5f4402d --- /dev/null +++ b/Include/auROXTL/Iterators/auUTF8Iterator.hpp @@ -0,0 +1,80 @@ +/*** + Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: auUTF8Iterator.hpp + Date: 2024-08-31 + Author: Reece + Notes: UTF8 iterator +***/ +#pragma once + +struct AuUTF8Iterator +{ + using iterator_type = const char *; + using value_type = typename std::iterator_traits::value_type; + using difference_type = typename std::iterator_traits::difference_type; + using pointer = typename std::iterator_traits::pointer; + using reference = typename std::iterator_traits::reference; + + inline constexpr AuUTF8Iterator(); + + inline constexpr AuUTF8Iterator(const AuUTF8Iterator ©); + + inline constexpr AuUTF8Iterator(AuUTF8Iterator &©); + + inline constexpr AuUTF8Iterator &operator =(const AuUTF8Iterator ©); + + inline constexpr AuUTF8Iterator &operator =(AuUTF8Iterator &&move); + + inline AuUTF8Iterator(const char *pStart); + + inline AuUTF8Iterator(const AuROString &in, AuUInt uOffset = AuROString::npos); + + inline AuUTF8Iterator(const AuROString &in); + + cstatic AuUTF8Iterator FromStringView(AuROString in, AuUInt uOffset = AuROString::npos); + + inline constexpr const char *base() const; + + inline constexpr const char *Base() const; + + inline constexpr AuUTF8Iterator end() const; + + inline constexpr AuUTF8Iterator End() const; + + inline constexpr AuOptional operator*() const; + + inline constexpr pointer operator->() const; + + inline constexpr AuUTF8Iterator &operator++(); + + inline constexpr AuUTF8Iterator operator++(int); + + inline constexpr AuUTF8Iterator &operator--(); + + inline constexpr AuUTF8Iterator operator--(int); + + inline constexpr AuUTF8Iterator operator+(const difference_type offset) const; + + inline constexpr AuUTF8Iterator &operator+=(const difference_type offset); + + inline constexpr AuUTF8Iterator operator-(const difference_type offset) const; + + inline constexpr AuUTF8Iterator &operator-=(const difference_type offset); + + inline constexpr AuOptional operator[](const difference_type offset) const; + + inline constexpr friend bool operator!=(AuUTF8Iterator a, AuUTF8Iterator b) + { + return a.base() != b.base(); + } + + inline constexpr friend bool operator==(AuUTF8Iterator a, AuUTF8Iterator b) + { + return a.base() == b.base(); + } + +private: + AuROString baseView {}; + const char *pCurrent {}; +}; diff --git a/Include/auROXTL/Iterators/auUTF8Iterator.ipp b/Include/auROXTL/Iterators/auUTF8Iterator.ipp new file mode 100644 index 0000000..b7683ee --- /dev/null +++ b/Include/auROXTL/Iterators/auUTF8Iterator.ipp @@ -0,0 +1,289 @@ +/*** + Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: auUTF8Iterator.ipp + Date: 2024-08-31 + Author: Reece + Notes: UTF8 iterator +***/ +#pragma once + +inline constexpr AuUTF8Iterator::AuUTF8Iterator() +{ + +} + +inline constexpr AuUTF8Iterator::AuUTF8Iterator(const AuUTF8Iterator ©) : + baseView(copy.baseView), + pCurrent(copy.pCurrent) +{ + +} + +inline constexpr AuUTF8Iterator::AuUTF8Iterator(AuUTF8Iterator &©) : + baseView(copy.baseView), + pCurrent(copy.pCurrent) +{ + +} + +inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator =(const AuUTF8Iterator ©) +{ + this->baseView = copy.baseView; + this->baseView = copy.pCurrent; + return *this; +} + +inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator =(AuUTF8Iterator &&move) +{ + this->baseView = move.baseView; + this->pCurrent = move.pCurrent; + return *this; +} + +inline AuUTF8Iterator::AuUTF8Iterator(const char *pStart) +{ + this->baseView = pStart; + this->pCurrent = pStart; +} + +inline AuUTF8Iterator::AuUTF8Iterator(const AuROString &in, AuUInt uOffset) +{ + this->baseView = in; + this->pCurrent = in.Begin(); + + if (uOffset != AuROString::npos) + { + auto out = AuCodepointsGetByteOffset(in, uOffset); + if (out != AuROString::npos) + { + this->pCurrent += out; + } + else + { + this->pCurrent = in.End(); + } + } +} + +inline AuUTF8Iterator::AuUTF8Iterator(const AuROString &in) +{ + this->baseView = in; + this->pCurrent = in.Begin(); +} + +AuUTF8Iterator AuUTF8Iterator::FromStringView(AuROString in, AuUInt uOffset) +{ + return AuUTF8Iterator(in, uOffset); +} + +inline constexpr const char *AuUTF8Iterator::base() const +{ + return this->pCurrent; +} + +inline constexpr const char *AuUTF8Iterator::Base() const +{ + return this->pCurrent; +} + +inline constexpr AuUTF8Iterator AuUTF8Iterator::end() const +{ + AuUTF8Iterator ret; + ret.baseView = this->baseView; + ret.pCurrent = this->baseView.End(); + return ret; +} + +inline constexpr AuUTF8Iterator AuUTF8Iterator::End() const +{ + AuUTF8Iterator ret; + ret.baseView = this->baseView; + ret.pCurrent = this->baseView.End(); + return ret; +} + +inline constexpr AuOptional AuUTF8Iterator::operator*() const +{ + auto pBegin = this->baseView.Begin(); + auto uDiff = this->pCurrent - pBegin; + auto uLength = this->baseView.Length(); + + if (uLength == uDiff) + { + return {}; + } + + auto pNext = pBegin + uDiff; + auto uNext = uLength - uDiff; + + return AuCodepointsDecodeOne(AuROString(pNext, uNext)); +} + +inline constexpr AuUTF8Iterator::pointer AuUTF8Iterator::operator->() const +{ + return this->base(); +} + +inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator++() +{ + auto pBegin = this->baseView.Begin(); + auto uDiff = this->pCurrent - pBegin; + auto uLength = this->baseView.Length(); + + if (uLength == uDiff) + { + return *this; + } + + auto pNext = pBegin + uDiff; + auto uNext = uLength - uDiff; + + if (auto uCount = AuCodepointsNextLength(AuROString(pNext, uNext))) + { + this->pCurrent += uCount; + } + else + { + *this = this->End(); + } + + return *this; +} + +inline constexpr AuUTF8Iterator AuUTF8Iterator::operator++(int) +{ + AuUTF8Iterator ret = *this; + ++ret; + return ret; +} + +inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator--() +{ + auto pBegin = this->baseView.Begin(); + auto uDiff = this->pCurrent - pBegin; + auto uLength = this->baseView.Length(); + + if (uLength == uDiff) + { + return *this; + } + + { + auto uOffset = AuCodepointsFindPreviousValidByteOffsetFromByteOffset(this->baseView, uDiff); + if (uOffset != AuString::npos) + { + this->pCurrent = pBegin + uOffset; + } + else + { + this->pCurrent = pBegin; + return *this; + } + } + + return *this; +} + +inline constexpr AuUTF8Iterator AuUTF8Iterator::operator--(int) +{ + AuUTF8Iterator ret = *this; + --ret; + return ret; +} + +inline constexpr AuUTF8Iterator AuUTF8Iterator::operator+(const difference_type offset) const +{ + AuUTF8Iterator copy = *this; + copy += offset; + return copy; +} + +inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator+=(const difference_type offset) +{ + auto pBegin = this->baseView.Begin(); + auto uDiff = this->pCurrent - pBegin; + auto uLength = this->baseView.Length(); + + if (uLength == uDiff || + offset == 0) + { + return *this; + } + + if (offset < 0) + { + (*this)-= 0 - offset; + return *this; + } + + auto pNext = pBegin + uDiff; + auto uNext = uLength - uDiff; + + for (AU_ITERATE_N(i, offset)) + { + if (auto uCount = AuCodepointsNextLength(AuROString(pNext, uNext))) + { + pNext += uCount; + uNext -= uCount; + this->pCurrent += uCount; + } + else + { + *this = this->End(); + return *this; + } + } + + return *this; +} + +inline constexpr AuUTF8Iterator AuUTF8Iterator::operator-(const difference_type offset) const +{ + AuUTF8Iterator copy = *this; + copy -= offset; + return copy; +} + +inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator-=(const difference_type offset) +{ + auto pBegin = this->baseView.Begin(); + auto uDiff = this->pCurrent - pBegin; + auto uLength = this->baseView.Length(); + + if (uLength == uDiff || + offset == 0) + { + return *this; + } + + if (offset < 0) + { + (*this)+= 0 - offset; + return *this; + } + + for (AU_ITERATE_N(i, offset)) + { + auto uOffset = AuCodepointsFindPreviousValidByteOffsetFromByteOffset(this->baseView, uDiff); + if (uOffset != AuString::npos) + { + this->pCurrent = pBegin + uOffset; + uDiff = uOffset; + } + else + { + this->pCurrent = pBegin; + return *this; + } + } + + return *this; +} + +inline constexpr AuOptional AuUTF8Iterator::operator[](const difference_type offset) const +{ + auto ret = *this; + ret += offset; + return *ret; +} \ No newline at end of file diff --git a/Include/auROXTL/auUTF8StringView.hpp b/Include/auROXTL/auUTF8StringView.hpp index 9ee9380..a78f01d 100644 --- a/Include/auROXTL/auUTF8StringView.hpp +++ b/Include/auROXTL/auUTF8StringView.hpp @@ -23,1469 +23,8 @@ static auline constexpr bool AuStartsWith(AuROString const &value, AuROString co #include "auMemoryUtils.hpp" -/* read-only, null terminated, utf-8 *byte* view */ -struct AuROString -{ - // using basic_string_view = AuROString; - using basic_string_view = std::basic_string_view; - - using traits_type = typename basic_string_view::traits_type; - - using value_type = char; - using pointer = char *; - using const_pointer = const char *; - using reference = char &; - using const_reference = const char &; - using const_iterator = const char *; - using iterator = char *; - using const_reverse_iterator = typename std::reverse_iterator; - using reverse_iterator = typename std::reverse_iterator; - using size_type = AuUInt; - using difference_type = AuSInt; - - cstatic constexpr size_type npos = size_type(-1); - - inline constexpr AuROString() - { - - } - - AU_COPY_MOVE(AuROString); - - inline constexpr AuROString(const AuString &str) : - pPointer(str.data()), - uLength(str.length()) - { - - } - - inline constexpr AuROString(const std::string &str) : - pPointer(str.data()), - uLength(str.length()) - { - - } - - inline constexpr AuROString(const char *str) : - pPointer(str), - uLength(traits_type::length(str)) - { - - } - - inline constexpr AuROString(const char *str, - AuUInt uLength) : - pPointer(str), - uLength(uLength) - { - - } - inline constexpr AuROString(const char *str, - const char *strEnd) : - pPointer(str), - uLength(strEnd - str) - { - - } - - inline constexpr AuROString(basic_string_view strView) : - pPointer(strView.data()), - uLength(strView.size()) - { - - } - - inline constexpr const_iterator begin() const noexcept - { - return this->cbegin(); - } - - inline constexpr const_iterator cbegin() const noexcept - { - return this->pPointer; - } - - inline constexpr const_iterator end() const noexcept - { - return this->cend(); - } - - inline constexpr const_iterator cend() const noexcept - { - return this->cbegin() + this->length(); - } - - inline constexpr const_reverse_iterator rbegin() const noexcept - { - return this->crbegin(); - } - - inline constexpr const_reverse_iterator crbegin() const noexcept - { - return const_reverse_iterator(this->cend()); - } - - inline constexpr const_reverse_iterator rend() const noexcept - { - return this->crend(); - } - - inline constexpr const_reverse_iterator crend() const noexcept - { - return const_reverse_iterator(this->cbegin()); - } - - inline constexpr AuROString substr(size_type pos1, size_type count1 = npos) const noexcept - { - if (pos1 >= this->uLength) - { - return {}; - } - - if (count1 == npos) - { - return AuROString {this->pPointer + pos1, this->uLength - pos1 }; - } - - if (pos1 + count1 > this->uLength) - { - return {}; - } - - return AuROString { this->pPointer + pos1, count1 }; - } - - inline constexpr void stl_remove_suffix(size_type n) - { - if (this->uLength < n) - { - *this = AuROString { }; - } - else - { - *this = AuROString { this->pPointer, this->uLength - n }; - } - } - - inline constexpr void stl_remove_prefix(size_type n) - { - if (this->uLength < n) - { - *this = AuROString { }; - } - else - { - *this = AuROString { this->pPointer + n, this->uLength - n }; - } - } - - inline constexpr AuROString remove_suffix(size_type n) const - { - if (this->uLength < n) - { - return {}; - } - - return AuROString { this->pPointer, this->uLength - n }; - } - - inline constexpr AuROString remove_prefix(size_type n) const - { - if (this->uLength < n) - { - return {}; - } - - return AuROString { this->pPointer + n, this->uLength - n }; - } - - inline constexpr AuROString RemoveSuffix(size_type n) const - { - return remove_suffix(n); - } - - inline constexpr AuROString RemovePrefix(size_type n) const - { - return remove_prefix(n); - } - - inline constexpr int compare(basic_string_view v) const noexcept - { - if (size() < v.size()) - { - return -1; - } - - int iRet = AuMemcmp(data(), v.data(), v.size()); - - if (size() > v.size() && - iRet == 0) - { - return 1; - } - - return iRet; - } - - inline constexpr int compare(const AuROString &v) const noexcept - { - if (size() < v.size()) - { - return -1; - } - - int iRet = AuMemcmp(data(), v.data(), v.size()); - - if (size() > v.size() && - iRet == 0) - { - return 1; - } - - return iRet; - } - - inline constexpr int compare(size_type pos1, size_type count1, - AuROString v) const - { - return this->substr(pos1, count1).compare(v); - } - - inline constexpr int compare(size_type pos1, size_type count1, AuROString v, - size_type pos2, size_type count2) const - { - return this->substr(pos1, count1).compare(v.substr(pos2, count2)); - } - - inline constexpr int compare(const char *s) const - { - return this->compare(AuROString(s)); - } - - inline constexpr int compare(size_type pos1, size_type count1, - const char *s) const - { - return this->substr(pos1, count1).compare(AuROString(s)); - } - - inline constexpr int compare(size_type pos1, size_type count1, - const char *s, size_type count2) const - { - return this->substr(pos1, count1).compare(AuROString(s, count2)); - } - - inline constexpr bool starts_with(AuROString sv) const noexcept - { - return AuStartsWith(*this, sv); - } - - inline constexpr bool starts_with(char ch) const noexcept - { - return AuStartsWith(*this, AuROString(&ch, 1)); - } - - inline constexpr bool starts_with(const char *s) const - { - return AuStartsWith(*this, s); - } - - inline constexpr bool ends_with(AuROString sv) const noexcept - { - return AuEndsWith(*this, sv); - } - - inline constexpr bool ends_with(char ch) const noexcept - { - return AuEndsWith(*this, AuROString(&ch, 1)); - } - - inline constexpr bool ends_with(const char *s) const - { - return AuEndsWith(*this, s); - } - - inline constexpr bool contains(AuROString sv) const noexcept - { - #if 0 - return AuCodepointsContains(*this, sv); - #else - return AuCodepointsFindByteOffsetUnsafe(*this, sv, 0) != AuROString::npos; - #endif - } - - inline constexpr bool contains(char c) const noexcept - { - return this->contains(AuROString(&c, 1)); - } - - inline constexpr bool contains(const char *s) const - { - return this->contains(AuROString(s)); - } - - inline constexpr const_reference operator[](size_type pos) const - { - return *(this->begin() + pos); - } - - inline constexpr const_reference at(size_type pos) const - { - return this->pPointer[pos]; - } - - inline constexpr const_reference front() const - { - return this->operator[](0); - } - - inline constexpr const_reference back() const - { - return this->operator[](size() - 1); - } - - inline constexpr const_pointer data() const noexcept - { - return &this->operator[](0); - } - - inline constexpr size_type max_size() const noexcept - { - return SIZE_MAX; - //return AuNumericLimits().max(); - } - - inline constexpr size_type size() const noexcept - { - return this->uLength; - } - - inline constexpr size_type length() const noexcept - { - return this->size(); - } - - inline constexpr bool empty() const noexcept - { - return this->size() == 0 || !this->pPointer; - } - - inline constexpr size_type find(AuROString v, size_type pos = 0) const noexcept - { - return AuCodepointsFindByteOffsetUnsafe(*this, v, pos); - } - - inline constexpr size_type find(char ch, size_type pos = 0) const noexcept - { - return this->find(AuROString(&ch, 1), pos); - } - - inline constexpr size_type find(const char *s, size_type pos, size_type count) const - { - return this->find(AuROString(s, count), pos); - } - - inline constexpr size_type find(const char *s, size_type pos = 0) const - { - return this->find(AuROString(s), pos); - } - - inline constexpr size_type rfind(AuROString v, size_type pos = npos) const noexcept - { - return basic_string_view(*this).rfind(basic_string_view { v }, pos); - } - - inline constexpr size_type rfind(char ch, size_type pos = npos) const noexcept - { - return this->find(AuROString(&ch, 1), pos); - } - - inline constexpr size_type rfind(const char *s, size_type pos, size_type count) const - { - return this->rfind(AuROString(s, count), pos); - } - - inline constexpr size_type rfind(const char *s, size_type pos = npos) const - { - return this->rfind(AuROString(s), pos); - } - - inline constexpr size_type find_first_not_of(const AuROString right, const size_type offset = 0) const noexcept - { - return basic_string_view(*this).find_first_not_of(basic_string_view { right }, offset); - } - - inline constexpr size_type find_last_not_of(const AuROString right, const size_type offset = npos) const noexcept - { - return basic_string_view(*this).find_last_not_of(basic_string_view { right }, offset); - } - - inline constexpr size_type find_last_of(const AuROString right, const size_type offset = npos) const noexcept - { - return basic_string_view(*this).find_last_of(basic_string_view { right }, offset); - } - - inline constexpr size_type find_first_of(const AuROString right, const size_type offset = 0) const noexcept - { - if (right.size() == 0) - { - return npos; - } - - return this->find(right, offset); - } - - inline constexpr size_type find_first_of(const char c, const size_type offset = 0) const noexcept - { - return this->find_first_of(AuROString(&c, 1), offset); - } - - inline constexpr size_type find_first_of(const char *const s, const size_type offset, const size_type count) const - { - return this->find_first_of(AuROString(s, count), offset); - } - - inline constexpr size_type find_first_of(const char *const s, const size_type offset = 0) const - { - return this->find_first_of(AuROString(s), offset); - } - - inline constexpr size_type find_last_of(const char c, const size_type offset = npos) const noexcept - { - return this->find_last_of(AuROString(&c, 1), offset); - } - - inline constexpr size_type find_last_of(const char *const s, const size_type offset, const size_type count) const - { - return this->find_last_of(AuROString(s, count), offset); - } - - inline constexpr size_type find_last_of(const char *const s, const size_type offset = npos) const - { - return this->find_last_of(AuROString(s), offset); - } - - inline constexpr size_type find_first_not_of(const char c, const size_type offset = 0) const noexcept - { - return this->find_first_not_of(AuROString(&c, 1), offset); - } - - inline constexpr size_type find_first_not_of(const char *const s, const size_type offset, const size_type count) const - { - return this->find_first_not_of(AuROString(s, count), offset); - } - - inline constexpr size_type find_first_not_of(const char *const s, const size_type offset = 0) const - { - return this->find_first_not_of(AuROString(s), offset); - } - - inline constexpr size_type find_last_not_of(const char c, const size_type offset = npos) const noexcept - { - return this->find_last_not_of(AuROString(&c, 1), offset); - } - - inline constexpr size_type find_last_not_of(const char *const s, const size_type offset, const size_type count) const - { - return this->find_last_not_of(AuROString(s, count), offset); - } - - inline constexpr size_type find_last_not_of(const char *const s, const size_type offset = npos) const - { - return this->find_last_not_of(AuROString(s), offset); - } - - inline constexpr operator std::string_view() const - { - return std::string_view { pPointer, uLength }; - } - - inline constexpr const_iterator Begin() const noexcept - { - return this->begin(); - } - - inline constexpr const_iterator CBegin() const noexcept - { - return this->cbegin(); - } - - inline constexpr const_iterator End() const noexcept - { - return this->end(); - } - - inline constexpr const_iterator CEnd() const noexcept - { - return this->cend(); - } - - inline constexpr const_reverse_iterator RBegin() const noexcept - { - return this->rbegin(); - } - - inline constexpr const_reverse_iterator CRBegin() const noexcept - { - return this->crbegin(); - } - - inline constexpr const_reverse_iterator REnd() const noexcept - { - return this->rend(); - } - - inline constexpr const_reverse_iterator CREnd() const noexcept - { - return this->crend(); - } - - inline constexpr AuROString Substr(size_type pos1, size_type count1 = npos) const noexcept - { - return this->substr(pos1, count1); - } - - inline constexpr AuROString SubStr(size_type pos1, size_type count1 = npos) const noexcept - { - return this->substr(pos1, count1); - } - - inline constexpr int Compare(basic_string_view v) const noexcept - { - return this->compare(v); - } - - inline constexpr int Compare(const AuROString &v) const noexcept - { - return this->compare(v); - } - - inline constexpr int Compare(size_type pos1, size_type count1, - AuROString v) const - { - return this->compare(pos1, count1, v); - } - - inline constexpr int Compare(size_type pos1, size_type count1, AuROString v, - size_type pos2, size_type count2) const - { - return this->compare(pos1, count1, v, pos2, count2); - } - - inline constexpr int Compare(const char *s) const - { - return this->compare(s); - } - - inline constexpr int Compare(size_type pos1, size_type count1, - const char *s) const - { - return this->compare(pos1, count1, s); - } - - inline constexpr int Compare(size_type pos1, size_type count1, - const char *s, size_type count2) const - { - return this->compare(pos1, count1, s, count2); - } - - inline constexpr bool StartsWith(AuROString sv) const noexcept - { - return this->starts_with(sv); - } - - inline constexpr bool StartsWith(char ch) const noexcept - { - return this->starts_with(ch); - } - - inline constexpr bool StartsWith(const char *s) const - { - return this->starts_with(s); - } - - inline constexpr bool EndsWith(AuROString sv) const noexcept - { - return this->ends_with(sv); - } - - inline constexpr bool EndsWith(char ch) const noexcept - { - return this->ends_with(ch); - } - - inline constexpr bool EndsWith(const char *s) const - { - return this->ends_with(s); - } - - inline constexpr bool Contains(AuROString sv) const noexcept - { - return this->contains(sv); - } - - inline constexpr bool Contains(char C) const noexcept - { - return this->contains(C); - } - - inline constexpr bool Contains(const char *s) const - { - return this->contains(s); - } - - inline constexpr const_reference At(size_type pos) const - { - return this->at(pos); - } - - inline constexpr const_reference Front() const - { - return this->front(); - } - - inline constexpr const_reference Back() const - { - return this->back(); - } - - inline constexpr const_pointer Data() const noexcept - { - return this->data(); - } - - inline constexpr size_type MaxSize() const noexcept - { - return this->max_size(); - } - - inline constexpr size_type Size() const noexcept - { - return this->size(); - } - - inline constexpr size_type Length() const noexcept - { - return this->length(); - } - - inline constexpr bool Empty() const noexcept - { - return this->empty(); - } - - inline constexpr size_type Find(AuROString v, size_type pos = 0) const noexcept - { - return this->find(v, pos); - } - - inline constexpr size_type Find(char ch, size_type pos = 0) const noexcept - { - return this->find(ch, pos); - } - - inline constexpr size_type Find(const char *s, size_type pos, size_type count) const - { - return this->find(s, pos, count); - } - - inline constexpr size_type Find(const char *s, size_type pos = 0) const - { - return this->find(s, pos); - } - - inline constexpr size_type RFind(AuROString v, size_type pos = npos) const noexcept - { - return this->rfind(v, pos); - } - - inline constexpr size_type RFind(char ch, size_type pos = npos) const noexcept - { - return this->rfind(ch, pos); - } - - inline constexpr size_type Rfind(const char *s, size_type pos, size_type count) const - { - return this->rfind(s, pos, count); - } - - inline constexpr size_type Rfind(const char *s, size_type pos = npos) const - { - return this->rfind(s, pos); - } - - inline constexpr size_type FindFirstNotOf(const AuROString right, const size_type offset = 0) const noexcept - { - return this->find_first_not_of(right, offset); - } - - inline constexpr size_type FindLastNotOf(const AuROString right, const size_type offset = npos) const noexcept - { - return this->find_last_not_of(right, offset); - } - - inline constexpr size_type FindLastOf(const AuROString right, const size_type offset = npos) const noexcept - { - return this->find_last_of(right, offset); - } - - inline constexpr size_type FindFirstOf(const AuROString right, const size_type offset = 0) const noexcept - { - return this->find_first_of(right, offset); - } - - inline constexpr size_type Find_first_of(const char c, const size_type offset = 0) const noexcept - { - return this->find_first_of(c, offset); - } - - inline constexpr size_type FindFirstOf(const char *const s, const size_type offset, const size_type count) const - { - return this->find_first_of(s, offset, count); - } - - inline constexpr size_type FindFirstOf(const char *const s, const size_type offset = 0) const - { - return this->find_first_of(s, offset); - } - - inline constexpr size_type FindLastOf(const char c, const size_type offset = npos) const noexcept - { - return this->find_last_of(c, offset); - } - - inline constexpr size_type FindLastOf(const char *const s, const size_type offset, const size_type count) const - { - return this->find_last_of(s, offset, count); - } - - inline constexpr size_type FindLastOf(const char *const s, const size_type offset = npos) const - { - return this->find_last_of(s, offset); - } - - inline constexpr size_type FindFirstNotOf(const char c, const size_type offset = 0) const noexcept - { - return this->find_first_not_of(c, offset); - } - - inline constexpr size_type FindFirstNotOf(const char *const s, const size_type offset, const size_type count) const - { - return this->find_first_not_of(s, offset, count); - } - - inline constexpr size_type FindFirstNotOf(const char *const s, const size_type offset = 0) const - { - return this->find_first_not_of(s, offset); - } - - inline constexpr size_type FindLastNotOf(const char c, const size_type offset = npos) const noexcept - { - return this->find_last_not_of(c, offset); - } - - inline constexpr size_type FindLastNotOf(const char *const s, const size_type offset, const size_type count) const - { - return this->find_last_not_of(s, offset, count); - } - - inline constexpr size_type FindLastNotOf(const char *const s, const size_type offset = npos) const - { - return this->find_last_not_of(s, offset); - } - - inline operator bool() const - { - return this->pPointer && - this->uLength; - } - -private: - const char *pPointer {}; - AuUInt uLength {}; -}; - -/* read-only, null terminated, utf-8 *byte* view */ -struct AuRONString -{ - using traits_type = typename AuROString::traits_type; - using value_type = typename AuROString::value_type; - using pointer = typename AuROString::pointer; - using const_pointer = typename AuROString::const_pointer; - using reference = typename AuROString::reference; - using const_reference = typename AuROString::const_reference; - using const_iterator = typename AuROString::const_iterator; - using iterator = const_iterator; - using const_reverse_iterator = typename AuROString::const_reverse_iterator; - using reverse_iterator = const_reverse_iterator; - using size_type = typename AuROString::size_type; - using difference_type = typename AuROString::difference_type; - - // using basic_string_view = AuROString; - using basic_string_view = std::basic_string_view; - - cstatic constexpr size_type npos = size_type(-1); - - - inline AuRONString(const AuString &str) : - view(str) - { - - } - - inline AuRONString(const std::string &str) : - view(str) - { - - } - - inline AuRONString(const char *str) : - view(str) - { - - } - - inline constexpr const_iterator begin() const noexcept - { - return this->cbegin(); - } - - inline constexpr const_iterator cbegin() const noexcept - { - return this->view.cbegin(); - } - - inline constexpr const_iterator end() const noexcept - { - return this->cend(); - } - - inline constexpr const_iterator cend() const noexcept - { - return this->cbegin() + this->length(); - } - - inline constexpr const_reverse_iterator rbegin() const noexcept - { - return this->crbegin(); - } - - inline constexpr const_reverse_iterator crbegin() const noexcept - { - return const_reverse_iterator(this->cend()); - } - - inline constexpr const_reverse_iterator rend() const noexcept - { - return this->crend(); - } - - inline constexpr const_reverse_iterator crend() const noexcept - { - return const_reverse_iterator(this->cbegin()); - } - - inline constexpr int compare(AuROString v) const noexcept - { - if (size() < v.size()) - { - return -1; - } - - int iRet = AuMemcmp(data(), v.data(), v.size()); - - if (size() > v.size() && - iRet == 0) - { - return 1; - } - - return iRet; - } - - inline constexpr int compare(size_type pos1, size_type count1, - AuROString v) const - { - return this->view.substr(pos1, count1).compare(v); - } - - inline constexpr int compare(size_type pos1, size_type count1, AuROString v, - size_type pos2, size_type count2) const - { - return this->view.substr(pos1, count1).compare(v.substr(pos2, count2)); - } - - inline constexpr int compare(const char *s) const - { - return this->compare(AuROString(s)); - } - - inline constexpr int compare(size_type pos1, size_type count1, - const char *s) const - { - return this->view.substr(pos1, count1).compare(AuROString(s)); - } - - inline constexpr int compare(size_type pos1, size_type count1, - const char *s, size_type count2) const - { - return this->view.substr(pos1, count1).compare(AuROString(s, count2)); - } - - inline constexpr bool starts_with(AuROString sv) const noexcept - { - return AuStartsWith(*this, sv); - } - - inline constexpr bool starts_with(char ch) const noexcept - { - return AuStartsWith(*this, AuROString(&ch, 1)); - } - - inline constexpr bool starts_with(const char *s) const - { - return AuStartsWith(*this, s); - } - - inline constexpr bool ends_with(AuROString sv) const noexcept - { - return AuEndsWith(*this, sv); - } - - inline constexpr bool ends_with(char ch) const noexcept - { - return AuEndsWith(*this, AuROString(&ch, 1)); - } - - inline constexpr bool ends_with(const char *s) const - { - return AuEndsWith(*this, s); - } - - inline constexpr bool contains(AuROString sv) const noexcept - { - #if 0 - return AuCodepointsContains(*this, sv); - #else - return AuCodepointsFindByteOffsetUnsafe(*this, sv, 0) != AuROString::npos; - #endif - } - - inline constexpr bool contains(char c) const noexcept - { - return this->contains(AuROString(&c, 1)); - } - - inline constexpr bool contains(const char *s) const - { - return this->contains(AuROString(s)); - } - - inline constexpr const_reference operator[](size_type pos) const - { - return *(this->begin() + pos); - } - - inline constexpr const_reference at(size_type pos) const - { - return this->view.at(pos); - } - - inline constexpr const_reference front() const - { - return this->operator[](0); - } - - inline constexpr const_reference back() const - { - return this->operator[](size() - 1); - } - - inline constexpr const_pointer data() const noexcept - { - return &this->operator[](0); - } - - inline constexpr const_pointer c_str() const noexcept - { - return this->data(); - } - - inline constexpr size_type max_size() const noexcept - { - return this->view.max_size(); - } - - inline constexpr size_type size() const noexcept - { - return this->view.size(); - } - - inline constexpr size_type length() const noexcept - { - return this->size(); - } - - inline constexpr bool empty() const noexcept - { - return this->size() == 0 || !this->view.data(); - } - - inline constexpr AuROString substr(size_type pos1, size_type count1 = npos) const noexcept - { - if (pos1 >= this->size()) - { - return {}; - } - - if (count1 == npos) - { - return AuROString {this->data() + pos1, this->size() - pos1 }; - } - - if (pos1 + count1 > this->size()) - { - return {}; - } - - return AuROString { this->data() + pos1, count1 }; - } - - inline constexpr size_type find(AuROString v, size_type pos = 0) const noexcept - { - return AuCodepointsFindByteOffsetUnsafe(*this, v, pos); - } - - inline constexpr size_type find(char ch, size_type pos = 0) const noexcept - { - return this->find(AuROString(&ch, 1), pos); - } - - inline constexpr size_type find(const char *s, size_type pos, size_type count) const - { - return this->find(AuROString(s, count), pos); - } - - inline constexpr size_type find(const char *s, size_type pos = 0) const - { - return this->find(AuROString(s), pos); - } - - inline constexpr size_type rfind(AuROString v, size_type pos = npos) const noexcept - { - return this->view.rfind(v, pos); - } - - inline constexpr size_type rfind(char ch, size_type pos = npos) const noexcept - { - return this->find(AuROString(&ch, 1), pos); - } - - inline constexpr size_type rfind(const char *s, size_type pos, size_type count) const - { - return this->rfind(AuROString(s, count), pos); - } - - inline constexpr size_type rfind(const char *s, size_type pos = npos) const - { - return this->rfind(AuROString(s), pos); - } - - inline constexpr size_type find_first_not_of(AuROString right, const size_type offset = 0) const noexcept - { - return this->view.find_first_not_of(right, offset); - } - - inline constexpr size_type find_last_not_of(AuROString right, const size_type offset = npos) const noexcept - { - return this->view.find_last_not_of(right, offset); - } - - inline constexpr size_type find_last_of(AuROString right, const size_type offset = npos) const noexcept - { - return this->view.find_last_of(right, offset); - } - - inline constexpr size_type find_first_of(AuROString right, const size_type offset = 0) const noexcept - { - if (right.size() == 0) - { - return npos; - } - - return this->find(right, offset); - } - - inline constexpr size_type find_first_of(const char c, const size_type offset = 0) const noexcept - { - return this->find_first_of(AuROString(&c, 1), offset); - } - - inline constexpr size_type find_first_of(const char *const s, const size_type offset, const size_type count) const - { - return this->find_first_of(AuROString(s, count), offset); - } - - inline constexpr size_type find_first_of(const char *const s, const size_type offset = 0) const - { - return this->find_first_of(AuROString(s), offset); - } - - inline constexpr size_type find_last_of(const char c, const size_type offset = npos) const noexcept - { - return this->find_last_of(AuROString(&c, 1), offset); - } - - inline constexpr size_type find_last_of(const char *const s, const size_type offset, const size_type count) const - { - return this->find_last_of(AuROString(s, count), offset); - } - - inline constexpr size_type find_last_of(const char *const s, const size_type offset = npos) const - { - return this->find_last_of(AuROString(s), offset); - } - - inline constexpr size_type find_first_not_of(const char c, const size_type offset = 0) const noexcept - { - return this->find_first_not_of(AuROString(&c, 1), offset); - } - - inline constexpr size_type find_first_not_of(const char *const s, const size_type offset, const size_type count) const - { - return this->find_first_not_of(AuROString(s, count), offset); - } - - inline constexpr size_type find_first_not_of(const char *const s, const size_type offset = 0) const - { - return this->find_first_not_of(AuROString(s), offset); - } - - inline constexpr size_type find_last_not_of(const char c, const size_type offset = npos) const noexcept - { - return this->find_last_not_of(AuROString(&c, 1), offset); - } - - inline constexpr size_type find_last_not_of(const char *const s, const size_type offset, const size_type count) const - { - return this->find_last_not_of(AuROString(s, count), offset); - } - - inline constexpr size_type find_last_not_of(const char *const s, const size_type offset = npos) const - { - return this->find_last_not_of(AuROString(s), offset); - } - - inline constexpr operator AuROString() const - { - return this->view; - } - - inline operator bool() const - { - return this->view; - } - - inline constexpr const_iterator Begin() const noexcept - { - return this->begin(); - } - - inline constexpr const_iterator CBegin() const noexcept - { - return this->cbegin(); - } - - inline constexpr const_iterator End() const noexcept - { - return this->end(); - } - - inline constexpr const_iterator CEnd() const noexcept - { - return this->cend(); - } - - inline constexpr const_reverse_iterator RBegin() const noexcept - { - return this->rbegin(); - } - - inline constexpr const_reverse_iterator CRBegin() const noexcept - { - return this->crbegin(); - } - - inline constexpr const_reverse_iterator REnd() const noexcept - { - return this->rend(); - } - - inline constexpr const_reverse_iterator CREnd() const noexcept - { - return this->crend(); - } - - inline constexpr AuROString Substr(size_type pos1, size_type count1 = npos) const noexcept - { - return this->substr(pos1, count1); - } - - inline constexpr AuROString SubStr(size_type pos1, size_type count1 = npos) const noexcept - { - return this->substr(pos1, count1); - } - - inline constexpr int Compare(AuROString v) const noexcept - { - return this->compare(v); - } - - inline constexpr int Compare(const AuROString &v) const noexcept - { - return this->compare(v); - } - - inline constexpr int Compare(size_type pos1, size_type count1, - AuROString v) const - { - return this->compare(pos1, count1, v); - } - - inline constexpr int Compare(size_type pos1, size_type count1, AuROString v, - size_type pos2, size_type count2) const - { - return this->compare(pos1, count1, v, pos2, count2); - } - - inline constexpr int Compare(const char *s) const - { - return this->compare(s); - } - - inline constexpr int Compare(size_type pos1, size_type count1, - const char *s) const - { - return this->compare(pos1, count1, s); - } - - inline constexpr int Compare(size_type pos1, size_type count1, - const char *s, size_type count2) const - { - return this->compare(pos1, count1, s, count2); - } - - inline constexpr bool StartsWith(AuROString sv) const noexcept - { - return this->starts_with(sv); - } - - inline constexpr bool StartsWith(char ch) const noexcept - { - return this->starts_with(ch); - } - - inline constexpr bool StartsWith(const char *s) const - { - return this->starts_with(s); - } - - inline constexpr bool EndsWith(AuROString sv) const noexcept - { - return this->ends_with(sv); - } - - inline constexpr bool EndsWith(char ch) const noexcept - { - return this->ends_with(ch); - } - - inline constexpr bool EndsWith(const char *s) const - { - return this->ends_with(s); - } - - inline constexpr bool Contains(AuROString sv) const noexcept - { - return this->contains(sv); - } - - inline constexpr bool Contains(char C) const noexcept - { - return this->contains(C); - } - - inline constexpr bool Contains(const char *s) const - { - return this->contains(s); - } - - inline constexpr const_reference At(size_type pos) const - { - return this->at(pos); - } - - inline constexpr const_reference Front() const - { - return this->front(); - } - - inline constexpr const_reference Back() const - { - return this->back(); - } - - inline constexpr const_pointer Data() const noexcept - { - return this->data(); - } - - inline constexpr const_pointer CStr() const noexcept - { - return this->c_str(); - } - - inline constexpr size_type MaxSize() const noexcept - { - return this->max_size(); - } - - inline constexpr size_type Size() const noexcept - { - return this->size(); - } - - inline constexpr size_type Length() const noexcept - { - return this->length(); - } - - inline constexpr bool Empty() const noexcept - { - return this->empty(); - } - - inline constexpr size_type Find(AuROString v, size_type pos = 0) const noexcept - { - return this->find(v, pos); - } - - inline constexpr size_type Find(char ch, size_type pos = 0) const noexcept - { - return this->find(ch, pos); - } - - inline constexpr size_type Find(const char *s, size_type pos, size_type count) const - { - return this->find(s, pos, count); - } - - inline constexpr size_type Find(const char *s, size_type pos = 0) const - { - return this->find(s, pos); - } - - inline constexpr size_type RFind(AuROString v, size_type pos = npos) const noexcept - { - return this->rfind(v, pos); - } - - inline constexpr size_type RFind(char ch, size_type pos = npos) const noexcept - { - return this->rfind(ch, pos); - } - - inline constexpr size_type Rfind(const char *s, size_type pos, size_type count) const - { - return this->rfind(s, pos, count); - } - - inline constexpr size_type Rfind(const char *s, size_type pos = npos) const - { - return this->rfind(s, pos); - } - - inline constexpr size_type FindFirstNotOf(const AuROString right, const size_type offset = 0) const noexcept - { - return this->find_first_not_of(right, offset); - } - - inline constexpr size_type FindLastNotOf(const AuROString right, const size_type offset = npos) const noexcept - { - return this->find_last_not_of(right, offset); - } - - inline constexpr size_type FindLastOf(const AuROString right, const size_type offset = npos) const noexcept - { - return this->find_last_of(right, offset); - } - - inline constexpr size_type FindFirstOf(const AuROString right, const size_type offset = 0) const noexcept - { - return this->find_first_of(right, offset); - } - - inline constexpr size_type Find_first_of(const char c, const size_type offset = 0) const noexcept - { - return this->find_first_of(c, offset); - } - - inline constexpr size_type FindFirstOf(const char *const s, const size_type offset, const size_type count) const - { - return this->find_first_of(s, offset, count); - } - - inline constexpr size_type FindFirstOf(const char *const s, const size_type offset = 0) const - { - return this->find_first_of(s, offset); - } - - inline constexpr size_type FindLastOf(const char c, const size_type offset = npos) const noexcept - { - return this->find_last_of(c, offset); - } - - inline constexpr size_type FindLastOf(const char *const s, const size_type offset, const size_type count) const - { - return this->find_last_of(s, offset, count); - } - - inline constexpr size_type FindLastOf(const char *const s, const size_type offset = npos) const - { - return this->find_last_of(s, offset); - } - - inline constexpr size_type FindFirstNotOf(const char c, const size_type offset = 0) const noexcept - { - return this->find_first_not_of(c, offset); - } - - inline constexpr size_type FindFirstNotOf(const char *const s, const size_type offset, const size_type count) const - { - return this->find_first_not_of(s, offset, count); - } - - inline constexpr size_type FindFirstNotOf(const char *const s, const size_type offset = 0) const - { - return this->find_first_not_of(s, offset); - } - - inline constexpr size_type FindLastNotOf(const char c, const size_type offset = npos) const noexcept - { - return this->find_last_not_of(c, offset); - } - - inline constexpr size_type FindLastNotOf(const char *const s, const size_type offset, const size_type count) const - { - return this->find_last_not_of(s, offset, count); - } - - inline constexpr size_type FindLastNotOf(const char *const s, const size_type offset = npos) const - { - return this->find_last_not_of(s, offset); - } -private: - AuROString view; -}; +#include "Iterators/auROString.hpp" +#include "Iterators/auRONString.hpp" inline constexpr bool operator==(const AuROString &lhs, const AuROString &rhs) noexcept diff --git a/Include/auROXTLTypes.hpp b/Include/auROXTLTypes.hpp index bbd5934..246268d 100644 --- a/Include/auROXTLTypes.hpp +++ b/Include/auROXTLTypes.hpp @@ -38,6 +38,7 @@ #include #include #include +#include // TODO: move to header // this needs to be after template mater and before containers and optional @@ -169,6 +170,7 @@ namespace __audetail #include #include #include +#include namespace Aurora::Memory { diff --git a/Include/auROXTLUtils.hpp b/Include/auROXTLUtils.hpp index 9a832a7..1707635 100644 --- a/Include/auROXTLUtils.hpp +++ b/Include/auROXTLUtils.hpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include #include