lib/mate/tmproj/ignores.rb in mate-1.2.1 vs lib/mate/tmproj/ignores.rb in mate-1.3.0
- old
+ new
@@ -54,11 +54,11 @@
ignore_file.readlines.map do |line|
line.lstrip[/(.*?)(\r?\n)?$/, 1] # this strange stuff strips line, but allows mac Icon\r files to be ignored
end.reject do |line|
line.empty? || %w[# !].include?(line[0, 1])
end.each do |line|
- pattern = Regexp.escape(line).gsub(/\\\*+/, '[^/]*') # understand only * pattern
+ pattern = glob2regexp(line)
pattern = "#{DOUBLE_ASTERISK_R}#{pattern}" unless line['/']
pattern.sub!(/^\//, '')
unless pattern.sub!(/\/$/, '')
current_file_pattern << pattern
end
@@ -71,8 +71,29 @@
current_file_pattern = "#{parent_pattern}/(?:#{current_file_pattern})"
current_folder_pattern = "#{parent_pattern}/(?:#{current_folder_pattern})"
end
file_pattern << current_file_pattern
folder_pattern << current_folder_pattern
+ end
+
+ def glob2regexp(glob)
+ glob.gsub(/\[([^\]]*)\]|\{([^\}]*)\}|(\*+)|(\?+)|./) do |m|
+ case
+ when $1
+ "[#{Regexp.escape($1)}]"
+ when $2
+ "(?:#{Regexp.escape($2).split(',').join('|')})"
+ when $3 == '*'
+ '[^/]*'
+ when $3
+ '.*'
+ when $4 == '?'
+ '[^/]'
+ when $4
+ "[^/]{#{$4.length}}"
+ else
+ Regexp.escape(m)
+ end
+ end
end
end
end