Skip to content

Instantly share code, notes, and snippets.

@k-yamada
Last active July 23, 2016 08:57
Show Gist options
  • Save k-yamada/3f57fbfab5859ffe32165481fa79a5c7 to your computer and use it in GitHub Desktop.
Save k-yamada/3f57fbfab5859ffe32165481fa79a5c7 to your computer and use it in GitHub Desktop.
SwiftのCGRectMakeとCGPointMakeを新しい書き方に修正するスクリプト ref: http://qiita.com/k-yamada@github/items/59027c80be7be2644cc7
#! /usr/bin/ruby
#
# # usage
#
# chmod +x replace.rb
# ./replace.rb ./hoge.swift > out.swift
#
file_path = File.absolute_path(ARGV[0].to_s)
unless File.exists? file_path
abort "ファイルが存在しません. file_path = #{file_path}"
end
f = File.open(file_path, "r")
out = []
f.each_line do |line|
line = line.gsub(/CGRectMake\((.+?), (.+?), (.+?), (.+?)\)/ , 'CGRect(x: \1, y: \2, width: \3, height: \4)')
line = line.gsub(/CGPointMake\((.+?), (.+?)\)/, 'CGPoint(x: \1, y: \2)')
out << line
end
print out.join()
CGRectMake(someFunctionToGetX(hoge, fuga), anotherFunction(hoge, fuga), 100, 100)
#! /usr/bin/ruby
#
# # usage
#
# chmod +x replace.rb
# ./replace.rb ./hoge.swift > out.swift
#
file_path = File.absolute_path(ARGV[0].to_s)
unless File.exists? file_path
abort "ファイルが存在しません. file_path = #{file_path}"
end
f = File.open(file_path, "r")
out = []
f.each_line do |line|
line = line.gsub(/CGRectMake\((.+?), (.+?), (.+?), (.+?)\)/ , 'CGRect(x: \1, y: \2, width: \3, height: \4)')
line = line.gsub(/CGPointMake\((.+?), (.+?)\)/, 'CGPoint(x: \1, y: \2)')
out << line
end
print out.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment