第4月第23天 文本替换

1.python

http://blog.chinaunix.net/uid-25602770-id-4009387.html

 

2.ruby

https://my.oschina.net/moluyingxing/blog/192248

 

Dir.glob('**/*').each do |file|
  next unless /\.m$/ =~ file or /\.h$/ =~ file  # Only Objective C code.
  next if /^ZergSupport\/TestSupport\/GTM\// =~ file  # Skip GTM code.
  next if /^ZergSupport\/TestSupport\/OCMock\// =~ file  # Skip OCMock code.
  
  contents = File.read file
  
  # eat whitespace at the end of lines
  contents.gsub! /[ \t]+$/, ""
  # tabs are 2 spaces
  contents.gsub! "\t", "  "
  
  # force -(type)method instead of - (type) method
  contents.gsub! /\-\s*\(([^(]*)\)\s*(\w)/, "-(\\1)\\2"
  contents.gsub! /\+\s*\(([^(]*)\)\s*(\w)/, "+(\\1)\\2"
  
  # force methodName:(type)argument instead of methodName: (type)argument
  contents.gsub! /(\w+)\:[ \t]*\(/, "\\1:("

  # license
  contents.gsub! '__MyCompanyName__', 'Zergling.Net'
  contents.gsub! /^\/\/  Copyright.*Zergling\.Net\. .*.$/,
                 "//  Copyright Zergling.Net. Licensed under the MIT license."
  
  File.open(file, 'w') { |f| f.write contents }
end

 

posted @ 2017-01-23 17:55  lianhuaren  阅读(120)  评论(0编辑  收藏  举报