[前][次][番号順一覧][スレッド一覧]

ruby-changes:71374

From: nagachika <ko1@a...>
Date: Sat, 12 Mar 2022 16:54:19 +0900 (JST)
Subject: [ruby-changes:71374] 4b1cee1431 (ruby_3_0): merge revision(s) e2ec97c4b823a0b2e0c31e7a6d77b1dcdc0dfada: [Backport #18415]

https://git.ruby-lang.org/ruby.git/commit/?id=4b1cee1431

From 4b1cee1431b44e923611c65a8ec5cc61d4025641 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Sat, 12 Mar 2022 16:00:02 +0900
Subject: merge revision(s) e2ec97c4b823a0b2e0c31e7a6d77b1dcdc0dfada: [Backport
 #18415]

	[DOC] How to get the longest last match [Bug #18415]

	---
	 string.c | 32 +++++++++++++++++++++++++++++++-
	 1 file changed, 31 insertions(+), 1 deletion(-)
---
 string.c  | 32 +++++++++++++++++++++++++++++++-
 version.h |  2 +-
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/string.c b/string.c
index 1777125b2b..4d55406dea 100644
--- a/string.c
+++ b/string.c
@@ -3846,7 +3846,6 @@ rb_str_rindex(VALUE str, VALUE sub, long pos) https://github.com/ruby/ruby/blob/trunk/string.c#L3846
     return str_rindex(str, sub, s, pos, enc);
 }
 
-
 /*
  *  call-seq:
  *    string.rindex(substring, offset = self.length) -> integer or nil
@@ -3866,6 +3865,23 @@ rb_str_rindex(VALUE str, VALUE sub, long pos) https://github.com/ruby/ruby/blob/trunk/string.c#L3865
  *    'foo'.rindex(/oo/) # => 1
  *    'foo'.rindex(/ooo/) # => nil
  *
+ *  The _last_ match means starting at the possible last position, not
+ *  the last of longest matches.
+ *
+ *    'foo'.rindex(/o+/) # => 2
+ *    $~ #=> #<MatchData "o">
+ *
+ *  To get the last longest match, needs to combine with negative
+ *  lookbehind.
+ *
+ *    'foo'.rindex(/(?<!o)o+/) # => 1
+ *    $~ #=> #<MatchData "oo">
+ *
+ *  Or String#index with negative lookforward.
+ *
+ *    'foo'.index(/o+(?!.*o)/) # => 1
+ *    $~ #=> #<MatchData "oo">
+ *
  *  \Integer argument +offset+, if given and non-negative, specifies the maximum starting position in the
  *   string to _end_ the search:
  *    'foo'.rindex('o', 0) # => nil
@@ -10101,6 +10117,20 @@ rb_str_partition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L10117
  *     "hello".rpartition("l")         #=> ["hel", "l", "o"]
  *     "hello".rpartition("x")         #=> ["", "", "hello"]
  *     "hello".rpartition(/.l/)        #=> ["he", "ll", "o"]
+ *
+ *  The match from the end means starting at the possible last position, not
+ *  the last of longest matches.
+ *
+ *     "hello".rpartition(/l+/)        #=> ["hel", "l", "o"]
+ *
+ *  To partition at the last longest match, needs to combine with
+ *  negative lookbehind.
+ *
+ *     "hello".rpartition(/(?<!l)l+/)  #=> ["he", "ll", "o"]
+ *
+ *  Or String#partition with negative lookforward.
+ *
+ *     "hello".partition(/l+(?!.*l)/)  #=> ["he", "ll", "o"]
  */
 
 static VALUE
diff --git a/version.h b/version.h
index 55dcb6531a..c58e649e5a 100644
--- a/version.h
+++ b/version.h
@@ -12,7 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L12
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 4
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 183
+#define RUBY_PATCHLEVEL 184
 
 #define RUBY_RELEASE_YEAR 2022
 #define RUBY_RELEASE_MONTH 3
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]