mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2025-09-10 14:06:27 -05:00
Implement NGC service (#5681)
* Implement NGC service * Use raw byte arrays instead of string for _wordSeparators * Silence IDE0230 for _wordSeparators * Try to silence warning about _rangeValuesCount not being read on SparseSet * Make AcType enum private * Add abstract methods and one TODO that I forgot * PR feedback * More PR feedback * More PR feedback
This commit is contained in:
41
src/Ryujinx.Horizon/Sdk/Ngc/Detail/Utf8Util.cs
Normal file
41
src/Ryujinx.Horizon/Sdk/Ngc/Detail/Utf8Util.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.Horizon.Sdk.Ngc.Detail
|
||||
{
|
||||
static class Utf8Util
|
||||
{
|
||||
public static Utf8ParseResult NormalizeFormKC(Span<byte> output, ReadOnlySpan<byte> input)
|
||||
{
|
||||
int length = input.IndexOf((byte)0);
|
||||
if (length >= 0)
|
||||
{
|
||||
input = input[..length];
|
||||
}
|
||||
|
||||
UTF8Encoding encoding = new(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
|
||||
|
||||
string text;
|
||||
|
||||
try
|
||||
{
|
||||
text = encoding.GetString(input);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return Utf8ParseResult.InvalidCharacter;
|
||||
}
|
||||
|
||||
string normalizedText = text.Normalize(NormalizationForm.FormKC);
|
||||
|
||||
int outputIndex = Encoding.UTF8.GetBytes(normalizedText, output);
|
||||
|
||||
if (outputIndex < output.Length)
|
||||
{
|
||||
output[outputIndex] = 0;
|
||||
}
|
||||
|
||||
return Utf8ParseResult.Success;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user