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

Method _count

core/string/ustring.cpp:3620–3652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3618}
3619
3620int String::_count(const String &p_string, int p_from, int p_to, bool p_case_insensitive) const {
3621 if (p_string.is_empty()) {
3622 return 0;
3623 }
3624 int len = length();
3625 int slen = p_string.length();
3626 if (len < slen) {
3627 return 0;
3628 }
3629 String str;
3630 if (p_from >= 0 && p_to >= 0) {
3631 if (p_to == 0) {
3632 p_to = len;
3633 } else if (p_from >= p_to) {
3634 return 0;
3635 }
3636 if (p_from == 0 && p_to == len) {
3637 str = *this;
3638 } else {
3639 str = substr(p_from, p_to - p_from);
3640 }
3641 } else {
3642 return 0;
3643 }
3644 int c = 0;
3645 int idx = 0;
3646 while ((idx = p_case_insensitive ? str.findn(p_string, idx) : str.find(p_string, idx)) != -1) {
3647 // Skip the occurrence itself.
3648 idx += slen;
3649 ++c;
3650 }
3651 return c;
3652}
3653
3654int String::_count(const char *p_string, int p_from, int p_to, bool p_case_insensitive) const {
3655 int substring_length = strlen(p_string);

Callers

nothing calls this directly

Calls 5

strlenFunction · 0.85
findnMethod · 0.80
is_emptyMethod · 0.45
lengthMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected