Add Slice functions to U8Strings

This commit is contained in:
Alex Barney 2019-11-01 17:10:11 -06:00
parent a6161e693c
commit ac70990fa0
4 changed files with 40 additions and 0 deletions

View file

@ -27,6 +27,16 @@ namespace LibHac.Common
_buffer = Encoding.UTF8.GetBytes(value);
}
public U8Span Slice(int start)
{
return new U8Span(_buffer.Slice(start));
}
public U8Span Slice(int start, int length)
{
return new U8Span(_buffer.Slice(start, length));
}
public static implicit operator ReadOnlySpan<byte>(U8Span value) => value.Value;
public static explicit operator string(U8Span value) => value.ToString();

View file

@ -28,6 +28,16 @@ namespace LibHac.Common
_buffer = Encoding.UTF8.GetBytes(value);
}
public U8SpanMutable Slice(int start)
{
return new U8SpanMutable(_buffer.Slice(start));
}
public U8SpanMutable Slice(int start, int length)
{
return new U8SpanMutable(_buffer.Slice(start, length));
}
public static implicit operator U8Span(U8SpanMutable value) => new U8Span(value._buffer);
public static implicit operator ReadOnlySpan<byte>(U8SpanMutable value) => value.Value;

View file

@ -24,6 +24,16 @@ namespace LibHac.Common
_buffer = Encoding.UTF8.GetBytes(value);
}
public U8String Slice(int start)
{
return new U8String(_buffer.AsSpan(start).ToArray());
}
public U8String Slice(int start, int length)
{
return new U8String(_buffer.AsSpan(start, length).ToArray());
}
public static implicit operator U8Span(U8String value) => new U8Span(value._buffer);
public static implicit operator ReadOnlySpan<byte>(U8String value) => value.Value;

View file

@ -28,6 +28,16 @@ namespace LibHac.Common
_buffer = Encoding.UTF8.GetBytes(value);
}
public U8StringMutable Slice(int start)
{
return new U8StringMutable(_buffer.AsSpan(start).ToArray());
}
public U8StringMutable Slice(int start, int length)
{
return new U8StringMutable(_buffer.AsSpan(start, length).ToArray());
}
public static implicit operator U8String(U8StringMutable value) => new U8String(value._buffer);
public static implicit operator U8SpanMutable(U8StringMutable value) => new U8SpanMutable(value._buffer);
public static implicit operator U8Span(U8StringMutable value) => new U8Span(value._buffer);