| 415 | } |
| 416 | |
| 417 | Array ScriptTextEditor::_inline_object_parse(const String &p_text) { |
| 418 | Array result; |
| 419 | int i_end_previous = 0; |
| 420 | int i_start = p_text.find("Color"); |
| 421 | |
| 422 | while (i_start != -1) { |
| 423 | // Ignore words that just have "Color" in them. |
| 424 | if (i_start != 0 && ('_' + p_text.substr(i_start - 1, 1)).is_valid_ascii_identifier()) { |
| 425 | i_end_previous = MAX(i_end_previous, i_start); |
| 426 | i_start = p_text.find("Color", i_start + 1); |
| 427 | continue; |
| 428 | } |
| 429 | |
| 430 | const int i_par_start = p_text.find_char('(', i_start + 5); |
| 431 | const int i_par_end = p_text.find_char(')', i_start + 5); |
| 432 | if (i_par_start == -1 || i_par_end == -1) { |
| 433 | i_end_previous = MAX(i_end_previous, i_start); |
| 434 | i_start = p_text.find("Color", i_start + 1); |
| 435 | continue; |
| 436 | } |
| 437 | |
| 438 | Dictionary color_info; |
| 439 | color_info["column"] = i_start; |
| 440 | color_info["width_ratio"] = 1.0; |
| 441 | color_info["color_end"] = i_par_end; |
| 442 | |
| 443 | const String fn_name = p_text.substr(i_start + 5, i_par_start - i_start - 5); |
| 444 | const String s_params = p_text.substr(i_par_start + 1, i_par_end - i_par_start - 1); |
| 445 | bool has_added_color = false; |
| 446 | |
| 447 | if (fn_name.is_empty()) { |
| 448 | String stripped = s_params.strip_edges(true, true); |
| 449 | if (stripped.length() > 1 && (stripped[0] == '"' || stripped[0] == '\'')) { |
| 450 | // String constructor. |
| 451 | const char32_t string_delimiter = stripped[0]; |
| 452 | if (stripped[stripped.length() - 1] == string_delimiter) { |
| 453 | const String color_string = stripped.substr(1, stripped.length() - 2); |
| 454 | if (!color_string.contains_char(string_delimiter)) { |
| 455 | color_info["color"] = Color::from_string(color_string, Color()); |
| 456 | color_info["color_mode"] = MODE_STRING; |
| 457 | has_added_color = true; |
| 458 | } |
| 459 | } |
| 460 | } else if (stripped.length() == 10 && stripped.begins_with("0x")) { |
| 461 | // Hex constructor. |
| 462 | const String color_string = stripped.substr(2); |
| 463 | if (color_string.is_valid_hex_number(false)) { |
| 464 | color_info["color"] = Color::from_string(color_string, Color()); |
| 465 | color_info["color_mode"] = MODE_HEX; |
| 466 | has_added_color = true; |
| 467 | } |
| 468 | } else if (stripped.is_empty()) { |
| 469 | // Empty Color() constructor. |
| 470 | color_info["color"] = Color(); |
| 471 | color_info["color_mode"] = MODE_RGB; |
| 472 | has_added_color = true; |
| 473 | } |
| 474 | } |
nothing calls this directly
no test coverage detected