ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: sonots@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:77192] [Ruby trunk Feature#12694] Want a String method to remove heading substr
Date: Wed, 07 Sep 2016 07:45:48 +0000	[thread overview]
Message-ID: <redmine.journal-60407.20160907074548.4037c528a48fd301@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-12694.20160823090345@ruby-lang.org

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/

  parent reply	other threads:[~2016-09-07  7:13 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 ` sonots [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-60407.20160907074548.4037c528a48fd301@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).