MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / rfindn

Method rfindn

core/string/ustring.cpp:3418–3466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3416}
3417
3418int String::rfindn(const String &p_str, int p_from) const {
3419 // establish a limit
3420 int limit = length() - p_str.length();
3421 if (limit < 0) {
3422 return -1;
3423 }
3424
3425 // establish a starting point
3426 if (p_from < 0) {
3427 p_from = limit;
3428 } else if (p_from > limit) {
3429 p_from = limit;
3430 }
3431
3432 int src_len = p_str.length();
3433 int len = length();
3434
3435 if (src_len == 0 || len == 0) {
3436 return -1; // won't find anything!
3437 }
3438
3439 const char32_t *src = get_data();
3440
3441 for (int i = p_from; i >= 0; i--) {
3442 bool found = true;
3443 for (int j = 0; j < src_len; j++) {
3444 int read_pos = i + j;
3445
3446 if (read_pos >= len) {
3447 ERR_PRINT("read_pos>=len");
3448 return -1;
3449 }
3450
3451 char32_t srcc = _find_lower(src[read_pos]);
3452 char32_t dstc = _find_lower(p_str[j]);
3453
3454 if (srcc != dstc) {
3455 found = false;
3456 break;
3457 }
3458 }
3459
3460 if (found) {
3461 return i;
3462 }
3463 }
3464
3465 return -1;
3466}
3467
3468int String::rfindn(const char *p_str, int p_from) const {
3469 const int source_length = length();

Callers 3

_search_lineMethod · 0.80
searchMethod · 0.80
_score_pathMethod · 0.80

Calls 4

get_dataFunction · 0.85
_find_lowerFunction · 0.85
strlenFunction · 0.85
lengthMethod · 0.45

Tested by

no test coverage detected