1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Index + range support

This commit is contained in:
Brian Fiete 2021-10-24 08:36:26 -07:00
parent 05a65287d3
commit 66eacca775

View file

@ -1010,17 +1010,95 @@ namespace System
public ref char8 this[int index]
{
[Checked]
get
{
Debug.Assert((uint)index < (uint)mLength);
return ref Ptr[index];
}
[Unchecked, Inline]
get
{
return ref Ptr[index];
}
[Checked]
set
{
Debug.Assert((uint)index < (uint)mLength);
Ptr[index] = value;
}
[Unchecked, Inline]
set
{
Ptr[index] = value;
}
}
public ref char8 this[Index index]
{
[Checked]
get
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mLength - 1 - offset;
}
Debug.Assert((uint)idx < (uint)mLength);
return ref Ptr[idx];
}
[Unchecked, Inline]
get
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mLength - 1 - offset;
}
return ref Ptr[idx];
}
[Checked]
set
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mLength - 1 - offset;
}
Debug.Assert((uint)idx < (uint)mLength);
Ptr[idx] = value;
}
[Unchecked, Inline]
set
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mLength - 1 - offset;
}
Ptr[idx] = value;
}
}
public StringView this[IndexRange range]
{
#if !DEBUG
[Inline]
#endif
get
{
return StringView(Ptr, Length)[range];
}
}
public void Concat(params Object[] objects)
@ -2891,6 +2969,97 @@ namespace System
mLength = length;
}
public ref char8 this[int index]
{
[Checked]
get
{
Runtime.Assert((uint)index < (uint)mLength);
return ref mPtr[index];
}
[Unchecked, Inline]
get
{
return ref mPtr[index];
}
}
public ref char8 this[Index index]
{
[Checked]
get
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mLength - 1 - offset;
}
Runtime.Assert((uint)idx < (uint)mLength);
return ref mPtr[idx];
}
[Unchecked, Inline]
get
{
int idx;
switch (index)
{
case .FromFront(let offset): idx = offset;
case .FromEnd(let offset): idx = mLength - 1 - offset;
}
return ref mPtr[idx];
}
}
public StringView this[IndexRange range]
{
#if !DEBUG
[Inline]
#endif
get
{
char8* start;
switch (range.mStart)
{
case .FromFront(let offset):
Debug.Assert((uint)offset <= (uint)mLength);
start = mPtr + offset;
case .FromEnd(let offset):
Debug.Assert((uint)offset <= (uint)mLength);
start = mPtr + mLength - 1 - offset;
}
char8* end;
if (range.mIsClosed)
{
switch (range.mEnd)
{
case .FromFront(let offset):
Debug.Assert((uint)offset < (uint)mLength);
end = mPtr + offset + 1;
case .FromEnd(let offset):
Debug.Assert((uint)offset < (uint)mLength);
end = mPtr + mLength - offset;
}
}
else
{
switch (range.mEnd)
{
case .FromFront(let offset):
Debug.Assert((uint)offset <= (uint)mLength);
end = mPtr + offset;
case .FromEnd(let offset):
Debug.Assert((uint)offset <= (uint)mLength);
end = mPtr + mLength - 1 - offset;
}
}
return .(start, end - start);
}
}
public String.RawEnumerator RawChars
{
get