ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:77016] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
@ 2016-08-23  9:03 ` sonots
  2016-08-23  9:06 ` [ruby-core:77017] " sonots
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-08-23  9:03 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been reported by Naotoshi Seo.

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77017] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
  2016-08-23  9:03 ` [ruby-core:77016] [Ruby trunk Feature#12694] Want a String method to remove heading substr sonots
@ 2016-08-23  9:06 ` sonots
  2016-08-23  9:08 ` [ruby-core:77018] " sonots
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-08-23  9:06 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.


Oops, lstrip and rstrip are opposite... Correctly, as below...


```
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60245

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77018] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
  2016-08-23  9:03 ` [ruby-core:77016] [Ruby trunk Feature#12694] Want a String method to remove heading substr sonots
  2016-08-23  9:06 ` [ruby-core:77017] " sonots
@ 2016-08-23  9:08 ` sonots
  2016-08-23 11:39 ` [ruby-core:77020] " nobu
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-08-23  9:08 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.


Proposed patch > https://github.com/sonots/ruby/commit/b6c2cd152cd06e878e27a08cf3c4ce79a0854fe0
Review is welcome.

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60246

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77020] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2016-08-23  9:08 ` [ruby-core:77018] " sonots
@ 2016-08-23 11:39 ` nobu
  2016-08-23 12:01 ` [ruby-core:77021] " sonots
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: nobu @ 2016-08-23 11:39 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Nobuyoshi Nakada.


IIRC, there were proposals of `lstrip` and `rstrip` enhancement.
I'd expect them to accept char class(es), than a sub-string.

Note that `rb_str_index_m` accepts a `Regexp` too.
Calling `str_strlen` on it will segfault.


----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60247

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77021] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2016-08-23 11:39 ` [ruby-core:77020] " nobu
@ 2016-08-23 12:01 ` sonots
  2016-08-24  5:34 ` [ruby-core:77032] [Ruby trunk Feature#12694][Rejected] " sonots
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-08-23 12:01 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.


Thanks, I found an issue which is 3 years old https://bugs.ruby-lang.org/issues/6842

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60248

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77032] [Ruby trunk Feature#12694][Rejected] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2016-08-23 12:01 ` [ruby-core:77021] " sonots
@ 2016-08-24  5:34 ` sonots
  2016-09-07  6:39 ` [ruby-core:77174] [Ruby trunk Feature#12694][Open] " sonots
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-08-24  5:34 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.

Status changed from Open to Rejected

I will continue this issue on https://bugs.ruby-lang.org/issues/6842, let me close.

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60259

* Author: Naotoshi Seo
* Status: Rejected
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77174] [Ruby trunk Feature#12694][Open] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2016-08-24  5:34 ` [ruby-core:77032] [Ruby trunk Feature#12694][Rejected] " sonots
@ 2016-09-07  6:39 ` sonots
  2016-09-07  6:42 ` [ruby-core:77175] [Ruby trunk Feature#12694] " muraken
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-09-07  6:39 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.

Status changed from Rejected to Open

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60388

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77175] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2016-09-07  6:39 ` [ruby-core:77174] [Ruby trunk Feature#12694][Open] " sonots
@ 2016-09-07  6:42 ` muraken
  2016-09-07  6:42 ` [ruby-core:77176] " sonots
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: muraken @ 2016-09-07  6:42 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Kenta Murata.


This method removes prefix string, so I propose `remove_prefix` or `deprefix` (means remove prefix).


----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60389

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77176] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2016-09-07  6:42 ` [ruby-core:77175] [Ruby trunk Feature#12694] " muraken
@ 2016-09-07  6:42 ` sonots
  2016-09-07  6:44 ` [ruby-core:77177] " sonots
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-09-07  6:42 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.


We discussed about this ticket on ruby development meeting.

Python lstrip http://www.tutorialspoint.com/python/string_lstrip.htm takes character classes as an argument, so providing a substring as an argument will introduce confusion.

We need to think of new naming. What about `String#lchomp` or `String#remove_prefix` or `String#head_chop` for example?

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60390

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77177] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2016-09-07  6:42 ` [ruby-core:77176] " sonots
@ 2016-09-07  6:44 ` sonots
  2016-09-07  6:48 ` [ruby-core:77178] " sonots
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-09-07  6:44 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.


It seems python, perl does not have similar methods (which removes heading substr)

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60391

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.index(substr) == 0 #=> 'def'
# or
str.sub(/^#{substr}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.rstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77178] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2016-09-07  6:44 ` [ruby-core:77177] " sonots
@ 2016-09-07  6:48 ` sonots
  2016-09-07  6:50 ` [ruby-core:77179] " sonots
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-09-07  6:48 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.

Description updated

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60392

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#lstrip` would be nice for symmetry although we already have `String#chomp(substr)`



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77179] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2016-09-07  6:48 ` [ruby-core:77178] " sonots
@ 2016-09-07  6:50 ` sonots
  2016-09-07  6:58 ` [ruby-core:77181] " sonots
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-09-07  6:50 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.

Description updated

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60393

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77181] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2016-09-07  6:50 ` [ruby-core:77179] " sonots
@ 2016-09-07  6:58 ` sonots
  2016-09-07  7:45 ` [ruby-core:77192] " sonots
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-09-07  6:58 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.

Description updated

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60395

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77192] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2016-09-07  6:58 ` [ruby-core:77181] " sonots
@ 2016-09-07  7:45 ` sonots
  2016-09-07  7:51 ` [ruby-core:77193] " sonots
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-09-07  7:45 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.


PHP has ltrim and rtrim (which is an alias of chop) http://php.net/manual/en/function.ltrim.php.
It seems String#ltrim is fine for me. How do you think?

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60407

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77193] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2016-09-07  7:45 ` [ruby-core:77192] " sonots
@ 2016-09-07  7:51 ` sonots
  2016-09-13  7:10 ` [ruby-core:77258] " duerst
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2016-09-07  7:51 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Naotoshi Seo.


