Fix multiline strings with single quotes in Cephelapod and implement both types in Kalypso, one new test should pass for both

This commit is contained in:
Nathan Braswell
2016-02-15 23:12:56 -05:00
parent 815c213270
commit a898104f8a
3 changed files with 28 additions and 4 deletions

View File

@@ -1066,13 +1066,16 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
case value:
{
// ok, we now check for it being a multiline string and escape all returns if it is (so that multiline strings work)
if (data.symbol.getName()[0] == '"' && strSlice(data.symbol.getName(), 0, 3) == "\"\"\"") {
std::string innerString = strSlice(data.symbol.getName(), 3, -4);
if (data.symbol.getName()[0] == '"') {
std::string innerString = strSlice(data.symbol.getName(), 1, -2);
bool triple = strSlice(data.symbol.getName(), 0, 3) == "\"\"\"";
if (triple)
innerString = strSlice(data.symbol.getName(), 3, -4);
std::string newStr;
for (auto character: innerString)
if (character == '\n')
newStr += "\\n";
else if (character == '"')
else if (triple && character == '"')
newStr += "\\\"";
else
newStr += character;