Created
November 29, 2011 08:39
-
-
Save zhhailon/1404033 to your computer and use it in GitHub Desktop.
To make comments like "/////////34//////////////" in order.
This file contains 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
# Created by ZHANG Hailong <[email protected]> | |
# | |
# This is a tool to serialize comments in specific style into the right order. | |
# For example: | |
# Before | |
# //////////////3////////////////// | |
# //////////////6////////////////// | |
# //////////////0////////////////// | |
# After | |
# //////////////0////////////////// | |
# //////////////1////////////////// | |
# //////////////2////////////////// | |
# | |
file_name = ARGV[0] | |
puts file_name | |
pre_number = 0 | |
data = nil | |
open(file_name, "r") do |f| | |
data = f.read | |
data.gsub!(/\/+[0-9]+\/+/) do |match| | |
number = match.tr('/', '') | |
match.gsub!("/#{number}/", pre_number.to_s) if number != pre_number.to_s | |
puts match | |
pre_number += 1 | |
match | |
end | |
end | |
open(file_name, "w") do |f| | |
f.write(data) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment