| 3065 | } |
| 3066 | |
| 3067 | int String::find(const String &p_str, int p_from) const { |
| 3068 | if (p_from < 0) { |
| 3069 | return -1; |
| 3070 | } |
| 3071 | |
| 3072 | const int src_len = p_str.length(); |
| 3073 | |
| 3074 | const int len = length(); |
| 3075 | |
| 3076 | if (src_len == 0 || len == 0) { |
| 3077 | return -1; // won't find anything! |
| 3078 | } |
| 3079 | |
| 3080 | if (src_len == 1) { |
| 3081 | return find_char(p_str[0], p_from); // Optimize with single-char find. |
| 3082 | } |
| 3083 | |
| 3084 | const char32_t *src = get_data(); |
| 3085 | const char32_t *str = p_str.get_data(); |
| 3086 | |
| 3087 | for (int i = p_from; i <= (len - src_len); i++) { |
| 3088 | bool found = true; |
| 3089 | for (int j = 0; j < src_len; j++) { |
| 3090 | int read_pos = i + j; |
| 3091 | |
| 3092 | if (read_pos >= len) { |
| 3093 | ERR_PRINT("read_pos>=len"); |
| 3094 | return -1; |
| 3095 | } |
| 3096 | |
| 3097 | if (src[read_pos] != str[j]) { |
| 3098 | found = false; |
| 3099 | break; |
| 3100 | } |
| 3101 | } |
| 3102 | |
| 3103 | if (found) { |
| 3104 | return i; |
| 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | return -1; |
| 3109 | } |
| 3110 | |
| 3111 | int String::find(const char *p_str, int p_from) const { |
| 3112 | if (p_from < 0 || !p_str) { |
no test coverage detected