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

Method find

core/string/ustring.cpp:3067–3109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3065}
3066
3067int 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
3111int String::find(const char *p_str, int p_from) const {
3112 if (p_from < 0 || !p_str) {

Callers 7

parse_urlMethod · 0.45
find_charMethod · 0.45
_countMethod · 0.45
_replace_commonFunction · 0.45
simplify_pathMethod · 0.45
try_exact_matchMethod · 0.45
get_messageMethod · 0.45

Calls 4

get_dataFunction · 0.85
strlenFunction · 0.85
lengthMethod · 0.45
get_dataMethod · 0.45

Tested by

no test coverage detected