in src/main/cpp/colorstartpatternconverter.cpp [224:277]
void ColorStartPatternConverter::parseColor(const LogString& color, LogString* result){
LogString lower = StringHelper::toLowerCase(color);
Pool pool;
// If the color we are trying to parse is blank, clear our result
if(StringHelper::trim(color).empty() ||
StringHelper::equalsIgnoreCase(color,
LOG4CXX_STR("NONE"),
LOG4CXX_STR("none"))){
result->clear();
return;
}
if( StringHelper::startsWith(lower, LOG4CXX_STR("\\x1b")) ){
if( color[color.size() - 1] != 'm' ){
// In order for this to be a valid ANSI escape sequence,
// it must end with an 'm'. If it does not, reject.
return;
}
// We start with an escape sequence, copy the data over after the escape byte
result->clear();
result->append(LOG4CXX_STR("\x1b"));
for( size_t x = 4; x < color.size(); x++ ){
result->push_back(color[x]);
}
}else{
// We do not start with an escape sequence: try to parse color
// Escape sequence information:
// https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
// https://en.wikipedia.org/wiki/ANSI_escape_code
result->clear();
result->append(LOG4CXX_STR("\x1b["));
LogString tmp;
for( size_t x = 0; x < color.size(); x++ ){
if(color[x] == '|' ){
LogString toAppend = convertSingleSequence(tmp, pool);
tmp.clear();
if(!toAppend.empty()){
result->push_back(';');
result->append(toAppend);
}
}else{
tmp.push_back(color[x]);
}
}
LogString toAppend = convertSingleSequence(tmp, pool);
tmp.clear();
if(!toAppend.empty()){
result->push_back(';');
result->append(toAppend);
}
result->append(LOG4CXX_STR("m"));
}
}