MCPcopy Create free account
hub / github.com/NativeScript/android / regex_search

Method regex_search

test-app/runtime/src/main/cpp/URLPatternImpl.cpp:41–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41std::optional<std::vector<std::optional<std::string>>>
42v8_regex_provider::regex_search(std::string_view input,
43 const tns::v8_regex_provider::regex_type &pattern) {
44 auto isolate = v8::Isolate::GetCurrent();
45 if (isolate == nullptr) {
46 return std::nullopt;
47 }
48 auto ctx = isolate->GetCurrentContext();
49 auto patt = pattern.Get(isolate);
50 if (patt.IsEmpty()) {
51 return std::nullopt;
52 }
53
54 v8::Local<v8::String> local_input;
55 if (!v8::String::NewFromUtf8(
56 isolate, input.data(), v8::NewStringType::kNormal, input.size())
57 .ToLocal(&local_input)) {
58 return std::nullopt;
59 }
60
61 v8::Local<v8::Object> matches;
62 if (!patt->Exec(isolate->GetCurrentContext(), local_input).ToLocal(
63 &matches) || matches->IsNull()) {
64 return std::nullopt;
65 }
66
67 std::vector<std::optional<std::string>> ret;
68 if (matches->IsArray()) {
69 auto array = matches.As<v8::Array>();
70 auto len = array->Length();
71 ret.reserve(len);
72 for (int i = 0; i < len; i++) {
73 v8::Local<v8::Value> item;
74 if (!array->Get(isolate->GetCurrentContext(), i).ToLocal(&item)) {
75 return std::nullopt;
76 }
77
78 if (item->IsUndefined()) {
79 ret.emplace_back(std::nullopt);
80 } else if (item->IsString()) {
81 ret.emplace_back(ArgConverter::ConvertToString(
82 item->ToString(ctx).ToLocalChecked()));
83 }
84 }
85 }
86
87 return ret;
88}
89
90bool v8_regex_provider::regex_match(std::string_view input,
91 const tns::v8_regex_provider::regex_type &pattern) {

Callers

nothing calls this directly

Calls 14

ToLocalMethod · 0.80
ExecMethod · 0.80
IsUndefinedMethod · 0.80
emplace_backMethod · 0.80
IsStringMethod · 0.80
ToLocalCheckedMethod · 0.80
GetMethod · 0.45
IsEmptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
IsNullMethod · 0.45
LengthMethod · 0.45

Tested by

no test coverage detected