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

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -39,20 +39,20 @@ namespace funcexp
{
CalpontSystemCatalog::ColType Func_trim::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_trim::getStrVal(rowgroup::Row& row,
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType&)
FunctionParm& fp,
bool& isNull,
execplan::CalpontSystemCatalog::ColType&)
{
// The number of characters (not bytes) in our input tstr.
// Not all of these are necessarily significant. We need to search for the
// Not all of these are necessarily significant. We need to search for the
// NULL terminator to be sure.
size_t strwclen;
size_t strwclen;
// this holds the number of characters (not bytes) in ourtrim tstr.
size_t trimwclen;
@ -64,79 +64,88 @@ std::string Func_trim::getStrVal(rowgroup::Row& row,
if (isNull)
return "";
if (tstr.empty() || tstr.length() == 0)
return tstr;
// Rather than calling the wideconvert functions with a null buffer to
// Rather than calling the wideconvert functions with a null buffer to
// determine the size of buffer to allocate, we can be sure the wide
// char string won't be longer than:
strwclen = tstr.length(); // a guess to start with. This will be >= to the real count.
int bufsize = (strwclen+1) * sizeof(wchar_t);
int bufsize = (strwclen + 1) * sizeof(wchar_t);
// Convert the string to wide characters. Do all further work in wide characters
wchar_t* wcbuf = (wchar_t*)alloca(bufsize);
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen+1);
// Bad char in mbc can return -1
if(strwclen == static_cast<size_t>(-1))
strwclen = 0;
strwclen = utf8::idb_mbstowcs(wcbuf, tstr.c_str(), strwclen + 1);
// Bad char in mbc can return -1
if (strwclen == static_cast<size_t>(-1))
strwclen = 0;
// Convert the trim string to wide
trimwclen = trim.length(); // A guess to start.
int trimbufsize = (trimwclen+1) * sizeof(wchar_t);
int trimbufsize = (trimwclen + 1) * sizeof(wchar_t);
wchar_t* wctrim = (wchar_t*)alloca(trimbufsize);
size_t trimlen = utf8::idb_mbstowcs(wctrim,trim.c_str(), trimwclen+1);
// Bad char in mbc can return -1
if(trimlen == static_cast<size_t>(-1))
trimlen = 0;
size_t trimlen = utf8::idb_mbstowcs(wctrim, trim.c_str(), trimwclen + 1);
// Bad char in mbc can return -1
if (trimlen == static_cast<size_t>(-1))
trimlen = 0;
size_t trimCmpLen = trimlen * sizeof(wchar_t);
const wchar_t* oPtr = wcbuf; // To remember the start of the string
const wchar_t* aPtr = oPtr;
const wchar_t* aEnd = wcbuf+strwclen-1;
const wchar_t* aEnd = wcbuf + strwclen - 1;
size_t trimCnt = 0;
if(trimlen > 0)
{
if (trimlen == 1)
{
// If trim is a single char, then don't spend the overhead for memcmp.
wchar_t chr = wctrim[0];
// remove leading
while (aPtr != aEnd && *aPtr == chr)
{
aPtr++;
++trimCnt;
}
// remove trailing
while (aEnd != aPtr && *aEnd == chr)
{
aEnd--;
++trimCnt;
}
}
else
{
aEnd-=(trimlen-1); // So we don't compare past the end of the string.
// remove leading
while (aPtr <= aEnd && !memcmp(aPtr, wctrim, trimCmpLen))
{
aPtr+=trimlen;
trimCnt+=trimlen;
}
// remove trailing
while (aPtr <= aEnd && !memcmp(aEnd, wctrim, trimCmpLen))
{
aEnd-=trimlen; //BUG 5241
trimCnt+=trimlen;
}
}
}
// Bug 5110 - error in allocating enough memory for utf8 chars
size_t aLen = strwclen-trimCnt;
wstring trimmed = wstring(aPtr, aLen);
// Turn back to a string
return utf8::wstring_to_utf8(trimmed.c_str());
}
if (trimlen > 0)
{
if (trimlen == 1)
{
// If trim is a single char, then don't spend the overhead for memcmp.
wchar_t chr = wctrim[0];
// remove leading
while (aPtr != aEnd && *aPtr == chr)
{
aPtr++;
++trimCnt;
}
// remove trailing
while (aEnd != aPtr && *aEnd == chr)
{
aEnd--;
++trimCnt;
}
}
else
{
aEnd -= (trimlen - 1); // So we don't compare past the end of the string.
// remove leading
while (aPtr <= aEnd && !memcmp(aPtr, wctrim, trimCmpLen))
{
aPtr += trimlen;
trimCnt += trimlen;
}
// remove trailing
while (aPtr <= aEnd && !memcmp(aEnd, wctrim, trimCmpLen))
{
aEnd -= trimlen; //BUG 5241
trimCnt += trimlen;
}
}
}
// Bug 5110 - error in allocating enough memory for utf8 chars
size_t aLen = strwclen - trimCnt;
wstring trimmed = wstring(aPtr, aLen);
// Turn back to a string
return utf8::wstring_to_utf8(trimmed.c_str());
}
} // namespace funcexp