Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions src/libraries/Common/src/System/Net/IPv4AddressHelper.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static int ParseHostNumber(ReadOnlySpan<char> str, int start, int end)
int b = 0;
char ch;

for (; (start < end) && (ch = str[start]) != '.' && ch != ':'; ++start)
for (; (start < end) && (ch = str[start]) is not ('.' or ':'); ++start)
{
b = (b * 10) + ch - '0';
}
Expand Down Expand Up @@ -118,10 +118,10 @@ internal static unsafe bool IsValidCanonical(char* name, int start, ref int end,
if (allowIPv6)
{
// for ipv4 inside ipv6 the terminator is either ScopeId, prefix or ipv6 terminator
if (ch == ']' || ch == '/' || ch == '%')
if (ch is ']' or '/' or '%')
break;
}
else if (ch == '/' || ch == '\\' || (notImplicitFile && (ch == ':' || ch == '?' || ch == '#')))
else if (ch is '/' or '\\' || (notImplicitFile && ch is ':' or '?' or '#'))
{
break;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ internal static unsafe long ParseNonCanonical(char* name, int start, ref int end
if (current < end)
{
ch = name[current];
if (ch == 'x' || ch == 'X')
if (ch is 'x' or 'X')
{
numberBase = Hex;
current++;
Expand Down Expand Up @@ -275,7 +275,7 @@ internal static unsafe long ParseNonCanonical(char* name, int start, ref int end
{
// end of string, allowed
}
else if ((ch = name[current]) == '/' || ch == '\\' || (notImplicitFile && (ch == ':' || ch == '?' || ch == '#')))
else if ((ch = name[current]) is '/' or '\\' || (notImplicitFile && ch is ':' or '?' or '#'))
{
end = current;
}
Expand Down
12 changes: 3 additions & 9 deletions src/libraries/Common/src/System/Net/IPv6AddressHelper.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ internal static void Parse(ReadOnlySpan<char> address, Span<ushort> numbers, int
}

start = i;
for (++i; i < address.Length && address[i] != ']' && address[i] != '/'; ++i)
for (++i; i < address.Length && address[i] is not (']' or '/'); ++i)
{
}
scopeId = new string(address.Slice(start, i - start));
Expand Down Expand Up @@ -339,14 +339,8 @@ internal static void Parse(ReadOnlySpan<char> address, Span<ushort> numbers, int

// check to see if the upcoming number is really an IPv4
// address. If it is, convert it to 2 ushort numbers
for (int j = i; j < address.Length &&
(address[j] != ']') &&
(address[j] != ':') &&
(address[j] != '%') &&
(address[j] != '/') &&
(j < i + 4); ++j)
for (int j = i; j < address.Length && address[j] is not (']' or ':' or '%' or '/') && (j < i + 4); j++)
{

if (address[j] == '.')
{
// we have an IPv4 address. Find the end of it:
Expand All @@ -355,7 +349,7 @@ internal static void Parse(ReadOnlySpan<char> address, Span<ushort> numbers, int
// the IPv4 address are the prefix delimiter '/'
// or the end-of-string (which we conveniently
// delimited with ']')
while (j < address.Length && (address[j] != ']') && (address[j] != '/') && (address[j] != '%'))
while (j < address.Length && address[j] is not (']' or '/' or '%'))
{
++j;
}
Expand Down
20 changes: 12 additions & 8 deletions src/libraries/System.Private.Uri/src/System/UncNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,24 @@ public static unsafe bool IsValid(char* name, int start, ref int returnedEnd, bo
int i = start;
for (; i < end; ++i)
{
if (name[i] == '/' || name[i] == '\\' || (notImplicitFile && (name[i] == ':' || name[i] == '?' || name[i] == '#')))
char c = name[i];

if (c is '/' or '\\' || (notImplicitFile && c is ':' or '?' or '#'))
{
end = i;
break;
}
else if (name[i] == '.')
else if (c == '.')
{
++i;
break;
}

if (char.IsLetter(name[i]) || name[i] == '-' || name[i] == '_')
if (char.IsLetter(c) || c is '-' or '_')
{
validShortName = true;
}
else if (!char.IsAsciiDigit(name[i]))
else if (!char.IsAsciiDigit(c))
{
return false;
}
Expand All @@ -79,24 +81,26 @@ public static unsafe bool IsValid(char* name, int start, ref int returnedEnd, bo

for (; i < end; ++i)
{
if (name[i] == '/' || name[i] == '\\' || (notImplicitFile && (name[i] == ':' || name[i] == '?' || name[i] == '#')))
char c = name[i];

if (c is '/' or '\\' || (notImplicitFile && c is ':' or '?' or '#'))
{
end = i;
break;
}
else if (name[i] == '.')
else if (c == '.')
{
if (!validShortName || ((i - 1) >= start && name[i - 1] == '.'))
return false;

validShortName = false;
}
else if (name[i] == '-' || name[i] == '_')
else if (c is '-' or '_')
{
if (!validShortName)
return false;
}
else if (char.IsLetter(name[i]) || char.IsAsciiDigit(name[i]))
else if (char.IsLetter(c) || char.IsAsciiDigit(c))
{
if (!validShortName)
validShortName = true;
Expand Down
Loading