Add TrimPrefix/TrimSuffix string extensions for segment-based trimming - #87
Merged
Conversation
Copilot created this pull request from a session on behalf of
Tyrrrz
July 15, 2026 12:05
View session
Tyrrrz
marked this pull request as ready for review
July 15, 2026 12:05
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## prime #87 +/- ##
==========================================
+ Coverage 86.23% 86.25% +0.02%
==========================================
Files 74 74
Lines 1242 1244 +2
Branches 229 231 +2
==========================================
+ Hits 1071 1073 +2
Misses 121 121
Partials 50 50 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds segment-aware string trimming helpers to PowerKit.Extensions.StringExtensions to complement TrimStart/TrimEnd/Trim, which operate on character sets rather than substrings.
Changes:
- Added
TrimPrefix(string prefix, StringComparison comparison = Ordinal)to remove a single matching leading substring. - Added
TrimSuffix(string suffix, StringComparison comparison = Ordinal)to remove a single matching trailing substring. - Added unit tests covering matching/non-matching cases, empty prefix/suffix, and
OrdinalIgnoreCasebehavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| PowerKit/Extensions/StringExtensions.cs | Introduces TrimPrefix/TrimSuffix extension methods implemented via StartsWith/EndsWith + slicing. |
| PowerKit.Tests/Extensions/StringExtensionsTests.cs | Adds test coverage for the new trimming methods, including case-insensitive comparisons and edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Aug 1, 2026
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.
string.TrimStart/TrimEnd/Trimoperate on character sets, not substrings. This adds segment-aware counterparts that strip a specific prefix or suffix string once if present.Changes
TrimPrefix(string prefix, StringComparison = Ordinal)— removes the leading substring if the string starts with it; otherwise returns the original unchangedTrimSuffix(string suffix, StringComparison = Ordinal)— removes the trailing substring if the string ends with it; otherwise returns the original unchangedNames intentionally avoid
TrimStart/TrimEndto prevent silent mismatch with the BCL overloads that acceptReadOnlySpan<char>(to whichstringimplicitly converts).Example