adjusted_file_content.reserve(file_content.size());
bool content_rewritten = false;
- for (const auto line : util::Tokenizer(
- file_content, "\n", util::Tokenizer::Mode::skip_last_empty)) {
+ using util::Tokenizer;
+ for (const auto line : Tokenizer(file_content,
+ "\n",
+ Tokenizer::Mode::include_empty,
+ Tokenizer::IncludeDelimiter::yes)) {
const auto tokens = Util::split_into_views(line, " \t");
for (size_t i = 0; i < tokens.size(); ++i) {
DEBUG_ASSERT(!line.empty()); // line.empty() -> no tokens
adjusted_file_content.append(token.begin(), token.end());
}
}
- adjusted_file_content.push_back('\n');
}
if (content_rewritten) {
static const std::string in_file_included_from = "In file included from ";
std::string result;
- for (auto line :
- util::Tokenizer(text, "\n", util::Tokenizer::Mode::skip_last_empty)) {
+ using util::Tokenizer;
+ for (auto line : Tokenizer(text,
+ "\n",
+ Tokenizer::Mode::include_empty,
+ Tokenizer::IncludeDelimiter::yes)) {
// Rewrite <path> to <absolute path> in the following two cases, where X may
// be optional ANSI CSI sequences:
//
result.append(line.data(), line.length());
}
}
- result += '\n';
}
return result;
}
m_right = delim_pos == npos ? string.length() : delim_pos;
}
} while (mode == Mode::skip_empty && m_left == m_right);
-
- if (mode == Mode::skip_last_empty && m_left == string.length()) {
- m_left = npos;
- }
}
nonstd::sv_lite::string_view
{
public:
enum class Mode {
- include_empty, // Include empty tokens.
- skip_empty, // Skip empty tokens.
- skip_last_empty, // Include empty tokens except the last one.
+ include_empty, // Include empty tokens.
+ skip_empty, // Skip empty tokens.
};
enum class IncludeDelimiter { no, yes };
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"});
}
- SUBCASE("skip last empty token")
- {
- SplitTest split(Mode::skip_last_empty);
- split("", "/", {});
- split("/", "/", {""});
- split("a/", "/", {"a"});
- split("/b", "/", {"", "b"});
- split("a/b", "/", {"a", "b"});
- split("/a:", "/:", {"", "a"});
- }
-
SUBCASE("include empty and delimiter")
{
SplitTest split(Mode::include_empty, IncludeDelimiter::yes);
"/:.+_abcdef",
{"0.", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9."});
}
-
- SUBCASE("skip last empty and include delimiter")
- {
- SplitTest split(Mode::skip_last_empty, IncludeDelimiter::yes);
- split("", "/", {});
- split("/", "/", {"/"});
- split("a/", "/", {"a/"});
- split("/b", "/", {"/", "b"});
- split("a/b", "/", {"a/", "b"});
- split("/a:", "/:", {"/", "a:"});
- }
}