Commits

eli.bendersky  committed 48e36ad

Fixed a bug in unified string handling (issue 7)

  • Participants
  • Parent commits 095457c

Comments (0)

Files changed (3)

 ------------------
 
 * bugfix: correct handling of do{} while statements in some cases
-
+* bugfix: Issue 6 (concatenation of string literals)
 
 Version Update
 --------------

File pycparser/c_parser.py

             p[0] = c_ast.Constant(
                 'string', p[1], self._coord(p.lineno(1)))
         else:
-            p[1].value = p[1].value.rstrip('"') + p[2].lstrip('"')
+            p[1].value = p[1].value[:-1] + p[2][1:]
             p[0] = p[1]
             
     def p_unified_wstring_literal(self, p):
             p[0] = c_ast.Constant(
                 'string', p[1], self._coord(p.lineno(1)))
         else:
-            p[1].value = p[1].value.rstrip('"') + p[2].lstrip('"')
+            p[1].value = p[1].value.rstrip[:-1] + p[2][1:]
             p[0] = p[1]
             
     def p_empty(self, p):

File tests/test_c_parser.py

         self.assertEqual(
             d3.ext[0].body.stmts[0].args.exprs[1].value,
             r'"Wrong Params?\nUsage:\n%s <binary_file_path>\n"')
+        
+        d4 = self.get_decl_init('char* s = "" "foobar";')
+        self.assertEqual(d4, ['Constant', 'string', '"foobar"'])
+        
+        d5 = self.get_decl_init(r'char* s = "foo\"" "bar";')
+        self.assertEqual(d5, ['Constant', 'string', r'"foo\"bar"'])
 
 
 class TestCParser_whole_code(unittest.TestCase):