strings: factor trim into a parameterised strip facility - #9140
strings: factor trim into a parameterised strip facility#9140tautschnig wants to merge 1 commit into
Conversation
Refactor add_axioms_for_trim into a thin wrapper over a new generic add_axioms_for_strip(str, res, is_strippable, strip_front, strip_back, result_type): remove a maximal run of `is_strippable` characters from the selected end(s). Java trim instantiates it with its `c <= ' '` predicate on both ends; behaviour-preserving. The parameterisation lets other strip-family operations share one axiom set instead of near-duplicating it: a different character predicate (e.g. Java 11's String.strip family uses the Character.isWhitespace set, which KEEPS control bytes below 0x20 that trim strips, so it cannot reuse trim) and one-sided stripping (stripLeading / stripTrailing) become instantiations rather than new axiom code. Verified: [strings] unit green; regression/strings green; jbmc-strings green (Java trim behaviour unchanged). Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Refactors Java trim constraint generation by introducing a generic, parameterised add_axioms_for_strip that can express trim-like “strip runs from ends” behaviors via a character predicate and end-selection flags.
Changes:
- Replaced the bespoke
add_axioms_for_trimaxiom set with a thin wrapper around a new generic strip axiom generator. - Added
string_constraint_generatort::add_axioms_for_strip(...)with predicate + (front/back) configuration to share logic across strip-family operations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/solvers/strings/string_constraint_generator_transformation.cpp | Implements add_axioms_for_strip and rewrites add_axioms_for_trim to call it. |
| src/solvers/strings/string_constraint_generator.h | Declares the new add_axioms_for_strip API and adjusts includes for std::function. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Maximality: either the result is empty (idx == |str|), or the kept | ||
| // boundary characters are non-strippable (so all leading/trailing | ||
| // strippable characters were removed). | ||
| exprt non_strip = static_cast<exprt>(true_exprt{}); | ||
| if(strip_front) | ||
| non_strip = and_exprt(non_strip, not_exprt(is_strippable(str[idx]))); | ||
| if(strip_back) | ||
| { | ||
| const exprt last = | ||
| minus_exprt(plus_exprt(idx, res_len), from_integer(1, index_type)); | ||
| non_strip = and_exprt(non_strip, not_exprt(is_strippable(str[last]))); | ||
| } | ||
| constraints.existential.push_back( | ||
| or_exprt(equal_exprt(idx, str_len), non_strip)); |
| // Maximality: either the result is empty (idx == |str|), or the kept | ||
| // boundary characters are non-strippable (so all leading/trailing | ||
| // strippable characters were removed). |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #9140 +/- ##
========================================
Coverage 80.83% 80.83%
========================================
Files 1715 1715
Lines 189957 189985 +28
Branches 73 73
========================================
+ Hits 153549 153572 +23
- Misses 36408 36413 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Refactor add_axioms_for_trim into a thin wrapper over a new generic add_axioms_for_strip(str, res, is_strippable, strip_front, strip_back, result_type): remove a maximal run of
is_strippablecharacters from the selected end(s). Java trim instantiates it with itsc <= ' 'predicate on both ends; behaviour-preserving.The parameterisation lets other strip-family operations share one axiom set instead of near-duplicating it: a different character predicate (e.g. Java 11's String.strip family uses the Character.isWhitespace set, which KEEPS control bytes below 0x20 that trim strips, so it cannot reuse trim) and one-sided stripping (stripLeading / stripTrailing) become instantiations rather than new axiom code.
Verified: [strings] unit green; regression/strings green; jbmc-strings green (Java trim behaviour unchanged).