Naotoshi Seo wrote:
> PHP has ltrim and rtrim (which is an alias of chop) http://php.net/manual/en/function.ltrim.php.
> It seems String#ltrim is fine for me. How do you think?

Sorry, it was the one accepting a character list, too.... `String#ltrim` was bad.

```
ltrim('foaofe', 'foa'); #=> 'e'
```




----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60408

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:77258] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2016-09-07  7:51 ` [ruby-core:77193] " sonots
@ 2016-09-13  7:10 ` duerst
  2017-05-25 12:24 ` [ruby-core:81380] " sonots
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: duerst @ 2016-09-13  7:10 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Martin Dürst.


Naotoshi Seo wrote:

> Python lstrip http://www.tutorialspoint.com/python/string_lstrip.htm takes character classes as an argument, so providing a substring as an argument will introduce confusion.

"character classes" may be confusing. "a list of characters" might be more precise. There are many classes of characters that can't be expressed easily with a list. In particular because Python lstrip doesn't accept hyphens to group characters.

One way to deal with this would be to allow a Regexp that selects a single character, and apply this repeatedly. But we don't have any such concept yet.

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-60490

* Author: Naotoshi Seo
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:81380] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2016-09-13  7:10 ` [ruby-core:77258] " duerst
@ 2017-05-25 12:24 ` sonots
  2017-05-31 12:37 ` [ruby-core:81486] " zn
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2017-05-25 12:24 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by sonots (Naotoshi Seo).


I've created a PR https://github.com/ruby/ruby/pull/1632 with a name String#**remove_prefix**.
I will merge if the name is acceptable.

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-65086

* Author: sonots (Naotoshi Seo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:81486] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (16 preceding siblings ...)
  2017-05-25 12:24 ` [ruby-core:81380] " sonots
@ 2017-05-31 12:37 ` zn
  2017-05-31 12:41 ` [ruby-core:81487] " sonots
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: zn @ 2017-05-31 12:37 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by znz (Kazuhiro NISHIYAMA).


> `str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'`

I think `^` should be `\A` in description of this ticket. (and maybe in handle_tag_name_mixin.rb of fluentd too)

Which is expected?: first prefix of string only or prefix of each line

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-65195

* Author: sonots (Naotoshi Seo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:81487] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (17 preceding siblings ...)
  2017-05-31 12:37 ` [ruby-core:81486] " zn
@ 2017-05-31 12:41 ` sonots
  2017-06-16  6:11 ` [ruby-core:81699] " matz
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2017-05-31 12:41 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by sonots (Naotoshi Seo).


\A is correct.

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-65196

* Author: sonots (Naotoshi Seo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:81699] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (18 preceding siblings ...)
  2017-05-31 12:41 ` [ruby-core:81487] " sonots
@ 2017-06-16  6:11 ` matz
  2017-06-16  6:26 ` [ruby-core:81700] " sonots
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: matz @ 2017-06-16  6:11 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by matz (Yukihiro Matsumoto).


I'd pick the name `delete_prefix`.

Matz.


----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-65389

