in src/main/cpp/nameabbreviator.cpp [269:373]
NameAbbreviatorPtr NameAbbreviator::getAbbreviator(const LogString& pattern)
{
if (pattern.length() > 0)
{
// if pattern is just spaces and numbers then
// use MaxElementAbbreviator
LogString trimmed(StringHelper::trim(pattern));
if (trimmed.length() == 0)
{
return getDefaultAbbreviator();
}
LogString::size_type i = 0;
while (
(i < trimmed.length()) && (trimmed[i] >= 0x30 /* '0' */)
&& (trimmed[i] <= 0x39 /* '9' */))
{
i++;
}
//
// if all blanks and digits
//
if (i == trimmed.length())
{
int len = 256;
try
{
len = StringHelper::toInt(trimmed);
}
catch (const std::out_of_range& ex)
{
LogLog::warn(LOG4CXX_STR("Invalid name abreviator pattern: ") + pattern, ex);
}
if(len > 256){
len = 256;
}else if( len < 0 ){
len = 0;
}
return std::make_shared<MaxElementAbbreviator>(len);
}
std::vector<PatternAbbreviatorFragment> fragments;
logchar ellipsis;
int charCount;
LogString::size_type pos = 0;
while (pos < trimmed.length())
{
LogString::size_type ellipsisPos = pos;
if (trimmed[pos] == 0x2A /* '*' */)
{
charCount = INT_MAX;
ellipsisPos++;
}
else
{
if ((trimmed[pos] >= 0x30 /* '0' */)
&& (trimmed[pos] <= 0x39 /* '9' */))
{
charCount = trimmed[pos] - 0x30 /* '0' */;
ellipsisPos++;
}
else
{
charCount = 0;
}
}
ellipsis = 0;
if (ellipsisPos < trimmed.length())
{
ellipsis = trimmed[ellipsisPos];
if (ellipsis == 0x2E /* '.' */)
{
ellipsis = 0;
}
}
fragments.push_back(PatternAbbreviatorFragment(charCount, ellipsis));
pos = trimmed.find(0x2E /* '.' */, pos);
if (pos == LogString::npos)
{
break;
}
pos++;
}
return std::make_shared<PatternAbbreviator>(fragments);
}
//
// no matching abbreviation, return defaultAbbreviator
//
return getDefaultAbbreviator();
}