static LogString convertSingleSequence()

in src/main/cpp/colorstartpatternconverter.cpp [93:133]


static LogString convertSingleSequence(const LogString& sequence, Pool& pool){
	LogString strInParens;
	bool inParens = false;
	bool hasParens = false;
	size_t x = 0;

	for(x = 0; x < sequence.length(); x++){
		if( sequence[x] == '(' && !inParens ){
			inParens = true;
			hasParens = true;
			continue;
		}else if( sequence[x] == '(' && inParens ){
			// Unbalanced parens - parse invalid
			return LOG4CXX_STR("");
		}

		if( sequence[x] == ')' && inParens ){
			hasParens = true;
			inParens = false;
			break;
		}

		if( inParens ){
			strInParens.push_back(sequence[x]);
		}
	}

	if( (x != (sequence.length() - 1) || inParens) && hasParens ){
		// Unbalanced parens, or more data in the string than we expected - parse invalid
		return LOG4CXX_STR("");
	}

	if(StringHelper::startsWith(sequence, LOG4CXX_STR("fg("))){
		// Parse foreground
		return colorToANSISequence(strInParens, true, pool);
	}else if(StringHelper::startsWith(sequence, LOG4CXX_STR("bg("))){
		return colorToANSISequence(strInParens, false, pool);
	}else{
		return graphicsModeToANSISequence(sequence, pool);
	}
}