aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2014-09-26 22:18:08 -0500
committerJack Nagel2014-09-26 22:35:37 -0500
commite409aa308461598815af44aec5f4f2e6ce39ba28 (patch)
treef940d9ab4bb94f4c114db36cf1ca33f1893be2cf
parent701691c261778c8f3b531b2b827f046b97ac0bf0 (diff)
downloadbrew-e409aa308461598815af44aec5f4f2e6ce39ba28.tar.bz2
Clean up inreplace regexps
- use literal syntax - escape interpolated variables - remove intermediate variables - remove unnecessary capture
-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