Skip to content

Commit

Permalink
Remove escape_regex and use Regex.append_source directly for all
Browse files Browse the repository at this point in the history
#5842 (comment)

It is super tricky way.
But @straight-shoota said, so it is right way also.
  • Loading branch information
makenowjust committed Mar 21, 2018
1 parent eecb0d3 commit 3f1f6f1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/compiler/crystal/syntax/to_s.cr
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ module Crystal
when StringLiteral
Regex.append_source exp.value, @str
when StringInterpolation
visit_interpolation(exp) { |s| escape_regex s }
visit_interpolation(exp) { |s| Regex.append_source s, @str }
end
@str << "/"
@str << "i" if node.options.includes? Regex::Options::IGNORE_CASE
Expand All @@ -979,10 +979,6 @@ module Crystal
false
end

def escape_regex(s)
String.build { |io| Regex.append_source s, io }
end

def visit(node : TupleLiteral)
@str << "{"

Expand Down
2 changes: 1 addition & 1 deletion src/regex.cr
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class Regex
end

# :nodoc:
def self.append_source(source, io)
def self.append_source(source, io) : Nil
reader = Char::Reader.new(source)
while reader.has_next?
case char = reader.current_char
Expand Down

0 comments on commit 3f1f6f1

Please sign in to comment.