Project

General

Profile

Feature #8343

StringScanner#[] should accept names of named captures

Added by Konstantin Haase about 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
[ruby-core:54664]

Description

Example:

s = StringScanner.new("Fri Dec 12 1975 14:39")
s.scan(/(?<wday>\w+) (?<month>\w+) (?<day>\d+) /)

# this currently works
s[0]                               # -> "Fri Dec 12 "
s[1]                               # -> "Fri"
s[2]                               # -> "Dec"
s[3]                               # -> "12"

# this currently does not work
s[:wday]                           # -> "Fri"
s[:month]                          # -> "Dec"
s[:day]                            # -> "12"

I attached a patch including tests for MRI, I don't know if Rubinius has a different implementation, I guess JRuby has.
I can look into this if the feature gets accepted.

0001-make-StringScanner-accept-names-of-named-captures.patch View (3.44 KB) Konstantin Haase, 04/28/2013 11:46 PM

Associated revisions

Revision 40881
Added by Yui NARUSE about 3 years ago

  • ext/strscan/strscan.c (strscan_aref): support named captures. patched by Konstantin Haase [Feature #8343]

Revision 40881
Added by Yui NARUSE about 3 years ago

  • ext/strscan/strscan.c (strscan_aref): support named captures. patched by Konstantin Haase [Feature #8343]

Revision 40881
Added by Yui NARUSE about 3 years ago

  • ext/strscan/strscan.c (strscan_aref): support named captures. patched by Konstantin Haase [Feature #8343]

History

#1 [ruby-core:54674] Updated by Konstantin Haase about 3 years ago

On a related note: should the patch be submitted in a second issue on the ruby-trunk project?

#2 [ruby-core:54713] Updated by Yui NARUSE about 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to Yui NARUSE

rkh (Konstantin Haase) wrote:

On a related note: should the patch be submitted in a second issue on the ruby-trunk project?

Here is also correct place now.
I'll merge this if there are no objection.

#3 Updated by Yui NARUSE about 3 years ago

  • Status changed from Assigned to Closed
  • Project changed from CommonRuby to Ruby trunk

Merged at r40881!

Also available in: Atom PDF