const char* content = R"(
void Fubame(){
//int a = (3>4) ? 200:100;
int a = ((3>4)? 200:100) ?(3>4? 300:100):3400;
int b = 3>4 ? 400:100;
}
)";
std::string dd = content;
int iPos = 0;
int length = dd.length();
auto data = dd.c_str();
std::stack<SAN_MU> sanmuStack;
do {
if (dd[iPos] == '/' && dd[iPos + 1] == '/') {
while (iPos < length) {
if (dd[iPos] == '\n') {
iPos++;
break;
}
iPos++;
}
}
else if (dd[iPos] == '/' && dd[iPos + 1] == '*') {
while (iPos < length) {
if (dd[iPos] == '*' && dd[iPos + 1] == '/') {
iPos += 2;
break;
}
iPos++;
}
}
if (dd[iPos] == '=') {
SAN_MU san_mu;
san_mu.iPosStart = iPos;
std::stack<SAN_MU> emptyTemp;
emptyTemp.push(san_mu);
sanmuStack.swap(emptyTemp);
}
else if (dd[iPos] == '\n') {
if (sanmuStack.size() > 0) {
std::stack<SAN_MU> emptyTemp;
sanmuStack.swap(emptyTemp);
}
}
else if (dd[iPos] == '(') {
SAN_MU san_mu;
san_mu.iPosStart = iPos;
sanmuStack.push(san_mu);
}
if (sanmuStack.size() > 0) {
auto& san_mu = sanmuStack.top();
if (dd[iPos] == '?') {
san_mu.iPosQuestion = iPos;
}
else if (dd[iPos] == ':') {
san_mu.iPosMaohao = iPos;
}
else if (dd[iPos] == ';' || dd[iPos] == ')') {
san_mu.iPosEnd = iPos;
}
if (san_mu.iPosStart >= 0 && san_mu.iPosQuestion >= 0 && san_mu.iPosMaohao >= 0 && san_mu.iPosEnd >= 0) {
auto& iPosStart = san_mu.iPosStart;
auto& iPosQuestion = san_mu.iPosQuestion;
auto& iPosMaohao = san_mu.iPosMaohao;
auto& iPosEnd = san_mu.iPosEnd;
std::string str = dd.substr(iPosStart + 1, iPosEnd - iPosStart - 1);
std::string startStr = str.substr(0, iPosQuestion - iPosStart - 1);
std::string midStr = str.substr(iPosQuestion - iPosStart, iPosMaohao - iPosQuestion - 1);
std::string endStr = str.substr(iPosMaohao - iPosStart, iPosEnd - iPosQuestion - 1);
str = "(" + startStr + ")?(" + midStr + "):(" + endStr + ")";
dd.replace(iPosStart + 1, iPosEnd - iPosStart - 1, str);
length = dd.length();
data = dd.c_str();
iPos = iPosStart + 1 + str.length();
iPosStart = -1;
iPosQuestion = -1;
iPosMaohao = -1;
iPosEnd = -1;
}
if (dd[iPos] == ')') {
sanmuStack.pop();
}
}
iPos++;
} while (iPos < length);
content = data;