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';
}
/*!