Skip to content

Add esc option to muse::strings join and split utils#74

Merged
igorkorsukov merged 1 commit into
musescore:mainfrom
saintmatthieu:string-join-and-split-fixes
Jun 3, 2026
Merged

Add esc option to muse::strings join and split utils#74
igorkorsukov merged 1 commit into
musescore:mainfrom
saintmatthieu:string-join-and-split-fixes

Conversation

@saintmatthieu
Copy link
Copy Markdown
Contributor

@saintmatthieu saintmatthieu commented Jun 2, 2026

The split and join utils from muse::strings can't be used by Audacity's effect-ID resolve logic as it stands, because it does not handle the presence of the escape characters in one of the constituents.

  • I signed the CLA as username:
  • The title of the PR describes the problem it addresses.
  • Each commit's message describes its purpose and effects, and references the issue it resolves. If changes are extensive, there is a sequence of easily reviewable commits.
  • The code in the PR follows the coding rules.
  • I understand all aspects of the code I'm contributing and I'm able to explain it if requested.
  • The code compiles and runs on my machine, preferably after each commit individually. I have manually tested and verified that my changes fulfil their intended purpose.
  • No prior attempts to resolve this problem exist, or if they do, I listed them in my PR description and described how I avoided repeating past mistakes.
  • There are no unnecessary changes.
  • I created a unit test or vtest to verify the changes I made (if applicable).

Build configuration

audacity: audacity/audacity/master
audacity platforms: linux_x64
musescore: musescore/MuseScore/main
musescore platforms: linux_x64

@saintmatthieu saintmatthieu self-assigned this Jun 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extends the muse::strings::split and muse::strings::join utility functions to support escape handling. The header declares optional esc parameters with empty string defaults, preserving backward compatibility. The split implementation recognizes escape sequences to treat escaped delimiters and escape characters as literal text. The join implementation prefixes occurrences of both the separator and escape character with the escape sequence, enabling round-trip reconstruction. A comprehensive test suite validates individual function behavior and verifies that join and split act as inverse operations across plain and complex inputs including multi-character separators and escape strings.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add esc option to muse::strings join and split utils' accurately and concisely describes the main change—adding escape character support to the join and split string utility functions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description covers all required template sections, including CLA signature confirmation, title validation, commit message verification, code guideline compliance, testing confirmation, and build configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@framework/global/stringutils.cpp`:
- Around line 88-101: The loop that checks s.compare(i, sep.size(), sep) must be
guarded against an empty separator to avoid zero-length matches and size_t
underflow; update the code around the esc/sep handling (the branch using
variables esc and sep) to either assert(!sep.empty()) or add a runtime guard
such as if (!sep.empty() && s.compare(i, sep.size(), sep) == 0) so the separator
branch is skipped when sep is empty; apply the same protection to the
corresponding split function (the split/delim comparison) to prevent infinite
loops.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5b10b3ec-86f8-44a1-80b7-51e4bcda1ddd

📥 Commits

Reviewing files that changed from the base of the PR and between f80d3c4 and 22a0a50.

📒 Files selected for processing (4)
  • framework/global/stringutils.cpp
  • framework/global/stringutils.h
  • framework/global/tests/CMakeLists.txt
  • framework/global/tests/stringutils_tests.cpp

Comment thread framework/global/stringutils.cpp Outdated
@saintmatthieu saintmatthieu force-pushed the string-join-and-split-fixes branch from 22a0a50 to 2bcf179 Compare June 2, 2026 11:20
Comment thread framework/global/stringutils.cpp Outdated
}

void muse::strings::split(const std::string& str, std::vector<std::string>& out, const std::string& delim)
void muse::strings::split(const std::string& str, std::vector<std::string>& out, const std::string& delim,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it would be better to make two functions - keep the old "simple" one as is, and add a new one with a new parameter and logic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have force-pushed a change that reduces the diff. Now you can see clearly that if the utils are called without the escape overload, it will pick the previous, simpler implementation.
That said, I can now confidently say that we do not need the simpler implementation at all anymore. join_handle_escape and split_handle_escape are generalizations. If they are used even when the escape argument is empty, the unit tests still pass. I also took some time debugging the machine-generating algorithm to gain an intuitive understanding. It's not trivial but not too complicated either.

@saintmatthieu saintmatthieu force-pushed the string-join-and-split-fixes branch from 2bcf179 to 7f8bce9 Compare June 3, 2026 08:27
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@framework/global/tests/stringutils_tests.cpp`:
- Line 145: Remove the redundant size assertion EXPECT_EQ(out.size(), 5u); from
the test in stringutils_tests.cpp because the subsequent EXPECT_EQ(out, parts)
already verifies content and size; leave the equality assertion using out and
parts (or only keep EXPECT_EQ(out, parts)) so the test remains clear and
non-duplicative.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3b4a9462-c070-4cc6-b921-721974cc8241

📥 Commits

Reviewing files that changed from the base of the PR and between 22a0a50 and 7f8bce9.

📒 Files selected for processing (4)
  • framework/global/stringutils.cpp
  • framework/global/stringutils.h
  • framework/global/tests/CMakeLists.txt
  • framework/global/tests/stringutils_tests.cpp


std::vector<std::string> out;
strings::split(joined, out, "_", "\\");
EXPECT_EQ(out.size(), 5u);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial | 💤 Low value

Redundant size assertion.

Line 146 already verifies out == parts, which implies size equality. The explicit size check on line 145 is redundant.

♻️ Simplify by removing redundant assertion
     std::vector<std::string> out;
     strings::split(joined, out, "_", "\\");
-    EXPECT_EQ(out.size(), 5u);
     EXPECT_EQ(out, parts);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
EXPECT_EQ(out.size(), 5u);
std::vector<std::string> out;
strings::split(joined, out, "_", "\\");
EXPECT_EQ(out, parts);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/global/tests/stringutils_tests.cpp` at line 145, Remove the
redundant size assertion EXPECT_EQ(out.size(), 5u); from the test in
stringutils_tests.cpp because the subsequent EXPECT_EQ(out, parts) already
verifies content and size; leave the equality assertion using out and parts (or
only keep EXPECT_EQ(out, parts)) so the test remains clear and non-duplicative.

@igorkorsukov igorkorsukov merged commit 553ecb7 into musescore:main Jun 3, 2026
3 checks passed
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