[*] Remove redundant constructor from UTF8 iterator

[+] Missing members on AuArray
This commit is contained in:
Reece Wilson 2024-09-01 19:43:22 +01:00
parent 52f3ca8026
commit 76e60d99e8
6 changed files with 183 additions and 27 deletions

View File

@ -8,8 +8,6 @@
***/
#pragma once
/* read-only, null terminated, utf-8 *byte* view */
struct AuRONString
{

View File

@ -23,8 +23,8 @@ struct AuROString
using const_reference = const char &;
using const_iterator = const char *;
using iterator = char *;
using const_reverse_iterator = typename std::reverse_iterator<const char *>;
using reverse_iterator = typename std::reverse_iterator<char *>;
using const_reverse_iterator = typename AuReverseIterator<const char *>;
using reverse_iterator = typename AuReverseIterator<char *>;
using size_type = AuUInt;
using difference_type = AuSInt;

View File

@ -8,8 +8,8 @@
#pragma once
template<typename Iterator>
constexpr AuReverseIterator<Iterator>::AuReverseIterator(Iterator that)
: iterator(AuMove(that))
constexpr AuReverseIterator<Iterator>::AuReverseIterator(Iterator that) :
iterator(AuMove(that))
{ }
template<typename Iterator>

View File

@ -30,8 +30,6 @@ struct AuUTF8Iterator
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;

View File

@ -50,7 +50,7 @@ inline AuUTF8Iterator::AuUTF8Iterator(const char *pStart)
inline AuUTF8Iterator::AuUTF8Iterator(const AuROString &in, AuUInt uOffset)
{
this->baseView = in;
this->pCurrent = in.Begin();
this->pCurrent = in.Begin();
if (uOffset != AuROString::npos)
{
@ -66,12 +66,6 @@ inline AuUTF8Iterator::AuUTF8Iterator(const AuROString &in, AuUInt uOffset)
}
}
inline AuUTF8Iterator::AuUTF8Iterator(const AuROString &in)
{
this->baseView = in;
this->pCurrent = in.Begin();
}
AuUTF8Iterator AuUTF8Iterator::FromStringView(AuROString in, AuUInt uOffset)
{
return AuUTF8Iterator(in, uOffset);
@ -220,7 +214,7 @@ inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator+=(const difference_typ
auto pNext = pBegin + uDiff;
auto uNext = uLength - uDiff;
for (AU_ITERATE_N(i, offset))
for (AU_ITERATE_N(i, AuUInt(offset)))
{
if (auto uCount = AuCodepointsNextLength(AuROString(pNext, uNext)))
{
@ -263,7 +257,7 @@ inline constexpr AuUTF8Iterator &AuUTF8Iterator::operator-=(const difference_typ
return *this;
}
for (AU_ITERATE_N(i, offset))
for (AU_ITERATE_N(i, AuUInt(offset)))
{
auto uOffset = AuCodepointsFindPreviousValidByteOffsetFromByteOffset(this->baseView, uDiff);
if (uOffset != AuString::npos)

View File

@ -19,19 +19,22 @@ struct AuArray
static const AuUInt kElementCount = Count;
using value_type = T;
using value_type = T;
using size_type = AuUInt;
using difference_type = AuSInt;
using size_type = AuUInt;
using difference_type = AuSInt;
using pointer = value_type *;
using const_pointer = const value_type *;
using pointer = value_type *;
using const_pointer = const value_type *;
using reference = value_type &;
using const_reference = const value_type &;
using reference = value_type &;
using const_reference = const value_type &;
using iterator = pointer;
using const_iterator = const_pointer;
using iterator = pointer;
using const_iterator = const_pointer;
using reverse_iterator = typename AuReverseIterator<iterator>;
using const_reverse_iterator = typename AuReverseIterator<const_iterator>;
void fill(const T &value)
{
@ -48,11 +51,16 @@ struct AuArray
}
}
void Fill(const T &value)
{
this->fill(value);
}
void swap(AuArray &other)
{
AuArray temp;
if constexpr (std::is_trivially_copyable_v<T>)
if constexpr (AuIsTriviallyCopyable_v<T>)
{
AuMemcpy(temp, this->elements, sizeof(this->elements));
AuMemcpy(this->elements, other.elements, sizeof(this->elements));
@ -78,6 +86,11 @@ struct AuArray
}
}
void Swap(AuArray &other)
{
this->swap(other);
}
constexpr iterator begin()
{
return this->elements;
@ -88,6 +101,16 @@ struct AuArray
return this->elements;
}
constexpr iterator Begin()
{
return this->elements;
}
constexpr const_iterator Begin() const
{
return this->elements;
}
constexpr iterator end()
{
return this->elements + kElementCount;
@ -98,6 +121,16 @@ struct AuArray
return this->elements + kElementCount;
}
constexpr iterator End()
{
return this->elements + kElementCount;
}
constexpr const_iterator End() const
{
return this->elements + kElementCount;
}
constexpr const_iterator cbegin() const
{
return begin();
@ -108,21 +141,101 @@ struct AuArray
return end();
}
constexpr const_iterator CBegin() const
{
return begin();
}
constexpr const_iterator CEnd() const
{
return end();
}
constexpr const_reverse_iterator rbegin() const
{
return reverse_iterator(end());
}
constexpr reverse_iterator RBegin()
{
return reverse_iterator(end());
}
constexpr const_reverse_iterator RBegin() const
{
return const_reverse_iterator(end());
}
constexpr reverse_iterator rend()
{
return reverse_iterator(begin());
}
constexpr const_reverse_iterator rend() const
{
return reverse_iterator(begin());
}
constexpr reverse_iterator REnd()
{
return const_reverse_iterator(begin());
}
constexpr const_reverse_iterator REnd() const
{
return const_reverse_iterator(begin());
}
constexpr const_reverse_iterator crbegin() const
{
return const_reverse_iterator(end());
}
constexpr const_reverse_iterator crend() const
{
return const_reverse_iterator(begin());
}
constexpr const_reverse_iterator CRBegin() const
{
return const_reverse_iterator(end());
}
constexpr const_reverse_iterator CREnd() const
{
return const_reverse_iterator(begin());
}
constexpr size_type size() const
{
return kElementCount;
}
constexpr size_type Size() const
{
return kElementCount;
}
constexpr size_type max_size() const
{
return kElementCount;
}
constexpr size_type MaxSize() const
{
return kElementCount;
}
constexpr bool empty() const
{
return false;
}
constexpr bool Empty() const
{
return false;
}
reference at(size_type pos)
{
#if defined(AU_CFG_ID_DEBUG)
@ -146,6 +259,29 @@ struct AuArray
return this->elements[pos];
}
reference At(size_type pos)
{
#if defined(AU_CFG_ID_DEBUG)
if (pos >= kElementCount)
{
AuMemoryPanic("out of bounds access");
}
#endif
return this->elements[pos];
}
constexpr const_reference At(size_type pos) const
{
#if defined(AU_CFG_ID_DEBUG)
if (pos >= kElementCount)
{
AuMemoryPanic("out of bounds access");
}
#endif
return this->elements[pos];
}
reference operator[](size_type pos)
{
#if defined(AU_CFG_ID_DEBUG)
@ -190,6 +326,26 @@ struct AuArray
return this->elements[Count - 1];
}
constexpr reference Front()
{
return this->elements[0];
}
constexpr const_reference Front() const
{
return this->elements[0];
}
constexpr reference Back()
{
return this->elements[Count - 1];
}
constexpr const_reference Back() const
{
return this->elements[Count - 1];
}
constexpr T *data()
{
return this->elements;
@ -200,6 +356,16 @@ struct AuArray
return this->elements;
}
constexpr T *Data()
{
return this->elements;
}
constexpr const T *Data() const
{
return this->elements;
}
// oh look, its that feature in that nearly 30 year old programming language intended to replace xerox alto's OOP language for the internet era.
AuUInt HashCode() const
{