Skip to content

Includes type forwarding for System.Text.Unicode.Utf8 to the Microsoft.Bcl.Memory library #111292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);MICROSOFT_BCL_MEMORY</DefineConstants>
<IsPackable>true</IsPackable>
<PackageDescription>Provides Base64Url, Utf8, Index and Range types support for .NET Framework and .NET Standard.</PackageDescription>
<PackageDescription>Provides Base64Url, Utf8, Index, and Range types support for .NET Framework and .NET Standard.</PackageDescription>
</PropertyGroup>

<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ public int EncodeToUtf8(Span<byte> destination)

public override int GetHashCode() => Value;

#if !MICROSOFT_BCL_MEMORY
#if SYSTEM_PRIVATE_CORELIB
/// <summary>
/// Gets the <see cref="Rune"/> which begins at index <paramref name="index"/> in
/// string <paramref name="input"/>.
Expand Down Expand Up @@ -852,7 +852,7 @@ internal static int ReadFirstRuneFromUtf16Buffer(ReadOnlySpan<char> input)
return (int)returnValue;
}

#if !MICROSOFT_BCL_MEMORY
#if SYSTEM_PRIVATE_CORELIB
// returns a negative number on failure
private static int ReadRuneFromString(string input, int index)
{
Expand Down Expand Up @@ -1132,7 +1132,7 @@ private static bool TryEncodeToUtf8(Rune value, Span<byte> destination, out int
return false;
}

#if !MICROSOFT_BCL_MEMORY
#if SYSTEM_PRIVATE_CORELIB
/// <summary>
/// Attempts to get the <see cref="Rune"/> which begins at index <paramref name="index"/> in
/// string <paramref name="input"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@

namespace System.Text.Unicode
{
#if SYSTEM_PRIVATE_CORELIB || MICROSOFT_BCL_MEMORY
/// <summary>
/// Provides methods for transcoding between UTF-8 and UTF-16.
/// Provides static methods that convert chunked data between UTF-8 and UTF-16 encodings.
/// </summary>
public
#else
internal
#endif
static class Utf8
public static class Utf8
{
/*
* OperationStatus-based APIs for transcoding of chunked data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,17 @@ public static byte[] DecodeHex(ReadOnlySpan<char> inputHex)
}
return result;

static int FromHex(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
else if (c >= 'a' && c <= 'f')
{
return c - 'a' + 10;
}
else
{
return c - 'A' + 10;
}
}
static int FromHex(char c) =>
c >= '0' && c <= '9' ? c - '0' :
c >= 'a' && c <= 'f' ? c - 'a' + 10 :
c - 'A' + 10;
#endif
}

// !! IMPORTANT !!
// Don't delete this implementation, as we use it as a reference to make sure the framework's
// transcoding logic is correct.
#if NET
public
#else
private
#endif
static byte[] ToUtf8(Rune rune)
private static byte[] ToUtf8(Rune rune)
{
Assert.True(Rune.IsValid(rune.Value), $"Rune with value U+{(uint)rune.Value:X4} is not well-formed.");

Expand Down
Loading