forked from OctaForge/OctaBuild
simplify extreplace
parent
bd3176cbbd
commit
a17bf0cedc
29
main.cc
29
main.cc
|
@ -131,40 +131,25 @@ static void init_baselib(cs_state &cs, build::make &mk, bool ignore_env) {
|
||||||
|
|
||||||
static void init_pathlib(cs_state &cs) {
|
static void init_pathlib(cs_state &cs) {
|
||||||
cs.new_command("extreplace", "sss", [](auto &cs, auto args, auto &res) {
|
cs.new_command("extreplace", "sss", [](auto &cs, auto args, auto &res) {
|
||||||
string_range lst = args[0].get_strr();
|
|
||||||
string_range oldext = args[1].get_strr();
|
string_range oldext = args[1].get_strr();
|
||||||
string_range newext = args[2].get_strr();
|
string_range newext = args[2].get_strr();
|
||||||
std::string ret;
|
std::string ret;
|
||||||
if (oldext.front() == '.') {
|
for (cscript::util::ListParser p{cs, args[0].get_strr()}; p.parse();) {
|
||||||
oldext.pop_front();
|
ostd::path np{p.get_item()};
|
||||||
}
|
|
||||||
if (newext.front() == '.') {
|
|
||||||
newext.pop_front();
|
|
||||||
}
|
|
||||||
cscript::util::ListParser p{cs, lst};
|
|
||||||
while (p.parse()) {
|
|
||||||
auto elem = p.get_item();
|
|
||||||
string_range it = ostd::iter(elem);
|
|
||||||
if (!ret.empty()) {
|
if (!ret.empty()) {
|
||||||
ret += ' ';
|
ret += ' ';
|
||||||
}
|
}
|
||||||
auto dot = ostd::find_last(it, '.');
|
ret += (
|
||||||
if (!dot.empty() && (dot.slice(1, dot.size()) == oldext)) {
|
(np.suffixes() == oldext) ? np.with_suffixes(newext) : np
|
||||||
ret += it.slice(0, &dot[0] - &it[0]);
|
).string();
|
||||||
ret += '.';
|
|
||||||
ret += newext;
|
|
||||||
} else {
|
|
||||||
ret += it;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
res.set_str(std::move(ret));
|
res.set_str(std::move(ret));
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.new_command("glob", "C", [](auto &cs, auto args, auto &res) {
|
cs.new_command("glob", "C", [](auto &cs, auto args, auto &res) {
|
||||||
auto ret = ostd::appender<std::string>();
|
auto ret = ostd::appender<std::string>();
|
||||||
auto app = ostd::appender<std::vector<path>>();
|
auto app = ostd::appender<std::vector<path>>();;
|
||||||
cscript::util::ListParser p{cs, args[0].get_strr()};
|
for (cscript::util::ListParser p{cs, args[0].get_strr()}; p.parse();) {
|
||||||
while (p.parse()) {
|
|
||||||
fs::glob_match(app, p.get_item());
|
fs::glob_match(app, p.get_item());
|
||||||
}
|
}
|
||||||
ostd::format(ret, "%(%s %)", app.get());
|
ostd::format(ret, "%(%s %)", app.get());
|
||||||
|
|
Loading…
Reference in New Issue