Add TrimFormatter for configurable string edge trimming#15
Add TrimFormatter for configurable string edge trimming#15henriquemoody wants to merge 1 commit intoRespect:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15 +/- ##
============================================
+ Coverage 99.47% 99.48% +0.01%
- Complexity 163 169 +6
============================================
Files 24 25 +1
Lines 382 392 +10
============================================
+ Hits 380 390 +10
Misses 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c905f41 to
4d383f4
Compare
src/TrimFormatter.php
Outdated
| /** @param 'both'|'left'|'right' $side */ | ||
| public function __construct( | ||
| private string $side = 'both', | ||
| private string $mask = " \t\n\r\0\x0B", |
There was a problem hiding this comment.
This default is too narrow. I think it's good as it is to merge because, honestly, this is a rabbit hole that will take months to properly implement:
https://invisible-characters.com/
However, we should remove phrases like "fully implement unicode" and similar claims from the docs, since we don't.
There was a problem hiding this comment.
I pick those from PHP's trim() default trimmed characters.
Do you mean we should not merge it?
There was a problem hiding this comment.
I mean, the code is fine but we need to be less cocky on the docs 😄 The PR needs that ajustment, but the code is good in the current state.
There was a problem hiding this comment.
65f8e47 to
9604536
Compare
Allows precise control over trimming operations with support for left, right, or both sides and custom character masks, using UTF-8-aware regex operations for proper international text handling. The formatter automatically escapes special regex characters in the custom mask and handles complex multi-byte characters including CJK spaces, emoji, and combining diacritics which are essential for global applications. Includes comprehensive tests covering all trim modes, custom masks, Unicode characters (CJK, emoji), special characters, multi-byte strings, and edge cases like empty strings and strings shorter than the mask. Assisted-by: OpenCode (GLM-4.7)
9604536 to
0253e04
Compare
Allows precise control over trimming operations with support for left, right, or both sides and custom character masks, using UTF-8-aware regex operations for proper international text handling.
The formatter automatically escapes special regex characters in the custom mask and handles complex multi-byte characters including CJK spaces, emoji, and combining diacritics which are essential for global applications.
Includes comprehensive tests covering all trim modes, custom masks, Unicode characters (CJK, emoji), special characters, multi-byte strings, and edge cases like empty strings and strings shorter than the mask.
Assisted-by: OpenCode (GLM-4.7)