| 3903 | } |
| 3904 | |
| 3905 | int String::_count(const String& p_string, int p_from, int p_to, bool p_case_insensitive) const |
| 3906 | { |
| 3907 | if (p_string.is_empty()) |
| 3908 | { |
| 3909 | return 0; |
| 3910 | } |
| 3911 | int len = length(); |
| 3912 | int slen = p_string.length(); |
| 3913 | if (len < slen) |
| 3914 | { |
| 3915 | return 0; |
| 3916 | } |
| 3917 | String str; |
| 3918 | if (p_from >= 0 && p_to >= 0) |
| 3919 | { |
| 3920 | if (p_to == 0) |
| 3921 | { |
| 3922 | p_to = len; |
| 3923 | } |
| 3924 | else if (p_from >= p_to) |
| 3925 | { |
| 3926 | return 0; |
| 3927 | } |
| 3928 | if (p_from == 0 && p_to == len) |
| 3929 | { |
| 3930 | str = String(); |
| 3931 | str.copy_from_unchecked(&get_data()[0], len); |
| 3932 | } |
| 3933 | else |
| 3934 | { |
| 3935 | str = substr(p_from, p_to - p_from); |
| 3936 | } |
| 3937 | } |
| 3938 | else |
| 3939 | { |
| 3940 | return 0; |
| 3941 | } |
| 3942 | int c = 0; |
| 3943 | int idx = -1; |
| 3944 | do |
| 3945 | { |
| 3946 | idx = p_case_insensitive ? str.findn(p_string) : str.find(p_string); |
| 3947 | if (idx != -1) |
| 3948 | { |
| 3949 | str = str.substr(idx + slen, str.length() - slen); |
| 3950 | ++c; |
| 3951 | } |
| 3952 | } while (idx != -1); |
| 3953 | return c; |
| 3954 | } |
| 3955 | |
| 3956 | int String::count(const String& p_string, int p_from, int p_to) const |
| 3957 | { |