Implement r_str_lstr API for R2_600

This commit is contained in:
pancake 2024-08-30 23:21:50 +02:00 committed by pancake
parent cfba7395e7
commit d3b8528a85
2 changed files with 28 additions and 0 deletions

View File

@ -197,6 +197,9 @@ R_API ut64 r_str_hash64(const char *str);
R_API char *r_str_trim_nc(char *str);
R_API const char *r_str_nstr(const char *from, const char *to, int size);
R_API const char *r_str_lchr(const char *str, char chr);
#if R2_600
R_API char *r_str_lstr(const char *s, const char *sub);
#endif
R_API const char *r_sub_str_lchr(const char *str, int start, int end, char chr);
R_API const char *r_sub_str_rchr(const char *str, int start, int end, char chr);
R_API char *r_str_ichr(char *str, char chr);

View File

@ -540,6 +540,31 @@ R_API const char *r_str_lchr(const char *str, char chr) {
return NULL;
}
#if R2_600
R_API char *r_str_lstr(const char *s, const char *sub) {
if (!s || !sub) {
return NULL; // Handle null input
}
const size_t sub_len = strlen (sub);
const size_t s_len = strlen (s);
if (sub_len == 0 || s_len < sub_len) {
return NULL; // No valid substring can be found
}
const char *p = s + s_len - sub_len;
while (p >= s) {
if (strncmp (p, sub, sub_len) == 0) {
return (char *)p;
}
p--;
}
return NULL;
}
#endif
/* find the last char chr in the substring str[start:end] with end not included */
R_API const char *r_sub_str_lchr(const char *str, int start, int end, char chr) {
do {