Przeglądaj źródła

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

master
kevin 11 lat temu
rodzic
commit
a8c3a33591
1 zmienionych plików z 20 dodań i 9 usunięć
  1. 20
    9
      cmLex.c

+ 20
- 9
cmLex.c Wyświetl plik

@@ -323,19 +323,30 @@ unsigned _cmLexIdentMatcher( cmLex* p, const cmChar_t* cp, unsigned cn, const cm
323 323
 
324 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 352
 unsigned _cmLexQCharMatcher( cmLex* p, const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )

Ładowanie…
Anuluj
Zapisz