Commits

Tommaso Urli committed 25c1ff6 Merge

Merged in t-ri/json-escape-strings/added-dubble-quote-escaping (pull request #4)

Added dubble quote escaping

Comments (0)

Files changed (2)

     #include "json.tab.hh"
 %}
 
+ESCAPED_THING                           \\["]
+CHAR                                    [^"\\]|{ESCAPED_THING}
+STRING_DUBBLE                           \"{CHAR}*\"
+
 %%
 
-\"[^\"]*\"                              { yylval.string_v = yytext; return DOUBLE_QUOTED_STRING; }
+{STRING_DUBBLE}                         { yylval.string_v = yytext; return DOUBLE_QUOTED_STRING; }
 \'[^\']*\'                              { yylval.string_v = yytext; return SINGLE_QUOTED_STRING; }
 "["                                     { return SQUARE_BRACKET_L; }
 "]"                                     { return SQUARE_BRACKET_R; }
         // Trim string
         std::string s($1);
         s = s.substr(1, s.length()-2);
+        while(true) {
+            auto n = s.find("\\\""); // searches \"
+            if (n == std::string::npos) break;
+            s.replace(n, 2, "\""); // replaces with "
+        }
         char* t = new char[s.length()+1];
         strcpy(t, s.c_str());
         $$ = t;