MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / rfind

Method rfind

modules/gui/gui/src/backend/text_server/ustring.cpp:3688–3744  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3686}
3687
3688int String::rfind(const String& p_str, int p_from) const
3689{
3690 // establish a limit
3691 int limit = length() - p_str.length();
3692 if (limit < 0)
3693 {
3694 return -1;
3695 }
3696
3697 // establish a starting point
3698 if (p_from < 0)
3699 {
3700 p_from = limit;
3701 }
3702 else if (p_from > limit)
3703 {
3704 p_from = limit;
3705 }
3706
3707 int src_len = p_str.length();
3708 int len = length();
3709
3710 if (src_len == 0 || len == 0)
3711 {
3712 return -1; // won't find anything!
3713 }
3714
3715 const char32_t* src = get_data();
3716
3717 for (int i = p_from; i >= 0; i--)
3718 {
3719 bool found = true;
3720 for (int j = 0; j < src_len; j++)
3721 {
3722 int read_pos = i + j;
3723
3724 if (read_pos >= len)
3725 {
3726 ERR_PRINT("read_pos>=len");
3727 return -1;
3728 }
3729
3730 if (src[read_pos] != p_str[j])
3731 {
3732 found = false;
3733 break;
3734 }
3735 }
3736
3737 if (found)
3738 {
3739 return i;
3740 }
3741 }
3742
3743 return -1;
3744}
3745

Callers 2

parse_urlMethod · 0.45
get_base_dirMethod · 0.45

Calls 3

lengthFunction · 0.50
get_dataFunction · 0.50
lengthMethod · 0.45

Tested by

no test coverage detected