Simplify appendCharInLiteral

This commit is contained in:
Rangi42
2025-07-13 13:19:54 -04:00
parent 041b86b8dd
commit ce78280af3

View File

@@ -1451,37 +1451,26 @@ static void appendCharInLiteral(std::string &str, int c) {
if (rawMode) { if (rawMode) {
str += '\\'; str += '\\';
} }
str += c;
shiftChar(); shiftChar();
break; break;
case 'n': case 'n':
if (rawMode) { str += rawMode ? "\\n" : "\n";
str += '\\';
} else {
c = '\n';
}
shiftChar(); shiftChar();
break; break;
case 'r': case 'r':
if (rawMode) { str += rawMode ? "\\r" : "\r";
str += '\\';
} else {
c = '\r';
}
shiftChar(); shiftChar();
break; break;
case 't': case 't':
if (rawMode) { str += rawMode ? "\\t" : "\t";
str += '\\';
} else {
c = '\t';
}
shiftChar(); shiftChar();
break; break;
case '0': case '0':
if (rawMode) { if (rawMode) {
str += '\\'; str += "\\0";
} else { } else {
c = '\0'; str += '\0';
} }
shiftChar(); shiftChar();
break; break;
@@ -1492,7 +1481,7 @@ static void appendCharInLiteral(std::string &str, int c) {
case '\r': case '\r':
case '\n': case '\n':
discardLineContinuation(); discardLineContinuation();
return; // Do not copy the character break;
// Macro arg // Macro arg
case '@': case '@':
@@ -1511,15 +1500,16 @@ static void appendCharInLiteral(std::string &str, int c) {
if (auto arg = readMacroArg(c); arg) { if (auto arg = readMacroArg(c); arg) {
appendExpandedString(str, *arg); appendExpandedString(str, *arg);
} }
return; // Do not copy an additional character break;
case EOF: // Can't really print that one case EOF: // Can't really print that one
error("Illegal character escape at end of input"); error("Illegal character escape at end of input");
c = '\\'; str += '\\';
break; break;
default: default:
error("Illegal character escape %s", printChar(c)); error("Illegal character escape %s", printChar(c));
str += c;
shiftChar(); shiftChar();
break; break;
} }
@@ -1533,12 +1523,12 @@ static void appendCharInLiteral(std::string &str, int c) {
appendExpandedString(str, *interpolation); appendExpandedString(str, *interpolation);
} }
lexerState->disableMacroArgs = true; lexerState->disableMacroArgs = true;
return; // Do not copy an additional character break;
// Regular characters will just get copied default: // Regular characters will just get copied
str += c;
break;
} }
str += c; // Copy the character
} }
static void readString(std::string &str, bool rawString) { static void readString(std::string &str, bool rawString) {