From 768a5ebf325cd61fb4217d2f7b7647ab40516dc1 Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Wed, 7 Dec 2022 23:26:16 +0100 Subject: [PATCH] Add XML comment to IndexOfAnyValues declarations --- .../gen/RegexGenerator.Emitter.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs index 12683cbe7ec94..c09c2df09342d 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs +++ b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs @@ -22,6 +22,10 @@ namespace System.Text.RegularExpressions.Generator { public partial class RegexGenerator { + /// Escapes '&', '<' and '>' characters. We aren't using HtmlEncode as that would also escape single and double quotes. + private static string EscapeXmlComment(string text) => + text.Replace("&", "&").Replace("<", "<").Replace(">", ">"); + /// Emits the definition of the partial method. This method just delegates to the property cache on the generated Regex-derived type. private static void EmitRegexPartialMethod(RegexMethod regexMethod, IndentedTextWriter writer) { @@ -405,9 +409,12 @@ private static string EmitIndexOfAnyValues(char[] asciiChars, Dictionary {fieldName} = IndexOfAnyValues.Create({Literal(new string(asciiChars))});", + $"/// Cached data to efficiently search for a character in the set {EscapeXmlComment(setLiteral)}.", + $"internal static readonly IndexOfAnyValues {fieldName} = IndexOfAnyValues.Create({setLiteral});", }); } @@ -5066,14 +5073,11 @@ RegexNodeKind.BackreferenceConditional when node.Parent.Child(1) == node => "Not _ => "", }; - // Get a textual description of the node, making it safe for an XML comment (escaping the minimal amount necessary to - // avoid compilation failures: we don't want to escape single and double quotes, as HtmlEncode would do). string nodeDescription = DescribeNode(node, rm); - nodeDescription = nodeDescription.Replace("&", "&").Replace("<", "<").Replace(">", ">"); // Write out the line for the node. const char BulletPoint = '\u25CB'; - writer.WriteLine($"/// {new string(' ', depth * 4)}{BulletPoint} {tag}{nodeDescription}
"); + writer.WriteLine($"/// {new string(' ', depth * 4)}{BulletPoint} {tag}{EscapeXmlComment(nodeDescription)}
"); } // Process each child.