in src/main/cpp/nameabbreviator.cpp [267:355]
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())
{
return std::make_shared<MaxElementAbbreviator>(StringHelper::toInt(trimmed));
}
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();
}