Browse Source

cmLex.c : The quoted string matcher now correctly handles escaped double quotes.

master
kevin 11 years ago
parent
commit
a8c3a33591
1 changed files with 20 additions and 9 deletions
  1. 20
    9
      cmLex.c

+ 20
- 9
cmLex.c View File

323
 
323
 
324
 unsigned _cmLexQStrMatcher( cmLex* p, const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )
324
 unsigned _cmLexQStrMatcher( cmLex* p, const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )
325
 {
325
 {
326
-  cmChar_t qStr[]="\"";
327
-  unsigned n = strlen(qStr);
328
-  if( strncmp(qStr,cp,n) == 0 )
326
+  bool escFl = false;
327
+  unsigned i = 0;
328
+  if( cp[i] != '"' )
329
+    return 0;
330
+
331
+  for(i=1; i<cn; ++i)
329
   {
332
   {
330
-    unsigned i;
331
-    if((i = _cmLexScanTo(cp+n, cn-n, qStr)) == cmInvalidIdx )
333
+    if( escFl )
332
     {
334
     {
333
-      _cmLexError( p, kMissingEndQuoteLexRC, "Missing string end quote.");
334
-      return 0;
335
+      escFl = false;
336
+      continue;
335
     }
337
     }
336
-    return n+i;
338
+
339
+    if( cp[i] == '\\' )
340
+    {
341
+      escFl = true;
342
+      continue;
343
+    }
344
+
345
+    if( cp[i] == '"' )
346
+      return i+1;    
337
   }
347
   }
338
-  return 0;
348
+
349
+  return _cmLexError(p, kMissingEndQuoteLexRC, "Missing string literal end quote.");
339
 }
350
 }
340
 
351
 
341
 unsigned _cmLexQCharMatcher( cmLex* p, const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )
352
 unsigned _cmLexQCharMatcher( cmLex* p, const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )

Loading…
Cancel
Save