1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

clang format apply

This commit is contained in:
Leonid Fedorov
2022-01-21 16:43:49 +00:00
parent 6b6411229f
commit 04752ec546
1376 changed files with 393460 additions and 412662 deletions

View File

@ -16,10 +16,10 @@
MA 02110-1301, USA. */
/****************************************************************************
* $Id: func_replace.cpp 3923 2013-06-19 21:43:06Z bwilkinson $
*
*
****************************************************************************/
* $Id: func_replace.cpp 3923 2013-06-19 21:43:06Z bwilkinson $
*
*
****************************************************************************/
#include <string>
using namespace std;
@ -34,150 +34,143 @@ using namespace rowgroup;
#include "joblisttypes.h"
using namespace joblist;
namespace funcexp
{
CalpontSystemCatalog::ColType Func_replace::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType)
CalpontSystemCatalog::ColType Func_replace::operationType(FunctionParm& fp,
CalpontSystemCatalog::ColType& resultType)
{
// operation type is not used by this functor
return fp[0]->data()->resultType();
// operation type is not used by this functor
return fp[0]->data()->resultType();
}
std::string Func_replace::getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
std::string Func_replace::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& isNull,
execplan::CalpontSystemCatalog::ColType& ct)
{
CHARSET_INFO* cs = ct.getCharset();
CHARSET_INFO* cs = ct.getCharset();
const string& str = fp[0]->data()->getStrVal(row, isNull);
if (isNull)
return "";
size_t strLen = str.length();
const string& fromstr = fp[1]->data()->getStrVal(row, isNull);
if (isNull)
return "";
if (fromstr.length() == 0)
return str;
size_t fromLen = fromstr.length();
const string& tostr = fp[2]->data()->getStrVal(row, isNull);
if (isNull)
return "";
size_t toLen = tostr.length();
const string& str = fp[0]->data()->getStrVal(row, isNull);
if (isNull)
return "";
size_t strLen = str.length();
bool binaryCmp = (cs->state & MY_CS_BINSORT) || !cs->use_mb();
string newstr;
size_t pos = 0;
if (binaryCmp)
const string& fromstr = fp[1]->data()->getStrVal(row, isNull);
if (isNull)
return "";
if (fromstr.length() == 0)
return str;
size_t fromLen = fromstr.length();
const string& tostr = fp[2]->data()->getStrVal(row, isNull);
if (isNull)
return "";
size_t toLen = tostr.length();
bool binaryCmp = (cs->state & MY_CS_BINSORT) || !cs->use_mb();
string newstr;
size_t pos = 0;
if (binaryCmp)
{
// Count the number of fromstr in strend so we can reserve buffer space.
int count = 0;
do
{
// Count the number of fromstr in strend so we can reserve buffer space.
int count = 0;
do
{
++count;
pos = str.find(fromstr, pos + fromLen);
}
while (pos != string::npos);
newstr.reserve(strLen + (count * ((int)toLen - (int)fromLen)) + 1);
uint32_t i = 0;
pos = str.find(fromstr);
if (pos == string::npos)
return str;
// Move the stuff into newstr
do
{
if (pos > i)
newstr = newstr + str.substr(i, pos - i);
++count;
pos = str.find(fromstr, pos + fromLen);
} while (pos != string::npos);
newstr = newstr + tostr;
i = pos + fromLen;
pos = str.find(fromstr, i);
}
while (pos != string::npos);
newstr = newstr + str.substr(i, string::npos);
}
else
newstr.reserve(strLen + (count * ((int)toLen - (int)fromLen)) + 1);
uint32_t i = 0;
pos = str.find(fromstr);
if (pos == string::npos)
return str;
// Move the stuff into newstr
do
{
// UTF
const char* src = str.c_str();
const char* srcEnd = src + strLen;
const char* srchEnd = srcEnd - fromLen + 1;
const char* from = fromstr.c_str();
const char* fromEnd = from + fromLen;
const char* to = tostr.c_str();
const char* ptr = src;
char *i,*j;
size_t count = 10; // Some arbitray number to reserve some space to start.
int growlen = (int)toLen - (int)fromLen;
growlen = growlen < 1 ? 1 : growlen;
growlen *= count;
newstr.reserve(strLen + (count * growlen) + 1);
size_t maxsize = newstr.capacity();
uint32_t l;
if (pos > i)
newstr = newstr + str.substr(i, pos - i);
// We don't know where byte patterns might match so
// we start at the beginning of the string and move forward
// one character at a time until we find a match. Then we can
// move the src bytes and add in the to bytes,then try again.
while (ptr < srchEnd)
newstr = newstr + tostr;
i = pos + fromLen;
pos = str.find(fromstr, i);
} while (pos != string::npos);
newstr = newstr + str.substr(i, string::npos);
}
else
{
// UTF
const char* src = str.c_str();
const char* srcEnd = src + strLen;
const char* srchEnd = srcEnd - fromLen + 1;
const char* from = fromstr.c_str();
const char* fromEnd = from + fromLen;
const char* to = tostr.c_str();
const char* ptr = src;
char *i, *j;
size_t count = 10; // Some arbitray number to reserve some space to start.
int growlen = (int)toLen - (int)fromLen;
growlen = growlen < 1 ? 1 : growlen;
growlen *= count;
newstr.reserve(strLen + (count * growlen) + 1);
size_t maxsize = newstr.capacity();
uint32_t l;
// We don't know where byte patterns might match so
// we start at the beginning of the string and move forward
// one character at a time until we find a match. Then we can
// move the src bytes and add in the to bytes,then try again.
while (ptr < srchEnd)
{
bool found = false;
if (*ptr == *from) // If the first byte matches, maybe we have a match
{
// Do a byte by byte compare of src at that spot against from
i = const_cast<char*>(ptr) + 1;
j = const_cast<char*>(from) + 1;
found = true;
while (j != fromEnd)
{
bool found = false;
if (*ptr == *from) // If the first byte matches, maybe we have a match
{
// Do a byte by byte compare of src at that spot against from
i = const_cast<char*>(ptr) + 1;
j = const_cast<char*>(from) + 1;
found = true;
while (j != fromEnd)
{
if (*i++ != *j++)
{
found = false;
break;
}
}
}
if (found)
{
if (ptr < i)
{
int mvsize = ptr - src;
if (newstr.length() + mvsize + toLen > maxsize)
{
// We need a re-alloc
newstr.reserve(maxsize + growlen);
maxsize = newstr.capacity();
growlen *= 2;
}
newstr.append(src, ptr - src);
src += mvsize + fromLen;
ptr = src;
}
newstr.append(to, toLen);
}
else
{
// move to the next character
if ((l = my_ismbchar(cs, ptr, srcEnd))) // returns the number of bytes in the leading char or zero if one byte
ptr += l;
else
++ptr;
}
if (*i++ != *j++)
{
found = false;
break;
}
}
// Copy in the trailing src chars.
newstr.append(src, srcEnd - src);
}
if (found)
{
if (ptr < i)
{
int mvsize = ptr - src;
if (newstr.length() + mvsize + toLen > maxsize)
{
// We need a re-alloc
newstr.reserve(maxsize + growlen);
maxsize = newstr.capacity();
growlen *= 2;
}
newstr.append(src, ptr - src);
src += mvsize + fromLen;
ptr = src;
}
newstr.append(to, toLen);
}
else
{
// move to the next character
if ((l = my_ismbchar(cs, ptr,
srcEnd))) // returns the number of bytes in the leading char or zero if one byte
ptr += l;
else
++ptr;
}
}
return newstr;
// Copy in the trailing src chars.
newstr.append(src, srcEnd - src);
}
return newstr;
}
} // namespace funcexp
} // namespace funcexp
// vim:ts=4 sw=4: