* [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
@ 2025-08-24 15:21 MSP-Greg (Greg L) via ruby-core
2025-09-12 18:56 ` [ruby-core:123233] " Dan0042 (Daniel DeLorme) via ruby-core
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: MSP-Greg (Greg L) via ruby-core @ 2025-08-24 15:21 UTC (permalink / raw)
To: ruby-core; +Cc: MSP-Greg (Greg L)
Issue #21552 has been reported by MSP-Greg (Greg L).
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:123233] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
@ 2025-09-12 18:56 ` Dan0042 (Daniel DeLorme) via ruby-core
2025-12-04 3:05 ` [ruby-core:124019] " shugo (Shugo Maeda) via ruby-core
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Dan0042 (Daniel DeLorme) via ruby-core @ 2025-09-12 18:56 UTC (permalink / raw)
To: ruby-core; +Cc: Dan0042 (Daniel DeLorme)
Issue #21552 has been updated by Dan0042 (Daniel DeLorme).
Agreed. I tend to use `str.sub(/[\ \t]+\z/,'')` for this, but an end-anchored regexp has pretty bad worst-case performance. Try to benchmark the previous when `str = " "*1000+"a"` 😦
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-114563
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124019] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
2025-09-12 18:56 ` [ruby-core:123233] " Dan0042 (Daniel DeLorme) via ruby-core
@ 2025-12-04 3:05 ` shugo (Shugo Maeda) via ruby-core
2025-12-04 6:30 ` [ruby-core:124021] " shugo (Shugo Maeda) via ruby-core
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: shugo (Shugo Maeda) via ruby-core @ 2025-12-04 3:05 UTC (permalink / raw)
To: ruby-core; +Cc: shugo (Shugo Maeda)
Issue #21552 has been updated by shugo (Shugo Maeda).
I just heard someone ask for a strip function that doesn't remove NUL characters.
Since Python's `str.strip` takes an optional argument, it might be a good idea to introduce a similar feature.
I've created a pull request at <https://github.com/ruby/ruby/pull/15400> and here's a benchmark result:
```
voyager:ruby$ cat benchmark_strip.rb (git)-[feature/allow-strip-to-take[0/1816]
require "benchmark"
TARGET = " \t\r\n\f\v\0" + "x" * 1024 + "\0 \t\r\n\f\v"
Benchmark.bmbm do |x|
x.report("strip") do
10000.times do
TARGET.strip
end
end
x.report("gsub") do
10000.times do
TARGET.gsub(/\A\s+|\s+\z/, "")
end
end
x.report('strip(" \t\r\n\f\v")') do
10000.times do
TARGET.strip(" \t\r\n\f\v")
end
end
end
voyager:ruby$ ./tool/runruby.rb benchmark_strip.rb (git)-[feature/allow-strip-to-take-chars]
Rehearsal --------------------------------------------------------
strip 0.005475 0.000065 0.005540 ( 0.005546)
gsub 0.022467 0.000000 0.022467 ( 0.022470)
strip(" \t\r\n\f\v") 0.004772 0.000000 0.004772 ( 0.004773)
----------------------------------------------- total: 0.032779sec
user system total real
strip 0.000759 0.000961 0.001720 ( 0.001720)
gsub 0.019911 0.000000 0.019911 ( 0.019912)
strip(" \t\r\n\f\v") 0.004958 0.000000 0.004958 ( 0.004961)
```
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115451
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124021] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
2025-09-12 18:56 ` [ruby-core:123233] " Dan0042 (Daniel DeLorme) via ruby-core
2025-12-04 3:05 ` [ruby-core:124019] " shugo (Shugo Maeda) via ruby-core
@ 2025-12-04 6:30 ` shugo (Shugo Maeda) via ruby-core
2025-12-05 2:26 ` [ruby-core:124031] " shugo (Shugo Maeda) via ruby-core
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: shugo (Shugo Maeda) via ruby-core @ 2025-12-04 6:30 UTC (permalink / raw)
To: ruby-core; +Cc: shugo (Shugo Maeda)
Issue #21552 has been updated by shugo (Shugo Maeda).
Suggested by nobu, I've added documentation and tests for character selectors: https://github.com/ruby/ruby/pull/15400/commits/a9ad44007dbb0ea543ce1eb8748edd4213083c5f
Exmaples:
```
"012abc345".strip("0-9") # "abc"
"012abc345".strip("^a-z") # "abc"
```
Unlike String#delete, the current implementation doesn't take multiple arguments.
I'm not sure whether there's a use case for it.
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115453
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124031] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
` (2 preceding siblings ...)
2025-12-04 6:30 ` [ruby-core:124021] " shugo (Shugo Maeda) via ruby-core
@ 2025-12-05 2:26 ` shugo (Shugo Maeda) via ruby-core
2025-12-05 8:36 ` [ruby-core:124035] " mame (Yusuke Endoh) via ruby-core
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: shugo (Shugo Maeda) via ruby-core @ 2025-12-05 2:26 UTC (permalink / raw)
To: ruby-core; +Cc: shugo (Shugo Maeda)
Issue #21552 has been updated by shugo (Shugo Maeda).
shugo (Shugo Maeda) wrote in #note-4:
> Unlike String#delete, the current implementation doesn't take multiple arguments.
> I'm not sure whether there's a use case for it.
I've noticed that String#count also take multiple selectors, so I've applied the same changes to String#strip etc. for consistency.
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115462
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124035] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
` (3 preceding siblings ...)
2025-12-05 2:26 ` [ruby-core:124031] " shugo (Shugo Maeda) via ruby-core
@ 2025-12-05 8:36 ` mame (Yusuke Endoh) via ruby-core
2025-12-05 13:48 ` [ruby-core:124039] " KitaitiMakoto via ruby-core
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2025-12-05 8:36 UTC (permalink / raw)
To: ruby-core; +Cc: mame (Yusuke Endoh)
Issue #21552 has been updated by mame (Yusuke Endoh).
I'm not strongly opposed, but this kind of API that use a string to represent a collection of characters feel outdated. It is sometimes convenient, though.
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115466
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124039] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
` (4 preceding siblings ...)
2025-12-05 8:36 ` [ruby-core:124035] " mame (Yusuke Endoh) via ruby-core
@ 2025-12-05 13:48 ` KitaitiMakoto via ruby-core
2025-12-10 6:28 ` [ruby-core:124115] " shugo (Shugo Maeda) via ruby-core
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: KitaitiMakoto via ruby-core @ 2025-12-05 13:48 UTC (permalink / raw)
To: ruby-core; +Cc: KitaitiMakoto
Issue #21552 has been updated by KitaitiMakoto (真 北市).
Thank you, shugo.
"someone" he says is me. My use case is here.
I want to extract chunks from a file and pass them to a neural network model to detect the file type. The model requires two chunks: the `lstrip`ped beggining portion and the `rstrip`ped ending portion, except that null characters must *not* be stripped. It's useful if I can call:
``` ruby
beg_portion.lstrip("\t\n\v\f\r ") # ["\t", "\n", "\v," "\f," "\r", " "] or `/\s/` is preferred?
end_portion.rstrip("\t\n\v\f\r ")
```
I'm not sure why the model requires such chunks, but I guess it was trained in Python framework and Python's `strip` family doesn't strip null characters by default.
As an aside, I was surprised when I saw null characters were stripped by `lstrip` and `rsrip` because I'm familiar with Regexp's `\s` as "whitespace", though the [String's documentation](https://docs.ruby-lang.org/en/master/String.html#class-String-label-Whitespace+in+Strings) explain what is "whitespace".
Tips:
For the case of `str = " "*1000+"a"`, `reverse`ing it gets faster than `strip`ping it:
``` ruby
str.sub(/\A\s+/, "").reverse.sub(/\A\s+/, "").reverse
```
But if many poeple use the trick just for speed, I don't prefer the situation.
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115470
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124115] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
` (5 preceding siblings ...)
2025-12-05 13:48 ` [ruby-core:124039] " KitaitiMakoto via ruby-core
@ 2025-12-10 6:28 ` shugo (Shugo Maeda) via ruby-core
2025-12-10 21:34 ` [ruby-core:124125] " Eregon (Benoit Daloze) via ruby-core
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: shugo (Shugo Maeda) via ruby-core @ 2025-12-10 6:28 UTC (permalink / raw)
To: ruby-core; +Cc: shugo (Shugo Maeda)
Issue #21552 has been updated by shugo (Shugo Maeda).
tr_setup_table_multi() was called twice in String#{strip,strip!}, so I've fixed it: https://github.com/ruby/ruby/pull/15400/commits/c9cb93f201644cd5e2fbbd6e83cf50acb27642de
### Benchmark
https://gist.github.com/shugo/c6367f4139bc2d8df9f9199c49cbbcdf
```
Rehearsal -----------------------------------------------------------------------------
strip() 0.006303 0.001084 0.007387 ( 0.007409)
lstrip("\0 \t-\r") 0.003104 0.000000 0.003104 ( 0.003106)
sub(/\A[\0\s]+/, "") 0.004521 0.000000 0.004521 ( 0.004522)
rstrip("\0 \t-\r") 0.003187 0.000000 0.003187 ( 0.003188)
sub(/[\0\s]+\z/, "") 0.016442 0.000000 0.016442 ( 0.016448)
strip("\0 \t-\r") 0.003774 0.000000 0.003774 ( 0.003781)
gsub(/\A[\0\s]+|[\0\s]+\z/, "") 0.022400 0.000000 0.022400 ( 0.022404)
sub(/\A[\0\s]+/, "").sub(/[\0\s]+\z/, "") 0.016304 0.000000 0.016304 ( 0.016320)
-------------------------------------------------------------------- total: 0.077119sec
user system total real
strip() 0.001528 0.000000 0.001528 ( 0.001527)
lstrip("\0 \t-\r") 0.002598 0.000000 0.002598 ( 0.002599)
sub(/\A[\0\s]+/, "") 0.004651 0.000000 0.004651 ( 0.004657)
rstrip("\0 \t-\r") 0.003305 0.000000 0.003305 ( 0.003306)
sub(/[\0\s]+\z/, "") 0.014502 0.000000 0.014502 ( 0.014502)
strip("\0 \t-\r") 0.003664 0.000000 0.003664 ( 0.003664)
gsub(/\A[\0\s]+|[\0\s]+\z/, "") 0.022062 0.000000 0.022062 ( 0.022077)
sub(/\A[\0\s]+/, "").sub(/[\0\s]+\z/, "") 0.017203 0.000000 0.017203 ( 0.017207)
```
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115565
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124125] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
` (6 preceding siblings ...)
2025-12-10 6:28 ` [ruby-core:124115] " shugo (Shugo Maeda) via ruby-core
@ 2025-12-10 21:34 ` Eregon (Benoit Daloze) via ruby-core
2025-12-10 21:41 ` [ruby-core:124126] " Eregon (Benoit Daloze) via ruby-core
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2025-12-10 21:34 UTC (permalink / raw)
To: ruby-core; +Cc: Eregon (Benoit Daloze)
Issue #21552 has been updated by Eregon (Benoit Daloze).
This sounds like a lot of complexity for one specific use-case, which already has a good solution with `sub`.
>From the benchmarks, `lstrip("\0 \t-\r")` and `sub(/\A[\0\s]+/, "")` are pretty close.
`sub(/[\0\s]+\z/, "")` is slower than `rstrip("\0 \t-\r")`, but that sounds more like something that could/should be optimized in the regexp engine (and would benefit far more cases than this specific one).
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115576
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124126] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
` (7 preceding siblings ...)
2025-12-10 21:34 ` [ruby-core:124125] " Eregon (Benoit Daloze) via ruby-core
@ 2025-12-10 21:41 ` Eregon (Benoit Daloze) via ruby-core
2025-12-10 21:43 ` [ruby-core:124127] " Eregon (Benoit Daloze) via ruby-core
2025-12-11 6:52 ` [ruby-core:124130] " matz (Yukihiro Matsumoto) via ruby-core
10 siblings, 0 replies; 12+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2025-12-10 21:41 UTC (permalink / raw)
To: ruby-core; +Cc: Eregon (Benoit Daloze)
Issue #21552 has been updated by Eregon (Benoit Daloze).
Eregon (Benoit Daloze) wrote in #note-9:
> but that sounds more like something that could/should be optimized in the regexp engine
To substantiate that:
```
$ ruby -rbenchmark/ips -e 'SPACES = ["\0", *("\t".."\r"), " "].join; TARGET = SPACES + "x" * 1024 + SPACES; r=nil; Benchmark.ips { _1.report { r = TARGET.sub(/[\0\s]+\z/, "") } }'
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-linux]
Warming up --------------------------------------
7.106k i/100ms
Calculating -------------------------------------
71.778k (± 1.8%) i/s (13.93 μs/i) - 362.406k in 5.050632s
$ ruby -rbenchmark/ips -e 'SPACES = ["\0", *("\t".."\r"), " "].join; TARGET = SPACES + "x" * 1024 + SPACES; r=nil; Benchmark.ips { _1.report { r = TARGET.sub(/[\0\s]+\z/, "") } }'
truffleruby 33.0.0-dev-bb226b84 (2025-12-01), like ruby 3.3.7, Oracle GraalVM Native [x86_64-linux]
Warming up --------------------------------------
475.108k i/100ms
Calculating -------------------------------------
25.222M (± 4.5%) i/s (39.65 ns/i) - 125.904M in 5.008875s
```
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115577
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124127] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
` (8 preceding siblings ...)
2025-12-10 21:41 ` [ruby-core:124126] " Eregon (Benoit Daloze) via ruby-core
@ 2025-12-10 21:43 ` Eregon (Benoit Daloze) via ruby-core
2025-12-11 6:52 ` [ruby-core:124130] " matz (Yukihiro Matsumoto) via ruby-core
10 siblings, 0 replies; 12+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2025-12-10 21:43 UTC (permalink / raw)
To: ruby-core; +Cc: Eregon (Benoit Daloze)
Issue #21552 has been updated by Eregon (Benoit Daloze).
Also in practice you'd probably want to use `sub!` to mutate in place if a big String.
That would avoid a copy, since CRuby doesn't do lazy substrings which don't share the same end.
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115578
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* [ruby-core:124130] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
` (9 preceding siblings ...)
2025-12-10 21:43 ` [ruby-core:124127] " Eregon (Benoit Daloze) via ruby-core
@ 2025-12-11 6:52 ` matz (Yukihiro Matsumoto) via ruby-core
10 siblings, 0 replies; 12+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2025-12-11 6:52 UTC (permalink / raw)
To: ruby-core; +Cc: matz (Yukihiro Matsumoto)
Issue #21552 has been updated by matz (Yukihiro Matsumoto).
I accept the proposal.
Matz.
----------------------------------------
Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
https://bugs.ruby-lang.org/issues/21552#change-115582
* Author: MSP-Greg (Greg L)
* Status: Open
----------------------------------------
Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions)
Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.
It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do:
```ruby
t = str.strip " \t"
```
One can use a regex for this, but this much simpler.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-12-11 6:52 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-24 15:21 [ruby-core:123063] [Ruby Feature#21552] allow String.strip and similar to take a parameter similar to String.delete MSP-Greg (Greg L) via ruby-core
2025-09-12 18:56 ` [ruby-core:123233] " Dan0042 (Daniel DeLorme) via ruby-core
2025-12-04 3:05 ` [ruby-core:124019] " shugo (Shugo Maeda) via ruby-core
2025-12-04 6:30 ` [ruby-core:124021] " shugo (Shugo Maeda) via ruby-core
2025-12-05 2:26 ` [ruby-core:124031] " shugo (Shugo Maeda) via ruby-core
2025-12-05 8:36 ` [ruby-core:124035] " mame (Yusuke Endoh) via ruby-core
2025-12-05 13:48 ` [ruby-core:124039] " KitaitiMakoto via ruby-core
2025-12-10 6:28 ` [ruby-core:124115] " shugo (Shugo Maeda) via ruby-core
2025-12-10 21:34 ` [ruby-core:124125] " Eregon (Benoit Daloze) via ruby-core
2025-12-10 21:41 ` [ruby-core:124126] " Eregon (Benoit Daloze) via ruby-core
2025-12-10 21:43 ` [ruby-core:124127] " Eregon (Benoit Daloze) via ruby-core
2025-12-11 6:52 ` [ruby-core:124130] " matz (Yukihiro Matsumoto) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).