From f9f95aefa37f4c9a187460988025382e350a0583 Mon Sep 17 00:00:00 2001 From: abap34 Date: Mon, 22 Apr 2024 00:29:57 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=96=E3=83=AD=E3=83=83=E3=82=AF=E3=82=92?= =?UTF-8?q?=E9=96=89=E3=81=98=E3=82=8B=E3=81=A8=E3=81=8D=E3=81=AB=E6=9C=AB?= =?UTF-8?q?=E5=B0=BE=E3=81=AE=E3=82=B9=E3=83=9A=E3=83=BC=E3=82=B9=E3=82=92?= =?UTF-8?q?=E8=A8=B1=E5=AE=B9=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parse.hpp | 12 ++++++------ src/utils.hpp | 9 ++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/parse.hpp b/src/parse.hpp index fd56ade..0db1553 100644 --- a/src/parse.hpp +++ b/src/parse.hpp @@ -253,7 +253,7 @@ namespace almo { // 1行ずつ読み込み、judge_info に情報を追加していく while (idx < (int)lines.size()) { - if (lines[idx] == ":::") break; + if (rtrim(lines[idx]) == ":::") break; std::string key = lines[idx].substr(0, lines[idx].find("=")); std::string value = lines[idx].substr(lines[idx].find("=") + 1); judge_info[key] = value; @@ -298,7 +298,7 @@ namespace almo { assert(idx < (int)lines.size()); std::string code; while (idx < (int)lines.size()) { - if (lines[idx] == ":::") break; + if (rtrim(lines[idx]) == ":::") break; code += lines[idx] + "\n"; idx++; } @@ -310,7 +310,7 @@ namespace almo { assert(idx < (int)lines.size()); std::vector libs; while (idx < (int)lines.size()) { - if (lines[idx] == ":::") break; + if (rtrim(lines[idx]) == ":::") break; libs.push_back(lines[idx]); idx++; } @@ -322,7 +322,7 @@ namespace almo { idx++; std::string code; while (idx < (int)lines.size()) { - if (lines[idx] == "```") break; + if (rtrim(lines[idx]) == "```") break; code += lines[idx] + "\n"; idx++; } @@ -340,13 +340,13 @@ namespace almo { idx++; std::vector text; - if (lines[idx] == ":::") { + if (rtrim(lines[idx]) == ":::") { root.childs.push_back(scopes.top()); } else { while (idx < (int)lines.size()) { - if (lines[idx] == ":::") { + if (rtrim(lines[idx]) == ":::") { // 一つぶん入れ子が終了 BlockParser parser = BlockParser(); Block contents = parser.processer(text); diff --git a/src/utils.hpp b/src/utils.hpp index ebeb586..0ab6a18 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -189,4 +189,11 @@ std::string escape(const std::string &s) { } } return o.str(); -} \ No newline at end of file +} + + +// 文字列を受け取り、末尾のスペースを削除する +std::string rtrim(std::string s) { + s.erase(s.find_last_not_of(" \n\r\t") + 1); + return s; +}