-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sakura.hhp で
sakura_core\sakura.hh` を参照するのをやめてコメントをカットした sakura.hh を使うようにする (python 版)
#930
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
/.vs | ||
/cppcheck-*.xml | ||
/cppcheck-install.log | ||
/help/sakura/sakura.hh | ||
/tests/build | ||
/Win32 | ||
/x64 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import sys | ||
import re | ||
import codecs | ||
|
||
# 引数で指定した文字列から改行コードを取り除く | ||
def clipEndOfLine(line): | ||
return line.rstrip('\r\n') | ||
|
||
# 行からコメントを削除する | ||
def clipCommet(line): | ||
return re.sub(r'//.*', r'', line) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. raw文字列。C++的にも |
||
|
||
# ファイルからコメントを削除する | ||
def removeComment(inFile, outFile): | ||
with codecs.open(inFile, "r", "utf_8_sig") as fin: | ||
with codecs.open(outFile, "w", "utf_8_sig") as fout: | ||
for line in fin: | ||
text = clipEndOfLine(line) | ||
text = clipCommet(text) | ||
fout.write(text + "\r\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ん?と思いましたが、生成された |
||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) < 3: | ||
print ("usage: " + os.path.basename(sys.argv[0]) + " <src file> <dst file>") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. あえて 2系&3系 両対応で書いてある雰囲気を感じました。 |
||
sys.exit(1) | ||
|
||
if not os.path.exists(sys.argv[1]): | ||
print (sys.argv[1] + " doesn't exist") | ||
sys.exit(1) | ||
|
||
removeComment(sys.argv[1], sys.argv[2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
関数名には突っ込まない方針がいいのかな?と思いつつ・・・。
ニュアンス的には trimかstripじゃないのかな、と。