Implement appendTail and appendReplacement methods in Matcher - #590
Open
Jitmisra wants to merge 1 commit into
Open
Implement appendTail and appendReplacement methods in Matcher#590Jitmisra wants to merge 1 commit into
Jitmisra wants to merge 1 commit into
Conversation
Jitmisra
force-pushed
the
feature/matcher-append-methods
branch
from
March 25, 2026 18:33
79f6551 to
94b3192
Compare
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.
#589
Summary
Implements the two missing
appendTail()andappendReplacement()methods in JPF's Matcher model class. These were marked as TODO in the codebase.Problem
Programs using the standard Java regex find-and-replace pattern could not be verified by JPF:
Calling these methods would fail because they weren't implemented.
Solution
Files Changed:
src/classes/.../java/util/regex/Matcher.javasrc/peers/.../JPF_java_util_regex_Matcher.javasrc/tests/.../regex/MatcherAppendTest.javaImplementation Details
The tricky part was handling Java 11+ compact strings. Unlike Java 8 where
StringBufferuseschar[], Java 11+ uses:byte[]for storage (compact representation)coderfield: 0 = LATIN1, 1 = UTF16The implementation:
Matcher.appendReplacement/appendTailTests Added
testAppendReplacementAndTail- Multiple replacementstestAppendReplacementSingleMatch- Single matchtestAppendTailNoMatch- No matches scenariotestAppendReplacementWithGroupReference- Using$1groupstestAppendReplacementEmptyString- Empty replacementVerification