diff --git a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs index c7c587c3a5bdc5..2029a7fb9ae4f2 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs +++ b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs @@ -416,7 +416,7 @@ private static string EmitSearchValues(char[] chars, Dictionary> 3] |= (byte)(1 << (c & 7)); } - string hexBitmap = BitConverter.ToString(bitmap).Replace("-", string.Empty); + string hexBitmap = ToHexStringNoDashes(bitmap); fieldName = hexBitmap switch { @@ -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 } @@ -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)