Commit c115559b authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

Extend Binary_string::strstr to also take in a const char pointer

One shouldn't have to instantiate a Binary_string every time a strstr
call is needed.
parent cd873c86
......@@ -677,33 +677,37 @@ bool String::append_with_prefill(const char *s,uint32 arg_length,
}
int Binary_string::strstr(const Binary_string &s, uint32 offset)
int Binary_string::strstr(const char *search, uint32 search_length, uint32 offset)
{
if (s.length()+offset <= str_length)
if (search_length + offset <= str_length)
{
if (!s.length())
if (!search_length)
return ((int) offset); // Empty string is always found
const char *str = Ptr+offset;
const char *search=s.ptr();
const char *end=Ptr+str_length-s.length()+1;
const char *search_end=s.ptr()+s.length();
const char *str= Ptr + offset;
const char *end= Ptr + str_length - search_length + 1;
const char *search_end= search + search_length;
skip:
while (str != end)
{
if (*str++ == *search)
{
char *i,*j;
i=(char*) str; j=(char*) search+1;
while (j != search_end)
if (*i++ != *j++) goto skip;
return (int) (str-Ptr) -1;
char *i= (char*) str;
char *j= (char*) search + 1 ;
while (j != search_end)
if (*i++ != *j++) goto skip;
return (int) (str-Ptr) -1;
}
}
}
return -1;
}
int Binary_string::strstr(const Binary_string &s, uint32 offset)
{
return strstr(s.ptr(), s.length(), offset);
}
/*
** Search string from end. Offset is offset to the end of string
*/
......
......@@ -330,6 +330,7 @@ class Binary_string: public Sql_alloc
// Returns offset to substring or -1
int strstr(const Binary_string &search, uint32 offset=0);
int strstr(const char *search, uint32 search_length, uint32 offset=0);
// Returns offset to substring or -1
int strrstr(const Binary_string &search, uint32 offset=0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment