<link rel="self" href="https://bugs.ruby-lang.org/issues/12694.atom"/> <link rel="alternate" href="https://bugs.ruby-lang.org/"/> <id>https://bugs.ruby-lang.org/</id> <sprite_icon>https://bugs.ruby-lang.org/assets/favicon-0e291875.ico</sprite_icon> <updated>2016-08-23T11:39:52Z</updated> <author> <name>Ruby Issue Tracking System</name> </author> <entry> <title>Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60247 2016-08-23T11:39:52Z nobu (Nobuyoshi Nakada) nobu@ruby-lang.org <ul></ul><p>IIRC, there were proposals of <code>lstrip</code> and <code>rstrip</code> enhancement.<br> I'd expect them to accept char class(es), than a sub-string.</p> <p>Note that <code>rb_str_index_m</code> accepts a <code>Regexp</code> too.<br> Calling <code>str_strlen</code> on it will segfault.</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60248 2016-08-23T12:01:43Z sonots (Naotoshi Seo) sonots@gmail.com <ul></ul><p>Thanks, I found an issue which is 3 years old <a href="https://bugs.ruby-lang.org/issues/6842" class="external">https://bugs.ruby-lang.org/issues/6842</a></p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60254 2016-08-24T00:24:58Z shyouhei (Shyouhei Urabe) shyouhei@ruby-lang.org <ul><li><strong>Is duplicate of</strong> <i><a class="issue tracker-2 status-2 priority-4 priority-default" href="https://bugs.ruby-lang.org/issues/6842">Feature #6842</a>: Add Optional Arguments to String#strip</i> added</li></ul> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60259 2016-08-24T05:34:49Z sonots (Naotoshi Seo) sonots@gmail.com <ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>I will continue this issue on <a href="https://bugs.ruby-lang.org/issues/6842" class="external">https://bugs.ruby-lang.org/issues/6842</a>, let me close.</p> <p>=&gt; <a href="https://bugs.ruby-lang.org/issues/6842" class="external">https://bugs.ruby-lang.org/issues/6842</a> is too broad. Let us reopen this ticket, and talk about a way removing heading substr at this thread.</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60388 2016-09-07T06:39:57Z sonots (Naotoshi Seo) sonots@gmail.com <ul><li><strong>Status</strong> changed from <i>Rejected</i> to <i>Open</i></li></ul> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60389 2016-09-07T06:42:02Z mrkn (Kenta Murata) muraken@gmail.com <ul></ul><p>This method removes prefix string, so I propose <code>remove_prefix</code> or <code>deprefix</code> (means remove prefix).</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60390 2016-09-07T06:42:34Z sonots (Naotoshi Seo) sonots@gmail.com <ul></ul><p>We discussed about this ticket on ruby development meeting.</p> <p>Python lstrip <a href="http://www.tutorialspoint.com/python/string_lstrip.htm" class="external">http://www.tutorialspoint.com/python/string_lstrip.htm</a> takes character classes as an argument, so providing a substring as an argument will introduce confusion.</p> <p>We need to think of new naming. What about <code>String#lchomp</code> or <code>String#remove_prefix</code> or <code>String#head_chop</code> for example?</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60391 2016-09-07T06:44:46Z sonots (Naotoshi Seo) sonots@gmail.com <ul></ul><p>It seems python, perl does not have similar methods (which removes heading substr)</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60392 2016-09-07T06:48:20Z sonots (Naotoshi Seo) sonots@gmail.com <ul><li><strong>Description</strong> updated (<a title="View differences" href="https://bugs.ruby-lang.org/journals/60392/diff?detail_id=42375">diff</a>)</li></ul> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60393 2016-09-07T06:50:29Z sonots (Naotoshi Seo) sonots@gmail.com <ul><li><strong>Description</strong> updated (<a title="View differences" href="https://bugs.ruby-lang.org/journals/60393/diff?detail_id=42376">diff</a>)</li></ul> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60395 2016-09-07T06:58:20Z sonots (Naotoshi Seo) sonots@gmail.com <ul><li><strong>Description</strong> updated (<a title="View differences" href="https://bugs.ruby-lang.org/journals/60395/diff?detail_id=42378">diff</a>)</li></ul> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60408 2016-09-07T07:51:06Z sonots (Naotoshi Seo) sonots@gmail.com <ul></ul><p>PHP has ltrim and rtrim (which is an alias of chop), but they are for removing a character list, not removing a substring <a href="http://php.net/manual/en/function.ltrim.php" class="external">http://php.net/manual/en/function.ltrim.php</a></p> <pre><code>ltrim('foaofe', 'foa'); #=&gt; 'e' </code></pre> <p>Elixir has trim_leading, but it looks different with what we want to do <a href="http://elixir-lang.org/docs/stable/elixir/String.html#trim_leading/2" class="external">http://elixir-lang.org/docs/stable/elixir/String.html#trim_leading/2</a></p> <pre><code>iex&gt; String.trim_leading("__ abc _", "_") " abc _" iex&gt; String.trim_leading("1 abc", "11") "1 abc" </code></pre> <p>Golang has the same one with what we want to do <a href="https://golang.org/pkg/strings/#TrimPrefix" class="external">https://golang.org/pkg/strings/#TrimPrefix</a> and TrimSuffix</p> <pre><code> var s = "Goodbye,, world!" s = strings.TrimPrefix(s, "Goodbye,") #=&gt; , world </code></pre> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=60490 2016-09-13T07:10:03Z duerst (Martin Dürst) duerst@it.aoyama.ac.jp <ul></ul><p>Naotoshi Seo wrote:</p> <blockquote> <p>Python lstrip <a href="http://www.tutorialspoint.com/python/string_lstrip.htm" class="external">http://www.tutorialspoint.com/python/string_lstrip.htm</a> takes character classes as an argument, so providing a substring as an argument will introduce confusion.</p> </blockquote> <p>"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.</p> <p>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.</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65086 2017-05-25T12:24:00Z sonots (Naotoshi Seo) sonots@gmail.com <ul></ul><p>I've created a PR <a href="https://github.com/ruby/ruby/pull/1632" class="external">https://github.com/ruby/ruby/pull/1632</a> with a name String#<strong>remove_prefix</strong>.<br> I will merge if the name is acceptable.</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65195 2017-05-31T12:37:38Z znz (Kazuhiro NISHIYAMA) <ul></ul><blockquote> <p><code>str.sub(/^#{Regexp.escape(substr)}/, '') #=&gt; 'def'</code></p> </blockquote> <p>I think <code>^</code> should be <code>\A</code> in description of this ticket. (and maybe in handle_tag_name_mixin.rb of fluentd too)</p> <p>Which is expected?: first prefix of string only or prefix of each line</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65196 2017-05-31T12:41:05Z sonots (Naotoshi Seo) sonots@gmail.com <ul></ul><p>\A is correct. I updated the description, thanks.</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65197 2017-05-31T12:46:12Z sonots (Naotoshi Seo) sonots@gmail.com <ul><li><strong>Description</strong> updated (<a title="View differences" href="https://bugs.ruby-lang.org/journals/65197/diff?detail_id=45276">diff</a>)</li></ul> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65389 2017-06-16T06:11:30Z matz (Yukihiro Matsumoto) matz@ruby.or.jp <ul></ul><p>I'd pick the name <code>delete_prefix</code>.</p> <p>Matz.</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65390 2017-06-16T06:26:10Z sonots (Naotoshi Seo) sonots@gmail.com <ul></ul><p>Thanks! I've changed the name to delete_prefix. <a href="https://github.com/ruby/ruby/pull/1632" class="external">https://github.com/ruby/ruby/pull/1632</a></p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65410 2017-06-16T14:14:33Z Hanmac (Hans Mackowiak) hanmac@gmx.de <ul></ul><p>sonots (Naotoshi Seo) wrote:</p> <blockquote> <p>Thanks! I've changed the name to delete_prefix. <a href="https://github.com/ruby/ruby/pull/1632" class="external">https://github.com/ruby/ruby/pull/1632</a></p> </blockquote> <p>do we need a delete_suffix too or is that done via another method?</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65411 2017-06-16T14:23:38Z sonots (Naotoshi Seo) sonots@gmail.com <ul></ul><p>We have String#chomp to delete suffix, but it would be nice to have the method for symmetry.<br> I will create another thread to discuss about it.</p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65412 2017-06-16T14:31:04Z sonots (Naotoshi Seo) sonots@gmail.com <ul></ul><p>I made a ticket for String#delete_suffix <a href="https://bugs.ruby-lang.org/issues/13665" class="external">https://bugs.ruby-lang.org/issues/13665</a></p> Ruby - Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694?journal_id=65434 2017-06-21T07:43:31Z sonots (Naotoshi Seo) sonots@gmail.com <ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset trunk|r59132.</p> <hr> <p>string.c: add String#delete_prefix and String#delete_prefix!<br> to remove leading substr [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Want a String method to remove heading substr (Closed)" href="https://bugs.ruby-lang.org/issues/12694">#12694</a>] [fix GH-1632]</p> <ul> <li> <p>string.c (rb_str_delete_prefix_bang): add a new method<br> to remove prefix destuctively.</p> </li> <li> <p>string.c (rb_str_delete_prefix): add a new method<br> to remove prefix non-destuctively.</p> </li> <li> <p>test/ruby/test_string.rb: add tests.</p> </li> </ul>