Skip to content
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

Fix regex generator CA1872 warnings #100345

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private static string EmitSearchValues(char[] chars, Dictionary<string, string[]
bitmap[c >> 3] |= (byte)(1 << (c & 7));
}

string hexBitmap = BitConverter.ToString(bitmap).Replace("-", string.Empty);
string hexBitmap = ToHexStringNoDashes(bitmap);

fieldName = hexBitmap switch
{
Expand Down Expand Up @@ -5427,7 +5427,7 @@ private static string GetSHA256FieldName(string prefix, string toEncode)
{
#pragma warning disable CA1850 // SHA256.HashData isn't available on netstandard2.0
using SHA256 sha = SHA256.Create();
return $"{prefix}{BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(toEncode))).Replace("-", "")}";
return $"{prefix}{ToHexStringNoDashes(Encoding.UTF8.GetBytes(toEncode))}";
#pragma warning restore CA1850
}

Expand Down Expand Up @@ -5623,6 +5623,13 @@ private static string DescribeLoop(RegexNode node, RegexMethod rm)
return style + bounds;
}

private static string ToHexStringNoDashes(byte[] bytes) =>
#if NETCOREAPP
Convert.ToHexString(bytes);
#else
BitConverter.ToString(bytes).Replace("-", "");
#endif

private static FinishEmitBlock EmitBlock(IndentedTextWriter writer, string? clause, bool faux = false)
{
if (clause is not null)
Expand Down
Loading