This commit is contained in:
张壹 2024-11-21 12:43:10 +08:00
parent 39eed90abb
commit 4c9cdb32d6
3 changed files with 20 additions and 16 deletions

View File

@ -59,8 +59,8 @@ int main(int argc, char const *argv[]) try
} }
std::clog << x.back() << "," << y.back() << "," << z.back() << "\n"; 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.tags_, std::clog, '\n');
display_vector(tc.annotates_, std::clog, '\n');
display_vector(tc.heads_, std::clog, '\n'); display_vector(tc.heads_, std::clog, '\n');
return 0; return 0;
} }

View File

@ -31,7 +31,7 @@ gctl::text_content::text_content()
{ {
// 设置基础参数 // 设置基础参数
att_sym_ = '#'; att_sym_ = '#';
tag_sym_ = '>'; tag_sym_ = '!';
deli_sym_ = ' '; deli_sym_ = ' ';
head_num_ = 0; head_num_ = 0;
} }
@ -45,7 +45,7 @@ gctl::text_content::text_content(std::string filename, std::string file_exten, b
{ {
// 设置基础参数 // 设置基础参数
att_sym_ = '#'; att_sym_ = '#';
tag_sym_ = '>'; tag_sym_ = '!';
deli_sym_ = ' '; deli_sym_ = ' ';
head_num_ = 0; 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::string tmp_line;
std::stringstream tmp_ss; 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); std::getline(infile, tmp_line);
if (!tmp_line.empty()) heads_.push_back(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)) 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(0, tmp_line.find_first_not_of(" \t"));
tmp_line.erase(tmp_line.find_last_not_of(" \t") + 1); tmp_line.erase(tmp_line.find_last_not_of(" \t") + 1);
annotates_.push_back(tmp_line); annotates_.push_back(tmp_line);
} }
else if (tmp_line[0] == tag_sym_) else lines_.push_back(tmp_line);
{
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);
} }
infile.close(); 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++) 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++) for (int i = 0; i < annotates_.size(); i++)

View File

@ -92,7 +92,7 @@ namespace gctl
* @param deli * @param deli
* @param h_num * @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 * @brief