* Author: sonots (Naotoshi Seo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/\A#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:81700] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (19 preceding siblings ...)
  2017-06-16  6:11 ` [ruby-core:81699] " matz
@ 2017-06-16  6:26 ` sonots
  2017-06-16 14:14 ` [ruby-core:81712] " hanmac
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2017-06-16  6:26 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by sonots (Naotoshi Seo).


Thanks! I've changed the name to delete_prefix.

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-65390

* Author: sonots (Naotoshi Seo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/\A#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:81712] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (20 preceding siblings ...)
  2017-06-16  6:26 ` [ruby-core:81700] " sonots
@ 2017-06-16 14:14 ` hanmac
  2017-06-16 14:23 ` [ruby-core:81713] " sonots
  2017-06-16 14:31 ` [ruby-core:81715] " sonots
  23 siblings, 0 replies; 24+ messages in thread
From: hanmac @ 2017-06-16 14:14 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by Hanmac (Hans Mackowiak).


sonots (Naotoshi Seo) wrote:
> Thanks! I've changed the name to delete_prefix. https://github.com/ruby/ruby/pull/1632

do we need a delete_suffix too or is that done via another method?

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-65410

* Author: sonots (Naotoshi Seo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/\A#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:81713] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (21 preceding siblings ...)
  2017-06-16 14:14 ` [ruby-core:81712] " hanmac
@ 2017-06-16 14:23 ` sonots
  2017-06-16 14:31 ` [ruby-core:81715] " sonots
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2017-06-16 14:23 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by sonots (Naotoshi Seo).


We have String#chomp to delete suffix, but it would be nice to have the method for symmetry.
I will create another thread to discuss about it. 

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-65411

* Author: sonots (Naotoshi Seo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/\A#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [ruby-core:81715] [Ruby trunk Feature#12694] Want a String method to remove heading substr
       [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
                   ` (22 preceding siblings ...)
  2017-06-16 14:23 ` [ruby-core:81713] " sonots
@ 2017-06-16 14:31 ` sonots
  23 siblings, 0 replies; 24+ messages in thread
From: sonots @ 2017-06-16 14:31 UTC (permalink / raw)
  To: ruby-core

Issue #12694 has been updated by sonots (Naotoshi Seo).


I made a ticket for String#delete_suffix https://bugs.ruby-lang.org/issues/13665

----------------------------------------
Feature #12694: Want a String method to remove heading substr
https://bugs.ruby-lang.org/issues/12694#change-65412

* Author: sonots (Naotoshi Seo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I often write codes like:

```ruby
str = 'abcdef'
substr = 'abc'
str[substr.size..-1] if str.start_with?(substr) #=> 'def'
# or
str.sub(/\A#{Regexp.escape(substr)}/, '') #=> 'def'
```

I want a short hand which is something like:

```ruby
str = 'abcdef'
substr = 'abc'
str.lstrip(substr) #=> 'def'
```

Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)`

My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2017-06-16 14:31 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-12694.20160823090345@ruby-lang.org>
2016-08-23  9:03 ` [ruby-core:77016] [Ruby trunk Feature#12694] Want a String method to remove heading substr sonots
2016-08-23  9:06 ` [ruby-core:77017] " sonots
2016-08-23  9:08 ` [ruby-core:77018] " sonots
2016-08-23 11:39 ` [ruby-core:77020] " nobu
2016-08-23 12:01 ` [ruby-core:77021] " sonots
2016-08-24  5:34 ` [ruby-core:77032] [Ruby trunk Feature#12694][Rejected] " sonots
2016-09-07  6:39 ` [ruby-core:77174] [Ruby trunk Feature#12694][Open] " sonots
2016-09-07  6:42 ` [ruby-core:77175] [Ruby trunk Feature#12694] " muraken
2016-09-07  6:42 ` [ruby-core:77176] " sonots
2016-09-07  6:44 ` [ruby-core:77177] " sonots
2016-09-07  6:48 ` [ruby-core:77178] " sonots
2016-09-07  6:50 ` [ruby-core:77179] " sonots
2016-09-07  6:58 ` [ruby-core:77181] " sonots
2016-09-07  7:45 ` [ruby-core:77192] " sonots
2016-09-07  7:51 ` [ruby-core:77193] " sonots
2016-09-13  7:10 ` [ruby-core:77258] " duerst
2017-05-25 12:24 ` [ruby-core:81380] " sonots
2017-05-31 12:37 ` [ruby-core:81486] " zn
2017-05-31 12:41 ` [ruby-core:81487] " sonots
2017-06-16  6:11 ` [ruby-core:81699] " matz
2017-06-16  6:26 ` [ruby-core:81700] " sonots
2017-06-16 14:14 ` [ruby-core:81712] " hanmac
2017-06-16 14:23 ` [ruby-core:81713] " sonots
2017-06-16 14:31 ` [ruby-core:81715] " sonots

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 read-only IMAP folder(s) and NNTP newsgroup(s).