From 4c9cdb32d6f5c21723653555d14984952e1262d4 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Thu, 21 Nov 2024 12:43:10 +0800 Subject: [PATCH] tmp --- example/text_io_ex.cpp | 2 +- lib/io/text_io2.cpp | 32 ++++++++++++++++++-------------- lib/io/text_io2.h | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/example/text_io_ex.cpp b/example/text_io_ex.cpp index 2142ef6..41d6783 100644 --- a/example/text_io_ex.cpp +++ b/example/text_io_ex.cpp @@ -59,8 +59,8 @@ int main(int argc, char const *argv[]) try } std::clog << x.back() << "," << y.back() << "," << z.back() << "\n"; - display_vector(tc.annotates_, std::clog, '\n'); display_vector(tc.tags_, std::clog, '\n'); + display_vector(tc.annotates_, std::clog, '\n'); display_vector(tc.heads_, std::clog, '\n'); return 0; } diff --git a/lib/io/text_io2.cpp b/lib/io/text_io2.cpp index e88d841..722e1bb 100644 --- a/lib/io/text_io2.cpp +++ b/lib/io/text_io2.cpp @@ -31,7 +31,7 @@ gctl::text_content::text_content() { // 设置基础参数 att_sym_ = '#'; - tag_sym_ = '>'; + tag_sym_ = '!'; deli_sym_ = ' '; head_num_ = 0; } @@ -45,7 +45,7 @@ gctl::text_content::text_content(std::string filename, std::string file_exten, b { // 设置基础参数 att_sym_ = '#'; - tag_sym_ = '>'; + tag_sym_ = '!'; deli_sym_ = ' '; head_num_ = 0; // 载入文本内容 @@ -80,7 +80,7 @@ void gctl::text_content::load_text(std::string filename, std::string file_exten, std::string tmp_line; std::stringstream tmp_ss; - for (int i = 0; i < head_num_; i++) + for (int i = 0; i < head_num_; i++) // 跳过前n行 包括空行 但不会保存空行 { std::getline(infile, tmp_line); if (!tmp_line.empty()) heads_.push_back(tmp_line); @@ -88,21 +88,25 @@ void gctl::text_content::load_text(std::string filename, std::string file_exten, while (std::getline(infile, tmp_line)) { - if (tmp_line[0] == att_sym_) + if (tmp_line.empty()) continue; // 跳过空行 + else if (tmp_line[0] == att_sym_) // 注释行或者标记行 # #! { - tmp_line = tmp_line.substr(1); + if (tmp_line[1] == tag_sym_) // #! + { + tmp_line = tmp_line.substr(2); // 去掉前两个字符 + tmp_line.erase(0, tmp_line.find_first_not_of(" \t")); + tmp_line.erase(tmp_line.find_last_not_of(" \t") + 1); + tags_.push_back(tmp_line); + continue; + } + + // # + tmp_line = tmp_line.substr(1); // 去掉第一个字符 tmp_line.erase(0, tmp_line.find_first_not_of(" \t")); tmp_line.erase(tmp_line.find_last_not_of(" \t") + 1); annotates_.push_back(tmp_line); } - else if (tmp_line[0] == tag_sym_) - { - tmp_line = tmp_line.substr(1); - tmp_line.erase(0, tmp_line.find_first_not_of(" \t")); - tmp_line.erase(tmp_line.find_last_not_of(" \t") + 1); - tags_.push_back(tmp_line); - } - else if (!tmp_line.empty()) lines_.push_back(tmp_line); + else lines_.push_back(tmp_line); } infile.close(); @@ -139,7 +143,7 @@ void gctl::text_content::save_text(std::string filename, std::string file_exten, for (int i = 0; i < tags_.size(); i++) { - outfile << "> " << tags_[i] << std::endl; + outfile << "#! " << tags_[i] << std::endl; } for (int i = 0; i < annotates_.size(); i++) diff --git a/lib/io/text_io2.h b/lib/io/text_io2.h index 05c11b3..e5c2a73 100644 --- a/lib/io/text_io2.h +++ b/lib/io/text_io2.h @@ -92,7 +92,7 @@ namespace gctl * @param deli 分割符 * @param h_num 头信息行数 */ - void set(char deli_sym = ' ', int h_num = 0, char att_sym = '#', char tag_sym = '>'); + void set(char deli_sym = ' ', int h_num = 0, char att_sym = '#', char tag_sym = '!'); /** * @brief 清理字符串向量对象