Skip to content

strings: factor trim into a parameterised strip facility - #9140

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:python-upstream-08-strings-parameterised-strip
Open

strings: factor trim into a parameterised strip facility#9140
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:python-upstream-08-strings-parameterised-strip

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

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).

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

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>
@tautschnig tautschnig self-assigned this Jul 28, 2026
Copilot AI review requested due to automatic review settings July 28, 2026 20:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_trim axiom 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.

Comment on lines +265 to +278
// 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));
Comment on lines +265 to +267
// 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

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.83%. Comparing base (9e80cec) to head (f350852).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
...ngs/string_constraint_generator_transformation.cpp 91.66% 4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants