diff options
| author | Adam Vandenberg | 2012-02-25 16:57:03 -0800 | 
|---|---|---|
| committer | Jack Nagel | 2012-02-25 22:41:20 -0600 | 
| commit | 42d44053ef5d9a3fd46e96be57b73a690a4501fa (patch) | |
| tree | 5573bd99a211340e4daa54306b5637e4156b263a | |
| parent | a3edec8b88a3490477f5a60b3262fb4ceb2f8166 (diff) | |
| download | brew-42d44053ef5d9a3fd46e96be57b73a690a4501fa.tar.bz2 | |
inreplace: also warn on plain gsub! usage
| -rw-r--r-- | Library/Homebrew/extend/string.rb | 13 | 
1 files changed, 11 insertions, 2 deletions
diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index a0cd4d635..c76df4d31 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -13,11 +13,20 @@ end  # used by the inreplace function (in utils.rb)  module StringInreplaceExtension +  # Warn if nothing was replaced +  def gsub! before, after, audit_result=true +    sub = super(before, after) +    if audit_result and sub.nil? +      opoo "inreplace: replacement of '#{before}' with '#{after}' failed" +    end +    return sub +  end +    # Looks for Makefile style variable defintions and replaces the    # 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 +    sub = gsub! Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$"), new_value, false      opoo "inreplace: changing '#{flag}' to '#{new_value}' failed" if sub.nil?    end @@ -27,7 +36,7 @@ module StringInreplaceExtension      flags = [flags] unless flags.kind_of? Array      flags.each do |flag|        # Also remove trailing \n, if present. -      sub = gsub! Regexp.new("^#{flag}[ \\t]*=(.*)$\n?"), "" +      sub = gsub! Regexp.new("^#{flag}[ \\t]*=(.*)$\n?"), "", false        opoo "inreplace: removing '#{flag}' failed" if sub.nil?      end    end  | 
