Skip to content

Conversation

@shugo
Copy link
Owner

@shugo shugo commented Dec 3, 2025

This enhancement allows specifying a custom set of characters to remove from strings instead of only whitespace characters.

Examples:
"---abc+++".strip("-+") # => "abc"
"---abc+++".lstrip("-") # => "abc+++"
"---abc+++".rstrip("+") # => "---abc"

The implementation:

  • Adds char_in_string() helper to check if a character is in the set
  • Adds lstrip_offset_chars() and rstrip_offset_chars() for custom char removal
  • Updates strip, lstrip, rstrip and their bang variants to accept optional chars arg
  • Maintains backward compatibility when no argument is provided
  • Properly handles multibyte characters with encoding awareness

🤖 Generated with Claude Code

shugo and others added 3 commits December 3, 2025 11:20
This enhancement allows specifying a custom set of characters to remove
from strings instead of only whitespace characters.

Examples:
  "---abc+++".strip("-+")  # => "abc"
  "---abc+++".lstrip("-")  # => "abc+++"
  "---abc+++".rstrip("+")  # => "---abc"

The implementation:
- Adds char_in_string() helper to check if a character is in the set
- Adds lstrip_offset_chars() and rstrip_offset_chars() for custom char removal
- Updates strip, lstrip, rstrip and their bang variants to accept optional chars arg
- Maintains backward compatibility when no argument is provided
- Properly handles multibyte characters with encoding awareness

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Use the existing tr_setup_table() and tr_find() functions from
String#tr implementation to optimize character lookups in strip/lstrip/rstrip
with chars argument.

Benefits:
- O(1) lookup for ASCII characters (< 256) using lookup table
- Hash-based lookup for multibyte characters
- Consistent with String#tr and String#delete implementations
- Much faster than linear search through chars string

Changes:
- Remove char_in_string() function (replaced by tr_find())
- Use tr_setup_table() to build character lookup table
- Use tr_find() for fast character membership testing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@shugo shugo requested a review from Copilot December 4, 2025 02:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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