sync: vendor (#799)

Co-authored-by: firecoperana <firecoperana>
This commit is contained in:
firecoperana
2025-09-26 11:22:47 -05:00
committed by GitHub
parent c108e4b7c9
commit 367654f99e
3 changed files with 1837 additions and 1042 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1575,6 +1575,19 @@ public:
else res[i] = std::tolower(res[i]);
}
return res;
} else if (method->get_name() == "replace") {
vargs.expectArgs("replace method", {2, 3}, {0, 0});
auto before = vargs.args[0].get<std::string>();
auto after = vargs.args[1].get<std::string>();
auto count = vargs.args.size() == 3 ? vargs.args[2].get<int64_t>()
: str.length();
size_t start_pos = 0;
while ((start_pos = str.find(before, start_pos)) != std::string::npos &&
count-- > 0) {
str.replace(start_pos, before.length(), after);
start_pos += after.length();
}
return str;
}
}
throw std::runtime_error("Unknown method: " + method->get_name());
@@ -2151,7 +2164,7 @@ private:
}
}
if ((has_first_colon || has_second_colon) && (start || end || step)) {
if ((has_first_colon || has_second_colon)) {
index = std::make_shared<SliceExpr>(slice_loc, std::move(start), std::move(end), std::move(step));
} else {
index = std::move(start);
@@ -2653,11 +2666,11 @@ inline std::shared_ptr<Context> Context::builtins() {
auto & obj = args.at("object");
if (!obj.is_object()) {
throw std::runtime_error("Can only get item pairs from a mapping");
}
for (auto & key : obj.keys()) {
items.push_back(Value::array({key, obj.at(key)}));
}
}
for (auto & key : obj.keys()) {
items.push_back(Value::array({key, obj.at(key)}));
}
}
return items;
}));
globals.set("last", simple_function("last", { "items" }, [](const std::shared_ptr<Context> &, Value & args) {

22
scripts/sync_vendor.py Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env python3
import urllib.request
vendor = {
"https://github.com/nlohmann/json/releases/latest/download/json.hpp": "common/json.hpp",
"https://github.com/nlohmann/json/releases/latest/download/json_fwd.hpp": "common/json_fwd.hpp",
# sync manually
# "https://raw.githubusercontent.com/ochafik/minja/refs/heads/main/include/minja/minja.hpp": "common/minja/minja.hpp",
# "https://raw.githubusercontent.com/ochafik/minja/refs/heads/main/include/minja/chat-template.hpp": "common/minja/chat-template.hpp",
# "https://raw.githubusercontent.com/nothings/stb/refs/heads/master/stb_image.h": "vendor/stb/stb_image.h",
# "https://github.com/mackron/miniaudio/raw/refs/tags/0.11.22/miniaudio.h": "vendor/miniaudio/miniaudio.h",
# "https://raw.githubusercontent.com/yhirose/cpp-httplib/refs/tags/v0.20.1/httplib.h": "vendor/cpp-httplib/httplib.h",
}
for url, filename in vendor.items():
print(f"downloading {url} to {filename}") # noqa: NP100
urllib.request.urlretrieve(url, filename)