Skip to content
Merged
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 @@ -218,16 +218,20 @@ private static void ValidateArguments(ReadOnlySpan<char> strInput, Normalization
/// </summary>
private static bool HasInvalidUnicodeSequence(ReadOnlySpan<char> s)
{
for (int i = 0; i < s.Length; i++)
const char Noncharacter = '\uFFFE';

int i = s.IndexOfAnyInRange(CharUnicodeInfo.HIGH_SURROGATE_START, Noncharacter);

for (; (uint)i < (uint)s.Length; i++)
{
char c = s[i];

if (c < '\ud800')
if (c < CharUnicodeInfo.HIGH_SURROGATE_START)
{
continue;
}

if (c == '\uFFFE')
if (c == Noncharacter)
{
return true;
}
Expand All @@ -240,7 +244,7 @@ private static bool HasInvalidUnicodeSequence(ReadOnlySpan<char> s)

if (char.IsHighSurrogate(c))
{
if (i + 1 >= s.Length || !char.IsLowSurrogate(s[i + 1]))
if ((uint)(i + 1) >= (uint)s.Length || !char.IsLowSurrogate(s[i + 1]))
{
// A high surrogate at the end of the string or a high surrogate
// not followed by a low surrogate
Expand All @@ -249,7 +253,6 @@ private static bool HasInvalidUnicodeSequence(ReadOnlySpan<char> s)
else
{
i++; // consume the low surrogate.
continue;
}
}
}
Expand Down
Loading