Add StringBuilderExtensions, consolidate StringBuilder helpers - #13372
Open
ivandrofly wants to merge 1 commit into
Open
Add StringBuilderExtensions, consolidate StringBuilder helpers#13372ivandrofly wants to merge 1 commit into
ivandrofly wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR consolidates scattered StringBuilder helper logic into a new Nikse.SubtitleEdit.Core.Common.StringBuilderExtensions extension class, and updates call sites to use these shared helpers while adding unit tests to validate behavior.
Changes:
- Added
StringBuilderExtensionswithTrim,StartsWith/EndsWith(char),CountChar(char), andAppendNumber(int,int)helpers. - Updated format writers (
SubRip,AdvancedSubStationAlpha) and translation merge logic (MergeAndSplitHelper) to use the new extensions. - Added
StringBuilderExtensionsTestcoverage for the new helpers.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/libse/Core/StringBuilderExtensionsTest.cs | Adds unit tests for the new StringBuilder extension methods. |
| src/libuilogic/Translate/MergeAndSplitHelper.cs | Switches merged-row end-character counting to StringBuilder.CountChar. |
| src/libse/SubtitleFormats/SubtitleFormat.cs | Removes the previous protected TrimBuilder helper (now consolidated into extensions). |
| src/libse/SubtitleFormats/SubRip.cs | Replaces TrimBuilder(sb) with sb.Trim(). |
| src/libse/SubtitleFormats/AdvancedSubStationAlpha.cs | Replaces TrimBuilder/AppendNumber helpers with sb.Trim() and sb.AppendNumber(...). |
| src/libse/Common/StringExtensions.cs | Removes StringBuilder-specific StartsWith/EndsWith extensions (moved to StringBuilderExtensions). |
| src/libse/Common/StringBuilderExtensions.cs | Introduces the consolidated StringBuilder extension methods. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Move scattered generic StringBuilder helpers into a new extension class Nikse.SubtitleEdit.Core.Common.StringBuilderExtensions: - Trim() - was SubtitleFormat.TrimBuilder (in-place trim without the sb.ToString().Trim() allocation) - StartsWith(char)/EndsWith(char) - moved from StringExtensions - CountChar(char) - was private in MergeAndSplitHelper; GetChunks is missing from the netstandard2.1 reference assemblies, so that target falls back to an indexer loop - AppendNumber(int, int) - was private in AdvancedSubStationAlpha All call sites updated; behavior unchanged. Adds xUnit coverage for the new class. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ivandrofly
force-pushed
the
add-stringbuilder-extensions
branch
from
August 8, 2026 23:50
4c14681 to
cfe40e4
Compare
7 tasks
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.
Summary
Nikse.SubtitleEdit.Core.Common.StringBuilderExtensionsclass consolidating generic StringBuilder helpers that were scattered as private/protected staticsTrim()— moved fromSubtitleFormat.TrimBuilder(in-place trim, avoids thesb.ToString().Trim()extra allocation); call sites inSubRipandAdvancedSubStationAlphaupdatedStartsWith(char)/EndsWith(char)— moved (not copied, to avoid ambiguous-call errors) fromStringExtensions; existing call sites unaffected since the namespace is unchangedCountChar(char)— moved fromMergeAndSplitHelper;StringBuilder.GetChunks()turned out to be missing from the netstandard2.1 reference assemblies, so that target falls back to an indexer loop behind the existing#if NET8_0_OR_GREATERguard patternAppendNumber(int, int)— moved fromAdvancedSubStationAlpha(zero-padded append matching"{0:00}")StringBuilderExtensionsTest(21 tests), including a cross-chunkCountCharcaseAppendTimeCode, EBU/MP4 tag helpers) stay where they areTest plan
dotnet build src/libse/LibSE.csproj— both netstandard2.1 and net10.0 targets compiledotnet test tests/libse/LibSETests.csproj— full suite passes (956/956 locally)h:mm:ss.cc)🤖 Generated with Claude Code