OSDN Git Service

[Refactor] #3566 spoiler_outlist() のstring::append() を廃止してstringstream へ差し替えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Mon, 24 Jul 2023 13:59:50 +0000 (22:59 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 8 Oct 2023 05:24:42 +0000 (14:24 +0900)
src/wizard/fixed-artifacts-spoiler.cpp

index 22a6126..016ef0c 100644 (file)
@@ -24,38 +24,44 @@ void spoiler_outlist(std::string_view header, const std::vector<std::string> &de
         return;
     }
 
-    std::string line = spoiler_indent;
+    std::stringstream line;
+    line << spoiler_indent;
     if (!header.empty()) {
-        line.append(header).append(" ");
+        line << header << " ";
     }
 
     std::stringstream ss;
     ss << list_separator << ' ';
     const auto last_separator = ss.str();
     for (size_t i = 0; i < descriptions.size(); i++) {
-        auto elem = descriptions[i];
+        std::stringstream element;
+        element << descriptions[i];
         if (i < descriptions.size() - 1) {
-            elem.push_back(separator);
-            elem.push_back(' ');
+            element << separator << ' ';
         }
 
-        if (line.length() + elem.length() <= MAX_LINE_LEN) {
-            line.append(elem);
+        const auto element_str = element.str();
+        const int line_length = line.tellp();
+        if (line_length + element_str.length() <= MAX_LINE_LEN) {
+            line << element_str;
             continue;
         }
 
-        if (line.length() > 1 && line.ends_with(last_separator)) {
-            ofs << std::string_view(line).substr(0, line.length() - 2) << '\n';
-            line = spoiler_indent;
-            line.append(elem);
+        const auto line_str = line.str();
+        if (line_str.ends_with(last_separator)) {
+            ofs << std::string_view(line_str).substr(0, line_str.length() - 2) << '\n';
+            line.str("");
+            line.clear(std::stringstream::goodbit);
+            line << spoiler_indent << element_str;
         } else {
-            ofs << line << '\n';
-            line = "      ";
-            line.append(elem);
+            ofs << line_str << '\n';
+            line.str("");
+            line.clear(std::stringstream::goodbit);
+            line << "      " << element_str;
         }
     }
 
-    ofs << line << '\n';
+    ofs << line.str() << '\n';
 }
 
 /*!