Last active
July 23, 2016 08:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGRectMake(someFunctionToGetX(hoge, fuga), anotherFunction(hoge, fuga), 100, 100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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