Skip to content

Commit

Permalink
Use String#undump for unescaping if available
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynetics committed Dec 30, 2021
1 parent 8414863 commit a408eb2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/regexp_parser/expression/classes/escape_sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ module Regexp::Expression
# TODO: unify naming with Token::Escape, on way or the other, in v3.0.0
module EscapeSequence
class Base < Regexp::Expression::Base
require 'yaml'

def char
# poor man's unescape without using eval
YAML.load(%Q(---\n"#{text}"\n))
end

def codepoint
char.ord
end

if ''.respond_to?(:undump)
def char
%("#{text}").undump
end
else
# poor man's unescape without using eval
require 'yaml'
def char
YAML.load(%Q(---\n"#{text}"\n))
end
end
end

class Literal < EscapeSequence::Base
Expand Down

0 comments on commit a408eb2

Please sign in to comment.