Skip to content

Commit 2a846ac

Browse files
Fix regex generator CA1872 warnings (#100345)
1 parent 788f572 commit 2a846ac

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ private static string EmitSearchValues(char[] chars, Dictionary<string, string[]
416416
bitmap[c >> 3] |= (byte)(1 << (c & 7));
417417
}
418418

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

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

@@ -5623,6 +5623,13 @@ private static string DescribeLoop(RegexNode node, RegexMethod rm)
56235623
return style + bounds;
56245624
}
56255625

5626+
private static string ToHexStringNoDashes(byte[] bytes) =>
5627+
#if NETCOREAPP
5628+
Convert.ToHexString(bytes);
5629+
#else
5630+
BitConverter.ToString(bytes).Replace("-", "");
5631+
#endif
5632+
56265633
private static FinishEmitBlock EmitBlock(IndentedTextWriter writer, string? clause, bool faux = false)
56275634
{
56285635
if (clause is not null)

0 commit comments

Comments
 (0)