mirror of
https://github.com/ruby/ruby.git
synced 2025-09-21 03:24:00 +02:00
[ruby/yarp] Return Regexp options that match MRI for e, u, s, and n
17dbf4ec46
This commit is contained in:
parent
0996cf5593
commit
101ac364a5
2 changed files with 28 additions and 8 deletions
22
lib/yarp.rb
22
lib/yarp.rb
|
@ -587,11 +587,14 @@ module YARP
|
|||
|
||||
class InterpolatedRegularExpressionNode < Node
|
||||
# Returns a numeric value that represents the flags that were used to create
|
||||
# the regular expression. This mirrors the Regexp#options method in Ruby.
|
||||
# Note that this is effectively masking only the three common flags that are
|
||||
# used in Ruby, and does not include the full set of flags like encoding.
|
||||
# the regular expression.
|
||||
def options
|
||||
flags & 0b111
|
||||
o = flags & 0b111
|
||||
o |= Regexp::FIXEDENCODING if flags & 8 != 0 # 'e'
|
||||
o |= Regexp::FIXEDENCODING if flags & 32 != 0 # 's'
|
||||
o |= Regexp::FIXEDENCODING if flags & 64 != 0 # 'u'
|
||||
o |= Regexp::NOENCODING if flags & 16 != 0 # 'n'
|
||||
o
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -604,11 +607,14 @@ module YARP
|
|||
|
||||
class RegularExpressionNode < Node
|
||||
# Returns a numeric value that represents the flags that were used to create
|
||||
# the regular expression. This mirrors the Regexp#options method in Ruby.
|
||||
# Note that this is effectively masking only the three common flags that are
|
||||
# used in Ruby, and does not include the full set of flags like encoding.
|
||||
# the regular expression.
|
||||
def options
|
||||
flags & 0b111
|
||||
o = flags & 0b111
|
||||
o |= Regexp::FIXEDENCODING if flags & 8 != 0 # 'e'
|
||||
o |= Regexp::FIXEDENCODING if flags & 32 != 0 # 's'
|
||||
o |= Regexp::FIXEDENCODING if flags & 64 != 0 # 'u'
|
||||
o |= Regexp::NOENCODING if flags & 16 != 0 # 'n'
|
||||
o
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue