2010-02-27 17:26:27 +00:00
|
|
|
class String
|
|
|
|
def undent
|
2010-10-25 21:12:41 -07:00
|
|
|
gsub(/^.{#{slice(/^ +/).length}}/, '')
|
2010-02-27 17:26:27 +00:00
|
|
|
end
|
2011-06-13 13:02:17 -07:00
|
|
|
|
|
|
|
unless String.method_defined?(:start_with?)
|
|
|
|
def start_with? prefix
|
|
|
|
prefix = prefix.to_s
|
|
|
|
self[0, prefix.length] == prefix
|
|
|
|
end
|
|
|
|
end
|
2010-02-27 17:26:27 +00:00
|
|
|
end
|
2010-11-12 21:05:35 -08:00
|
|
|
|
|
|
|
# used by the inreplace function (in utils.rb)
|
|
|
|
module StringInreplaceExtension
|
|
|
|
# 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}"
|
2012-02-23 21:05:49 -06:00
|
|
|
sub = gsub! Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$"), new_value
|
|
|
|
opoo "inreplace: changing '#{flag}' to '#{new_value}' failed" if sub.nil?
|
2010-11-12 21:05:35 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Removes variable assignments completely.
|
|
|
|
def remove_make_var! flags
|
2011-07-22 13:52:45 -05:00
|
|
|
# Next line is for Ruby 1.9.x compatibility
|
|
|
|
flags = [flags] unless flags.kind_of? Array
|
2010-11-12 21:05:35 -08:00
|
|
|
flags.each do |flag|
|
|
|
|
# Also remove trailing \n, if present.
|
2012-02-23 21:05:49 -06:00
|
|
|
sub = gsub! Regexp.new("^#{flag}[ \\t]*=(.*)$\n?"), ""
|
|
|
|
opoo "inreplace: removing '#{flag}' failed" if sub.nil?
|
2010-11-12 21:05:35 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Finds the specified variable
|
|
|
|
def get_make_var flag
|
|
|
|
m = match Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$")
|
|
|
|
return m[1] if m
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|