* [ruby-core:105290] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring
@ 2021-09-16 7:34 nobu (Nobuyoshi Nakada)
2021-09-16 9:04 ` [ruby-core:105292] " matz (Yukihiro Matsumoto)
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2021-09-16 7:34 UTC (permalink / raw
To: ruby-core
Issue #18172 has been reported by nobu (Nobuyoshi Nakada).
----------------------------------------
Feature #18172: MatchData#sublen to return the length of a substring
https://bugs.ruby-lang.org/issues/18172
* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Priority: Normal
----------------------------------------
There are many code taking the length of a substring matched by `Regexp`.
For instance, in rdoc/markup/attribute_manager.rb:
```ruby
attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
if attr_updated
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
```
People often tends to use such code (although the first addition can be simpler as `$~.begin(3)`), that creates and soon drops substrings, just to take the length.
Therefore, how about the new method to calculate the length, `MatchData#sublen`?
```ruby
/(\d+)\W(\w+)/ =~ "1:foo"
$~.sublen(1) #=> 1
$~.sublen(2) #=> 3
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:105292] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring
2021-09-16 7:34 [ruby-core:105290] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring nobu (Nobuyoshi Nakada)
@ 2021-09-16 9:04 ` matz (Yukihiro Matsumoto)
2021-09-16 13:36 ` [ruby-core:105299] " Hanmac (Hans Mackowiak)
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: matz (Yukihiro Matsumoto) @ 2021-09-16 9:04 UTC (permalink / raw
To: ruby-core
Issue #18172 has been updated by matz (Yukihiro Matsumoto).
In Ruby C source code, we use names like `sublen` but Ruby methods tend to be fully spelled. So I propose `MatchData#match(n)` and `MatchData#match_length(n)`.
Matz.
----------------------------------------
Feature #18172: MatchData#sublen to return the length of a substring
https://bugs.ruby-lang.org/issues/18172#change-93701
* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Priority: Normal
----------------------------------------
There are many code taking the length of a substring matched by `Regexp`.
For instance, in rdoc/markup/attribute_manager.rb:
```ruby
attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
if attr_updated
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
```
People often tends to use such code (although the first addition can be simpler as `$~.begin(3)`), that creates and soon drops substrings, just to take the length.
Therefore, how about the new method to calculate the length, `MatchData#sublen`?
```ruby
/(\d+)\W(\w+)/ =~ "1:foo"
$~.sublen(1) #=> 1
$~.sublen(2) #=> 3
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:105299] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring
2021-09-16 7:34 [ruby-core:105290] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring nobu (Nobuyoshi Nakada)
2021-09-16 9:04 ` [ruby-core:105292] " matz (Yukihiro Matsumoto)
@ 2021-09-16 13:36 ` Hanmac (Hans Mackowiak)
2021-09-16 14:28 ` [ruby-core:105307] " nobu (Nobuyoshi Nakada)
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Hanmac (Hans Mackowiak) @ 2021-09-16 13:36 UTC (permalink / raw
To: ruby-core
Issue #18172 has been updated by Hanmac (Hans Mackowiak).
@nobu, isn't your `MatchData#match` the same as `MatchData#[]` ?
----------------------------------------
Feature #18172: MatchData#sublen to return the length of a substring
https://bugs.ruby-lang.org/issues/18172#change-93709
* Author: nobu (Nobuyoshi Nakada)
* Status: Closed
* Priority: Normal
----------------------------------------
There are many code taking the length of a substring matched by `Regexp`.
For instance, in rdoc/markup/attribute_manager.rb:
```ruby
attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
if attr_updated
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
```
People often tends to use such code (although the first addition can be simpler as `$~.begin(3)`), that creates and soon drops substrings, just to take the length.
Therefore, how about the new method to calculate the length, `MatchData#sublen`?
```ruby
/(\d+)\W(\w+)/ =~ "1:foo"
$~.sublen(1) #=> 1
$~.sublen(2) #=> 3
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:105307] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring
2021-09-16 7:34 [ruby-core:105290] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring nobu (Nobuyoshi Nakada)
2021-09-16 9:04 ` [ruby-core:105292] " matz (Yukihiro Matsumoto)
2021-09-16 13:36 ` [ruby-core:105299] " Hanmac (Hans Mackowiak)
@ 2021-09-16 14:28 ` nobu (Nobuyoshi Nakada)
2021-09-16 16:02 ` [ruby-core:105311] " Hanmac (Hans Mackowiak)
2021-09-17 0:29 ` [ruby-core:105316] " nobu (Nobuyoshi Nakada)
4 siblings, 0 replies; 6+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2021-09-16 14:28 UTC (permalink / raw
To: ruby-core
Issue #18172 has been updated by nobu (Nobuyoshi Nakada).
Hanmac (Hans Mackowiak) wrote in #note-3:
> @nobu, isn't your `MatchData#match` the same as `MatchData#[]` ?
Similar, but `#match` accepts only single index/name, but not a range.
----------------------------------------
Feature #18172: MatchData#sublen to return the length of a substring
https://bugs.ruby-lang.org/issues/18172#change-93717
* Author: nobu (Nobuyoshi Nakada)
* Status: Closed
* Priority: Normal
----------------------------------------
There are many code taking the length of a substring matched by `Regexp`.
For instance, in rdoc/markup/attribute_manager.rb:
```ruby
attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
if attr_updated
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
```
People often tends to use such code (although the first addition can be simpler as `$~.begin(3)`), that creates and soon drops substrings, just to take the length.
Therefore, how about the new method to calculate the length, `MatchData#sublen`?
```ruby
/(\d+)\W(\w+)/ =~ "1:foo"
$~.sublen(1) #=> 1
$~.sublen(2) #=> 3
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:105311] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring
2021-09-16 7:34 [ruby-core:105290] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring nobu (Nobuyoshi Nakada)
` (2 preceding siblings ...)
2021-09-16 14:28 ` [ruby-core:105307] " nobu (Nobuyoshi Nakada)
@ 2021-09-16 16:02 ` Hanmac (Hans Mackowiak)
2021-09-17 0:29 ` [ruby-core:105316] " nobu (Nobuyoshi Nakada)
4 siblings, 0 replies; 6+ messages in thread
From: Hanmac (Hans Mackowiak) @ 2021-09-16 16:02 UTC (permalink / raw
To: ruby-core
Issue #18172 has been updated by Hanmac (Hans Mackowiak).
nobu (Nobuyoshi Nakada) wrote in #note-4:
> Hanmac (Hans Mackowiak) wrote in #note-3:
> > @nobu, isn't your `MatchData#match` the same as `MatchData#[]` ?
>
> Similar, but `#match` accepts only single index/name, but not a range or an optional length.
i just wonder why not use the functions there like done in the other method?
``` c
if (FIXNUM_P(idx)) {
return rb_reg_nth_match(FIX2INT(idx), match);
}
else {
int num = namev_to_backref_number(RMATCH_REGS(match), RMATCH(match)->regexp, idx);
if (num >= 0) {
return rb_reg_nth_match(num, match);
}
else {
return match_ary_aref(match, idx, Qnil);
}
}
```
----------------------------------------
Feature #18172: MatchData#sublen to return the length of a substring
https://bugs.ruby-lang.org/issues/18172#change-93724
* Author: nobu (Nobuyoshi Nakada)
* Status: Closed
* Priority: Normal
----------------------------------------
There are many code taking the length of a substring matched by `Regexp`.
For instance, in rdoc/markup/attribute_manager.rb:
```ruby
attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
if attr_updated
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
```
People often tends to use such code (although the first addition can be simpler as `$~.begin(3)`), that creates and soon drops substrings, just to take the length.
Therefore, how about the new method to calculate the length, `MatchData#sublen`?
```ruby
/(\d+)\W(\w+)/ =~ "1:foo"
$~.sublen(1) #=> 1
$~.sublen(2) #=> 3
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:105316] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring
2021-09-16 7:34 [ruby-core:105290] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring nobu (Nobuyoshi Nakada)
` (3 preceding siblings ...)
2021-09-16 16:02 ` [ruby-core:105311] " Hanmac (Hans Mackowiak)
@ 2021-09-17 0:29 ` nobu (Nobuyoshi Nakada)
4 siblings, 0 replies; 6+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2021-09-17 0:29 UTC (permalink / raw
To: ruby-core
Issue #18172 has been updated by nobu (Nobuyoshi Nakada).
`match_ary_aref` may return an `Array` of substrings when `idx` is a `Range`.
----------------------------------------
Feature #18172: MatchData#sublen to return the length of a substring
https://bugs.ruby-lang.org/issues/18172#change-93731
* Author: nobu (Nobuyoshi Nakada)
* Status: Closed
* Priority: Normal
----------------------------------------
There are many code taking the length of a substring matched by `Regexp`.
For instance, in rdoc/markup/attribute_manager.rb:
```ruby
attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
if attr_updated
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
```
People often tends to use such code (although the first addition can be simpler as `$~.begin(3)`), that creates and soon drops substrings, just to take the length.
Therefore, how about the new method to calculate the length, `MatchData#sublen`?
```ruby
/(\d+)\W(\w+)/ =~ "1:foo"
$~.sublen(1) #=> 1
$~.sublen(2) #=> 3
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-09-17 0:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-16 7:34 [ruby-core:105290] [Ruby master Feature#18172] MatchData#sublen to return the length of a substring nobu (Nobuyoshi Nakada)
2021-09-16 9:04 ` [ruby-core:105292] " matz (Yukihiro Matsumoto)
2021-09-16 13:36 ` [ruby-core:105299] " Hanmac (Hans Mackowiak)
2021-09-16 14:28 ` [ruby-core:105307] " nobu (Nobuyoshi Nakada)
2021-09-16 16:02 ` [ruby-core:105311] " Hanmac (Hans Mackowiak)
2021-09-17 0:29 ` [ruby-core:105316] " nobu (Nobuyoshi Nakada)
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).