Conversation
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf8.cs
Outdated
Show resolved
Hide resolved
| public static System.Buffers.OperationStatus ToUtf16(System.ReadOnlySpan<byte> source, System.Span<char> destination, out int bytesRead, out int charsWritten, bool replaceInvalidSequences = true, bool isFinalBlock = true) { throw null; } | ||
| public static bool TryWrite(System.Span<byte> destination, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute("destination")] ref System.Text.Unicode.Utf8.TryWriteInterpolatedStringHandler handler, out int bytesWritten) { throw null; } | ||
| public static bool TryWrite(System.Span<byte> destination, IFormatProvider? provider, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute("destination", "provider")] ref System.Text.Unicode.Utf8.TryWriteInterpolatedStringHandler handler, out int bytesWritten) { throw null; } | ||
| public static bool IsValid(System.ReadOnlySpan<byte> value) { throw null; } |
There was a problem hiding this comment.
Can you also search around dotnet/runtime for places this can be used? For example, System.Text.Json currently does this with a public static unsafe bool IsValidUtf8String(ReadOnlySpan<byte> bytes) method that can be entirely replaced when targeting .NET 8+. (Actually, looks like it even has two different helpers for the same thing, with another one public static void ValidateUtf8(ReadOnlySpan<byte> utf8Buffer)).
There was a problem hiding this comment.
One useful pattern to look for is for call sites that invoke UTF8Encoding.GetCharCount and throw away the return value. Those call sites are probably calling GetCharCount just for its side effect of throwing an exception when it sees invalid data.
Another might be to look for places which catch EncoderFallbackException and to see if they're actually trying to convert bytes <-> chars or if they're just performing validation.
|
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsClose #502 issue.
|
src/libraries/System.Runtime/tests/System/Text/Unicode/Utf8Tests.cs
Outdated
Show resolved
Hide resolved
|
Thanks @AlexRadch! The logic LGTM, but it would also be interesting to check what Steve mentioned at #88004 (comment). It would probably be better to get any such changes into this PR rather than into a cleanup PR. |
I'll be busy for about a week and then I'll finish. |
Thanks for your efforts here. In that case, I'll go ahead and merge this and will handle fixing the most obvious consumption sites. If you have time to look for more after that, great. |
Close #502 issue.