Replace countPrecedingBackslashes with hasEscapedBackslashAt#2
Draft
Replace countPrecedingBackslashes with hasEscapedBackslashAt#2
Conversation
…ing forward Instead of counting backslashes backwards at each position, track the escape state as we iterate forward through the string. This is more efficient and intuitive. - Removed countPrecedingBackslashes(), hasEscapedWhitespaceAt(), and hasEscapedNewlineAt() helper methods - Added forward-tracking escape state logic in stringComponents() - Maintains same behavior: properly handles \\t, \\n, \\r and escaped backslashes - All StringWrapper tests pass Co-authored-by: jkrinke <3253748+jkrinke@users.noreply.github.com>
- Fix loop condition to properly check bounds before accessing charAt(endIdx + 1) - Add parentheses to ensure correct boolean logic for 'n' or 'r' check - Prevents potential StringIndexOutOfBoundsException Co-authored-by: jkrinke <3253748+jkrinke@users.noreply.github.com>
Move the charAt checks into the while loop condition for cleaner code and better short-circuit evaluation. Co-authored-by: jkrinke <3253748+jkrinke@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add check for escaped backslash in string components
Refactor stringComponents to track escape state forward instead of counting backwards
Dec 21, 2025
Owner
|
@copilot These are too many changes. Keep the original source code as most as possible, but remove countPrecedingBackslashes, add a new method hasEscapedBackslashAt, and invoke it within StringWrapper. |
Per feedback, keep original code structure but replace countPrecedingBackslashes with a new hasEscapedBackslashAt method that returns a boolean instead of a count. Changes: - Removed countPrecedingBackslashes method - Added hasEscapedBackslashAt method that returns true if backslash is escaped - Updated hasEscapedWhitespaceAt to use hasEscapedBackslashAt - Updated hasEscapedNewlineAt to use hasEscapedBackslashAt - Kept stringComponents method unchanged Co-authored-by: jkrinke <3253748+jkrinke@users.noreply.github.com>
Author
Done. I've reverted to the original code structure and made only the minimal change as requested:
All tests pass. See commit 13ddfb8. |
Copilot
AI
changed the title
Refactor stringComponents to track escape state forward instead of counting backwards
Replace countPrecedingBackslashes with hasEscapedBackslashAt
Dec 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
countPrecedingBackslashes()method returned a count of preceding backslashes, requiring callers to check the parity of the count to determine if a backslash was escaped. This PR replaces it with a more direct boolean method.Changes
Removed:
countPrecedingBackslashes()- returned count of preceding backslashesAdded:
hasEscapedBackslashAt()- returns boolean indicating if backslash at given position is escapedUpdated to use new method:
hasEscapedWhitespaceAt()- now callshasEscapedBackslashAt()instead of checking parity of counthasEscapedNewlineAt()- now callshasEscapedBackslashAt()instead of checking parity of countBenefits
Testing
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.