| 3618 | } |
| 3619 | |
| 3620 | int 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 | |
| 3654 | int String::_count(const char *p_string, int p_from, int p_to, bool p_case_insensitive) const { |
| 3655 | int substring_length = strlen(p_string); |