|
7 | 7 | //----------------------------------------------------------------------- |
8 | 8 |
|
9 | 9 | using System.Globalization; |
10 | | -using System.Linq; |
11 | 10 | using System.Text; |
12 | 11 | using System.Text.RegularExpressions; |
13 | 12 | using System.Xml.Linq; |
@@ -93,7 +92,7 @@ private static string ConvertToCamelCase(string input, bool firstCharacterMustBe |
93 | 92 | private static string DoFullCamelCaseConversion(string input, bool firstCharacterMustBeAlpha, CamelCaseMode mode) |
94 | 93 | { |
95 | 94 | var capacity = input.Length + (firstCharacterMustBeAlpha ? 1 : 0); |
96 | | - var buffer = capacity < 2 ? stackalloc char[capacity] : new char[capacity]; |
| 95 | + var buffer = capacity <= 256 ? stackalloc char[256] : new char[capacity]; |
97 | 96 |
|
98 | 97 | var sb = new ValueStringBuilder(buffer); |
99 | 98 |
|
@@ -363,20 +362,29 @@ private static void AddPrefixToBeginningOfNonEmptyLines(string input, string tab |
363 | 362 | } |
364 | 363 | } |
365 | 364 |
|
| 365 | + private static readonly char [] _cSharpDocLineBreakChars = ['\r', '\n']; |
| 366 | + private static readonly Lazy<Regex> _cSharpDocLineBreakRegex = new(static () => new Regex("^( *)/// ", RegexOptions.Multiline | RegexOptions.Compiled)); |
| 367 | + |
366 | 368 | /// <summary>Converts all line breaks in a string into '\n' and removes white spaces.</summary> |
367 | 369 | /// <param name="input">The input.</param> |
368 | 370 | /// <param name="tabCount">The tab count.</param> |
369 | 371 | /// <returns>The output.</returns> |
370 | 372 | public static string ConvertCSharpDocs(string input, int tabCount) |
371 | 373 | { |
372 | | - input = input? |
373 | | - .Replace("\r", string.Empty) |
374 | | - .Replace("\n", "\n" + string.Join("", Enumerable.Repeat(" ", tabCount)) + "/// ") |
375 | | - ?? string.Empty; |
| 374 | + input ??= ""; |
| 375 | + |
| 376 | + var needsCleanup = input.IndexOfAny(_cSharpDocLineBreakChars) != -1; |
| 377 | + |
| 378 | + if (needsCleanup) |
| 379 | + { |
| 380 | + input = input |
| 381 | + .Replace("\r", string.Empty) |
| 382 | + .Replace("\n", "\n" + CreateTabString(tabCount) + "/// "); |
| 383 | + } |
376 | 384 |
|
377 | 385 | // TODO: Support more markdown features here |
378 | 386 | var xml = new XText(input).ToString(); |
379 | | - return Regex.Replace(xml, @"^( *)/// ", m => m.Groups[1] + "/// <br/>", RegexOptions.Multiline); |
| 387 | + return _cSharpDocLineBreakRegex.Value.Replace(xml, static m => m.Groups[1] + "/// <br/>"); |
380 | 388 | } |
381 | 389 |
|
382 | 390 | private static string CreateTabString(int tabCount) |
|
0 commit comments