Browse Source

Move `replace` to generate utils

default_compile_flags
vector-of-bool 5 years ago
parent
commit
0e6ee6838a
2 changed files with 21 additions and 23 deletions
  1. +0
    -23
      src/dds/toolchain.cpp
  2. +21
    -0
      src/dds/util.hpp

+ 0
- 23
src/dds/toolchain.cpp View File

return acc; return acc;
} }


namespace {

std::string replace(std::string_view str, std::string_view key, std::string_view repl) {
std::string ret;
std::string_view::size_type pos = 0;
std::string_view::size_type prev_pos = 0;
while (pos = str.find(key, pos), pos != key.npos) {
ret.append(str.begin() + prev_pos, str.begin() + pos);
ret.append(repl);
prev_pos = pos += key.size();
}
ret.append(str.begin() + prev_pos, str.end());
return ret;
}

vector<string> replace(vector<string> strings, std::string_view key, std::string_view repl) {
for (auto& item : strings) {
item = replace(item, key, repl);
}
return strings;
}
} // namespace

vector<string> toolchain::include_args(const fs::path& p) const noexcept { vector<string> toolchain::include_args(const fs::path& p) const noexcept {
return replace(_inc_template, "<PATH>", p.string()); return replace(_inc_template, "<PATH>", p.string());
} }

+ 21
- 0
src/dds/util.hpp View File

return ret; return ret;
} }


inline std::string replace(std::string_view str, std::string_view key, std::string_view repl) {
std::string ret;
std::string_view::size_type pos = 0;
std::string_view::size_type prev_pos = 0;
while (pos = str.find(key, pos), pos != key.npos) {
ret.append(str.begin() + prev_pos, str.begin() + pos);
ret.append(repl);
prev_pos = pos += key.size();
}
ret.append(str.begin() + prev_pos, str.end());
return ret;
}

inline std::vector<std::string>
replace(std::vector<std::string> strings, std::string_view key, std::string_view repl) {
for (auto& item : strings) {
item = replace(item, key, repl);
}
return strings;
}

template <typename Container, typename Predicate> template <typename Container, typename Predicate>
void erase_if(Container& c, Predicate&& p) { void erase_if(Container& c, Predicate&& p) {
auto erase_point = std::remove_if(c.begin(), c.end(), p); auto erase_point = std::remove_if(c.begin(), c.end(), p);

Loading…
Cancel
Save