Skip to content

Fix multi-character newline handling in IndentedStringBuilder.TrimEnd#7

Merged
walterlv merged 2 commits into
t/walterlv/source-text-builderfrom
copilot/sub-pr-6
Nov 13, 2025
Merged

Fix multi-character newline handling in IndentedStringBuilder.TrimEnd#7
walterlv merged 2 commits into
t/walterlv/source-text-builderfrom
copilot/sub-pr-6

Conversation

Copilot AI commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

The TrimEnd method assumed single-character newlines, breaking when NewLine is configured to multi-character sequences like \r\n.

Changes:

  • FindLastNewLineIndex: Changed signature from char to string parameter; now searches for complete newline sequence instead of just the last character
  • Offset calculations: Replace hardcoded + 1 with + NewLine.Length at lines 289 and 298 to properly skip/preserve the entire newline sequence

Example:

var builder = new IndentedStringBuilder { NewLine = "\r\n" };
builder.AppendLine("foo").TrimEnd();
// Previously: Would incorrectly calculate positions mid-sequence (\r|\n split)
// Now: Correctly handles the full \r\n sequence

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant

CLAassistant commented Nov 13, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Co-authored-by: walterlv <9959623+walterlv@users.noreply.github.com>
Copilot AI changed the title [WIP] Update expression code generator based on feedback Fix multi-character newline handling in IndentedStringBuilder.TrimEnd Nov 13, 2025
Copilot AI requested a review from walterlv November 13, 2025 08:27
@lindexi lindexi marked this pull request as ready for review November 13, 2025 08:37
@walterlv walterlv merged commit 681bacd into t/walterlv/source-text-builder Nov 13, 2025
3 checks passed
@walterlv walterlv deleted the copilot/sub-pr-6 branch November 13, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants