Ned Batchelder committed 2adfe36

C can't do single-quoted strings, so we have to convert them to double-quoted.

Comments (0)

Files changed (2)

+    def escape_quotes(m):
+        """Used in a regex to properly escape double quotes."""
+        s =
+        if s == '"':
+            return r'\"'
+        else:
+            return s
     lexer = JsLexer()
     c = []
     for name, tok in lexer.lex(js):
             # C doesn't grok regexes, and they aren't needed for gettext,
             # so just output a string instead.
             tok = '"REGEX"';
+        elif name == 'string':
+            # C doesn't have single-quoted strings, so make all strings
+            # double-quoted.
+            if tok.startswith("'"):
+                guts = re.sub(r"\\.|.", escape_quotes, tok[1:-1])
+                tok = '"' + guts + '"'
     return ''.join(c)
 s = "Hello \"th/foo/ere\"";
 s = 'He\x23llo \'th/foo/ere\'';
+s = 'slash quote \", just quote "';
 s = "Hello \"th/foo/ere\"";
-s = 'He\x23llo \'th/foo/ere\'';
+s = "He\x23llo \'th/foo/ere\'";
+s = "slash quote \", just quote \"";
 s = "Line continuation\
 continued /hello/ still the string";/hello/;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.