W5
This commit is contained in:
+45
-17
@@ -642,41 +642,69 @@ StringList regex_split(String pattern, String subject, String flags)
|
||||
|
||||
#else
|
||||
|
||||
// PCRE2 is not compiled into the wasm core; regex runs host-side (the host
|
||||
// already links libpcre2). One UCEB1-marshalled hostcall carries the request
|
||||
// {op,pattern,subject,flags,replacement} in and the result tree out — the host
|
||||
// runs the real regex_* and packs the answer. See uce_host_regex in
|
||||
// src/wasm/worker.cpp.
|
||||
extern "C" size_t uce_host_regex(const char* in, size_t in_len, char* out, size_t cap);
|
||||
|
||||
static DValue wasm_regex_call(String op, String pattern, String subject, String flags, String replacement = "")
|
||||
{
|
||||
DValue request;
|
||||
request["op"] = op;
|
||||
request["pattern"] = pattern;
|
||||
request["subject"] = subject;
|
||||
request["flags"] = flags;
|
||||
request["replacement"] = replacement;
|
||||
String encoded = ucb_encode(request);
|
||||
size_t need = uce_host_regex(encoded.data(), encoded.size(), 0, 0);
|
||||
if(need == 0)
|
||||
return(DValue());
|
||||
String buffer(need, 0);
|
||||
size_t got = uce_host_regex(encoded.data(), encoded.size(), &buffer[0], need);
|
||||
if(got == 0 || got > need)
|
||||
return(DValue());
|
||||
DValue response;
|
||||
String error;
|
||||
ucb_decode(String(buffer.data(), got), response, &error);
|
||||
return(response);
|
||||
}
|
||||
|
||||
bool regex_match(String pattern, String subject, String flags)
|
||||
{
|
||||
(void)pattern; (void)subject; (void)flags;
|
||||
return(false);
|
||||
return(wasm_regex_call("match", pattern, subject, flags)["bool"].to_bool());
|
||||
}
|
||||
|
||||
DValue regex_search(String pattern, String subject, String flags)
|
||||
{
|
||||
DValue result;
|
||||
result["matched"].set_bool(false);
|
||||
result["pattern"] = pattern;
|
||||
result["flags"] = flags == "" ? "default" : flags;
|
||||
return(result);
|
||||
DValue response = wasm_regex_call("search", pattern, subject, flags);
|
||||
DValue* tree = response.key("tree");
|
||||
return(tree ? *tree : DValue());
|
||||
}
|
||||
|
||||
DValue regex_search_all(String pattern, String subject, String flags)
|
||||
{
|
||||
DValue result;
|
||||
result["matched"].set_bool(false);
|
||||
result["pattern"] = pattern;
|
||||
result["flags"] = flags == "" ? "default" : flags;
|
||||
result["count"] = (f64)0;
|
||||
return(result);
|
||||
DValue response = wasm_regex_call("search_all", pattern, subject, flags);
|
||||
DValue* tree = response.key("tree");
|
||||
return(tree ? *tree : DValue());
|
||||
}
|
||||
|
||||
String regex_replace(String pattern, String replacement, String subject, String flags)
|
||||
{
|
||||
(void)pattern; (void)replacement; (void)flags;
|
||||
return(subject);
|
||||
return(wasm_regex_call("replace", pattern, subject, flags, replacement)["text"].to_string());
|
||||
}
|
||||
|
||||
StringList regex_split(String pattern, String subject, String flags)
|
||||
{
|
||||
(void)pattern; (void)flags;
|
||||
return(StringList{ subject });
|
||||
DValue response = wasm_regex_call("split", pattern, subject, flags);
|
||||
StringList result;
|
||||
DValue* list = response.key("list");
|
||||
if(list)
|
||||
list->each([&](const DValue& part, String) {
|
||||
result.push_back(part.to_string());
|
||||
});
|
||||
return(result);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user