# HG changeset patch # User Mike Pavone # Date 1376047777 25200 # Node ID d8f92ebf1ff63b6637a8517d882ec9d48ee8010e # Parent 7db37f040a6ff8d34db328da0db7746e11271820 Fix string literal escaping to allow more than one of each type of escaped character diff -r 7db37f040a6f -r d8f92ebf1ff6 cbackend.js --- a/cbackend.js Fri Aug 09 04:15:53 2013 -0700 +++ b/cbackend.js Fri Aug 09 04:29:37 2013 -0700 @@ -167,13 +167,13 @@ strlit.prototype.toC = function() { if (!(this.val in declaredStrings)) { //TODO: get the proper byte length - toplevelcode += 'string str_' + nextStringId + ' = {{&string_meta, NULL}, ' + this.val.length + ', ' + this.val.length + ', "' + this.val.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n').replace('\r', '\\r') + '"};\n'; + toplevelcode += 'string str_' + nextStringId + ' = {{&string_meta, NULL}, ' + this.val.length + ', ' + this.val.length + ', "' + this.val.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r') + '"};\n'; declaredStrings[this.val] = nextStringId++; } return '((object *)&str_' + declaredStrings[this.val] + ')'; }; strlit.prototype.toCLLExpr = function(vars) { - return '"' + this.val.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n').replace('\r', '\\r') + '"'; + return '"' + this.val.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r') + '"'; }; strlit.prototype.toCLines = function(vars, needsreturn) { return [ (needsreturn ? 'return (object *)' : '' ) + this.toCLLExpr(vars) +';' ];