From ac70990fa0c0f5ef4fc09e56833d7cd19c78fca8 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Fri, 1 Nov 2019 17:10:11 -0600 Subject: [PATCH] Add Slice functions to U8Strings --- src/LibHac/Common/U8Span.cs | 10 ++++++++++ src/LibHac/Common/U8SpanMutable.cs | 10 ++++++++++ src/LibHac/Common/U8String.cs | 10 ++++++++++ src/LibHac/Common/U8StringMutable.cs | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/LibHac/Common/U8Span.cs b/src/LibHac/Common/U8Span.cs index c58aa3e7..c504d556 100644 --- a/src/LibHac/Common/U8Span.cs +++ b/src/LibHac/Common/U8Span.cs @@ -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(U8Span value) => value.Value; public static explicit operator string(U8Span value) => value.ToString(); diff --git a/src/LibHac/Common/U8SpanMutable.cs b/src/LibHac/Common/U8SpanMutable.cs index d0edcfa1..3570d7ab 100644 --- a/src/LibHac/Common/U8SpanMutable.cs +++ b/src/LibHac/Common/U8SpanMutable.cs @@ -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(U8SpanMutable value) => value.Value; diff --git a/src/LibHac/Common/U8String.cs b/src/LibHac/Common/U8String.cs index df952cf5..e7d27a99 100644 --- a/src/LibHac/Common/U8String.cs +++ b/src/LibHac/Common/U8String.cs @@ -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(U8String value) => value.Value; diff --git a/src/LibHac/Common/U8StringMutable.cs b/src/LibHac/Common/U8StringMutable.cs index 2bb7c75b..2a0d659b 100644 --- a/src/LibHac/Common/U8StringMutable.cs +++ b/src/LibHac/Common/U8StringMutable.cs @@ -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);