You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[API Proposal]: ReadOnlySpan<char> overloads for StringNormalizationExtensions #87757
If we try to verify that the string represented by ReadOnlySpan<char> is Unicode normalized, we currently have to turn it into a string once.
Overloading for ReadOnlySpan<char> is needed to reduce allocation.
API Proposal
namespace System;
// Doesn't throw on the operation even when having wrong character sequence.
public static class StringNormalizationExtensions {
+ public static bool IsNormalized(this ReadOnlySpan<char> source, NormalizationForm normalizationForm = NormalizationForm.FormC); // will return false in invalid sequence+ public static OperationStatus TryNormalize(this ReadOnlySpan<char> source, Span<char> destination, out int charsWritten, NormalizationForm normalizationForm = NormalizationForm.FormC);
}
Original Proposal - Alternative Proposal
namespace System;
// throws on wrong sequence as String.Normalize does.
public static class StringNormalizationExtensions {
+ public static bool IsNormalized(this ReadOnlySpan<char> strInput, NormalizationForm normalizationForm = NormalizationForm.FormC);+ public static bool TryNormalize(this ReadOnlySpan<char> strInput, Span<char> destination, out int charsWritten, NormalizationForm normalizationForm = NormalizationForm.FormC);
}
API Usage
ReadOnlySpan<char>partOfhugeArray=hugeArray.AsSpan(start,length);if(!partOfhugeArray.IsNormalized())thrownewException("Text must be Unicode normalized.");/// ...
No response
Risks
No response
Reacted by Viktor Svub, Kristian Hellang, Georg Jung, Curtis Buys, rampaa and neon-sunset
Activity
[-][API Proposal]: [/-][+][API Proposal]: `ReadOnlySpan<char>` overloads for `StringNormalizationExtensions`[/+]tarekgh commentedon Nov 18, 2024
@udaken I made a few edits to the proposal and hope that works for you.
bartonjs commentedon Nov 19, 2024
Video