mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 10:14:19 +01:00
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.
This commit is contained in:
parent
cd873c8688
commit
c115559b66
2 changed files with 17 additions and 12 deletions
|
@ -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 @@ public:
|
|||
|
||||
// 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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue