Rewrite TextFormatter.StripCRLF

Uses StringBuilder and char span indexof search to reduce intermediate allocations.

The new implementation behaves slightly different compared to old implementation. In synthetic LFCR scenario it is correctly removed while the old implementation left the CR, which seems like an off-by-one error.
This commit is contained in:
Tonttu
2025-03-14 22:27:22 +02:00
committed by Tig
parent c4502b0741
commit 6f63dca591
4 changed files with 159 additions and 38 deletions

View File

@@ -2895,9 +2895,9 @@ public class TextFormatterTests
[InlineData ("This has crlf\r\nin the middle", "This has crlfin the middle")]
[InlineData ("This has crlf in the end\r\n", "This has crlf in the end")]
// LFCR
[InlineData ("\n\rThis has lfcr in the beginning", "\rThis has lfcr in the beginning")]
[InlineData ("This has lfcr\n\rin the middle", "This has lfcr\rin the middle")]
[InlineData ("This has lfcr in the end\n\r", "This has lfcr in the end\r")]
[InlineData ("\n\rThis has lfcr in the beginning", "This has lfcr in the beginning")]
[InlineData ("This has lfcr\n\rin the middle", "This has lfcrin the middle")]
[InlineData ("This has lfcr in the end\n\r", "This has lfcr in the end")]
// CR
[InlineData ("\rThis has cr in the beginning", "This has cr in the beginning")]
[InlineData ("This has cr\rin the middle", "This has crin the middle")]