3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-07 09:55:20 +00:00

cxxrtl: fix two buggy split_by functions.

This commit is contained in:
whitequark 2020-06-09 11:05:35 +00:00
parent 74e3ac2449
commit bbfe55a8d0
2 changed files with 16 additions and 14 deletions

View file

@ -474,14 +474,16 @@ std::vector<std::string> split_by(const std::string &str, const std::string &sep
std::vector<std::string> result; std::vector<std::string> result;
size_t prev = 0; size_t prev = 0;
while (true) { while (true) {
size_t curr = str.find_first_of(sep, prev + 1); size_t curr = str.find_first_of(sep, prev);
if (curr > str.size()) if (curr == std::string::npos) {
curr = str.size(); std::string part = str.substr(prev);
if (curr > prev + 1) if (!part.empty()) result.push_back(part);
result.push_back(str.substr(prev, curr - prev));
if (curr == str.size())
break; break;
prev = curr; } else {
std::string part = str.substr(prev, curr - prev);
if (!part.empty()) result.push_back(part);
prev = curr + 1;
}
} }
return result; return result;
} }

View file

@ -136,14 +136,14 @@ class vcd_writer {
std::vector<std::string> hierarchy; std::vector<std::string> hierarchy;
size_t prev = 0; size_t prev = 0;
while (true) { while (true) {
size_t curr = hier_name.find_first_of(' ', prev + 1); size_t curr = hier_name.find_first_of(' ', prev);
if (curr > hier_name.size()) if (curr == std::string::npos) {
curr = hier_name.size(); hierarchy.push_back(hier_name.substr(prev));
if (curr > prev + 1)
hierarchy.push_back(hier_name.substr(prev, curr - prev));
if (curr == hier_name.size())
break; break;
prev = curr + 1; } else {
hierarchy.push_back(hier_name.substr(prev, curr - prev));
prev = curr + 1;
}
} }
return hierarchy; return hierarchy;
} }