MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / replace_variant_constants

Function replace_variant_constants

compat/fake_csharp_script.cpp:328–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

326}
327
328String replace_variant_constants(const String &p_string) {
329 String new_string = p_string;
330 Ref<RegEx> re = memnew(RegEx());
331 re->compile("\\b([A-Za-z_][A-Za-z0-9_]+)\\.([A-Za-z_][A-Za-z0-9_]+)\\b");
332 Ref<RegExMatch> match = re->search(new_string);
333 while (match.is_valid()) {
334 auto start = match->get_start(0);
335 auto end = match->get_end(0);
336 String type_name = match->get_string(1);
337 Variant::Type type = string_to_variant_type(type_name);
338 if (type == Variant::VARIANT_MAX) {
339 match = re->search(new_string, end);
340 continue;
341 }
342 String constant_name = match->get_string(2);
343 if (!Variant::has_constant(type, constant_name)) {
344 match = re->search(new_string, end);
345 continue;
346 }
347 Variant constant = Variant::get_constant_value(type, constant_name);
348 if (constant == Variant()) {
349 match = re->search(new_string, end);
350 continue;
351 }
352 String old_string = new_string;
353 new_string = new_string.substr(0, start) + constant.get_construct_string() + new_string.substr(end);
354 if (new_string == old_string) {
355 match = re->search(new_string, end);
356 continue;
357 }
358 match = re->search(new_string);
359 }
360 return new_string;
361}
362
363bool parse_expression(const String &p_expression, Variant &r_value) {
364 Ref<Expression> expr = Ref<Expression>(memnew(Expression()));

Callers 1

reloadMethod · 0.85

Calls 3

string_to_variant_typeFunction · 0.85
get_stringMethod · 0.80
is_validMethod · 0.45

Tested by

no test coverage detected