diff options
author | whitequark <whitequark@whitequark.org> | 2020-06-09 11:59:17 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-09 11:59:17 +0000 |
commit | 3dc32490e071f221481c7bae9285957565026d76 (patch) | |
tree | f8be815a179ac1f49c3550388c9d19efff013f1c /backends/cxxrtl/cxxrtl_backend.cc | |
parent | 74e3ac2449f521a50d5e88daa951acee1062e620 (diff) | |
parent | bbfe55a8d0a40eda2df8af0383c9175791377eb7 (diff) | |
download | yosys-3dc32490e071f221481c7bae9285957565026d76.tar.gz yosys-3dc32490e071f221481c7bae9285957565026d76.tar.bz2 yosys-3dc32490e071f221481c7bae9285957565026d76.zip |
Merge pull request #2130 from whitequark/cxxrtl-fix-split_by
cxxrtl: fix two buggy split_by functions
Diffstat (limited to 'backends/cxxrtl/cxxrtl_backend.cc')
-rw-r--r-- | backends/cxxrtl/cxxrtl_backend.cc | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/backends/cxxrtl/cxxrtl_backend.cc b/backends/cxxrtl/cxxrtl_backend.cc index 2646f9371..4c04a2f14 100644 --- a/backends/cxxrtl/cxxrtl_backend.cc +++ b/backends/cxxrtl/cxxrtl_backend.cc @@ -474,14 +474,16 @@ std::vector<std::string> split_by(const std::string &str, const std::string &sep std::vector<std::string> result; size_t prev = 0; while (true) { - size_t curr = str.find_first_of(sep, prev + 1); - if (curr > str.size()) - curr = str.size(); - if (curr > prev + 1) - result.push_back(str.substr(prev, curr - prev)); - if (curr == str.size()) + size_t curr = str.find_first_of(sep, prev); + if (curr == std::string::npos) { + std::string part = str.substr(prev); + if (!part.empty()) result.push_back(part); break; - prev = curr; + } else { + std::string part = str.substr(prev, curr - prev); + if (!part.empty()) result.push_back(part); + prev = curr + 1; + } } return result; } |