Skip to content

Add TrimFormatter for configurable string edge trimming#15

Open
henriquemoody wants to merge 1 commit intoRespect:mainfrom
henriquemoody:trim_formatter
Open

Add TrimFormatter for configurable string edge trimming#15
henriquemoody wants to merge 1 commit intoRespect:mainfrom
henriquemoody:trim_formatter

Conversation

@henriquemoody
Copy link
Member

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)

@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.48%. Comparing base (1a07f89) to head (0253e04).

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

@henriquemoody henriquemoody force-pushed the trim_formatter branch 4 times, most recently from c905f41 to 4d383f4 Compare February 6, 2026 21:19
@henriquemoody henriquemoody requested a review from alganet February 6, 2026 21:21
/** @param 'both'|'left'|'right' $side */
public function __construct(
private string $side = 'both',
private string $mask = " \t\n\r\0\x0B",
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

I pick those from PHP's trim() default trimmed characters.

Do you mean we should not merge it?

Copy link
Member

@alganet alganet Feb 6, 2026

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

@henriquemoody henriquemoody force-pushed the trim_formatter branch 3 times, most recently from 65f8e47 to 9604536 Compare February 7, 2026 08:43
@henriquemoody henriquemoody requested a review from alganet February 7, 2026 08:49
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)
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.

3 participants