lib/cocoapods-jxedt/command/header/header.rb in cocoapods-jxedt-0.0.20 vs lib/cocoapods-jxedt/command/header/header.rb in cocoapods-jxedt-0.0.21
- old
+ new
@@ -73,19 +73,20 @@
process_target_files.each {|file_path|
changed = false
lines = File.readlines(file_path)
# 获取命中的行
File.foreach(file_path).with_index {|line, num|
- matched = line =~ /^\s*#import\s*"#{header_name_regulation}"\s*\n$/ || line =~ /^\s*#import\s*<#{header_name_regulation}>\s*\n$/
+ matched_regex = "(^\s*#import\s*\"#{header_name_regulation}\")|(^\s*#import\s*<#{header_name_regulation}>)"
+ matched = line =~ /#{matched_regex}/
next unless matched
header_name = line.match(/(?<=")#{header_name_regulation}(?=")/) || line.match(/(?<=<)#{header_name_regulation}(?=>)/)
next unless public_header_mapping.include?("#{header_name}")
changed = true # 文件需要修改
project_module_name = public_header_mapping["#{header_name}"]
- replace_line = "#import " << "<#{project_module_name}/#{header_name}>\n"
+ replace_line = line.gsub(/#{matched_regex}/, "#import <#{project_module_name}/#{header_name}>")
lines[num] = replace_line
record << "#{file_path} 第#{num}行,#{line} => #{replace_line}"
}
files << file_path if changed
begin
@@ -105,10 +106,11 @@
#{JSON.pretty_generate(files)}
文件修改详情:
#{JSON.pretty_generate(record)}
LOGS
- logs.gsub!('\\"', '"').gsub!('\\n', '') # 去除转义字符
+ logs.gsub!('\\"', '"')# 去除转义字符
+ logs.gsub!('\\n', '') # 去除转义字符
puts logs if @verbose_flag
File.open(log_file_path, 'w') { |file| file.write("#{logs}") } unless log_file_path.nil?
end
end
\ No newline at end of file