aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend/string.rb
diff options
context:
space:
mode:
authorJack Nagel2014-09-26 22:18:08 -0500
committerJack Nagel2014-09-26 22:35:37 -0500
commitf15a2b4b565b315ad792cc9bb8452d79e672caa7 (patch)
treee4a680bf76635341e3e1b9464cffc9e8d729d01e /Library/Homebrew/extend/string.rb
parent9784ff463dd185671ba62d8a302a366bb6f4f1b9 (diff)
downloadhomebrew-f15a2b4b565b315ad792cc9bb8452d79e672caa7.tar.bz2
Clean up inreplace regexps
- use literal syntax - escape interpolated variables - remove intermediate variables - remove unnecessary capture
Diffstat (limited to 'Library/Homebrew/extend/string.rb')
-rw-r--r--Library/Homebrew/extend/string.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb
index c0f5ae1db..d18539b5c 100644
--- a/Library/Homebrew/extend/string.rb
+++ b/Library/Homebrew/extend/string.rb
@@ -69,22 +69,23 @@ module StringInreplaceExtension
# value with "new_value", or removes the definition entirely.
def change_make_var! flag, new_value
new_value = "#{flag}=#{new_value}"
- sub = gsub! Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$"), new_value, false
- opoo "inreplace: changing '#{flag}' to '#{new_value}' failed" if sub.nil?
+ unless gsub!(/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, new_value, false)
+ opoo "inreplace: changing '#{flag}' to '#{new_value}' failed"
+ end
end
# Removes variable assignments completely.
def remove_make_var! flags
Array(flags).each do |flag|
# Also remove trailing \n, if present.
- sub = gsub! Regexp.new("^#{flag}[ \\t]*=(.*)$\n?"), "", false
- opoo "inreplace: removing '#{flag}' failed" if sub.nil?
+ unless gsub!(/^#{Regexp.escape(flag)}[ \t]*=.*$\n?/, "", false)
+ opoo "inreplace: removing '#{flag}' failed"
+ end
end
end
# Finds the specified variable
def get_make_var flag
- m = match Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$")
- return m[1] if m
+ self[/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, 1]
end
end