交換したいテキスト ファイルに 2 つの変数があります。[V1] と [V2]。プログラムを実行すると、そのうちの 1 つだけが変更されます。なんで?
#Read up into variable
file (STRINGS "myfile.txt" v1)
#Store text to replace in variable (we need to escape the '[' and ']' since we will use a regexp later on)
set(v1_placeholder "\\[v1\\]")
set(v2_placeholder "\\[v2\\]")
#New reading of documents to process
set(doc_files [v1]_Hello_Documentation.txt myfile.txt)
#Lets iterate over each documentation file
foreach(doc_file ${doc_files})
message(STATUS "Proccessing document file: " ${doc_file})
#Read up content of documentation file
file(READ ${doc_file} FILE_CONTENT)
#Remove occurences of [v2] with nothing
string(REGEX REPLACE "${v2_placeholder}" "" MODIFIED_FILE_CONTENT "${FILE_CONTENT}")
#Replace occurences of [v1] with the real variable in the content
string(REGEX REPLACE "${v1_placeholder}" "${V1}" MODIFIED_FILE_CONTENT "${FILE_CONTENT}")
#Replace occurences of [v1] with the real variable in the file name
string(REGEX REPLACE "${v1_placeholder}" "${V1}" MODIFIED_FILE_NAME "${doc_file}")
#Write modified content back into modifed file name
file(WRITE ${MODIFIED_FILE_NAME} "${MODIFIED_FILE_CONTENT}")
#Add the files to the package in dir /doc
install (FILES ${MODIFIED_FILE_NAME} DESTINATION doc)
endforeach(doc_file)
これを実行すると、ファイルは次のようになります: (v2 は削除されません)。
アプリケーションは現在 r.
主な機能 Hello r を実行すると、標準出力に「Hello World」というテキストが表示されます。
History
[v2]
r
a
b
c
d