Changeset 426
- Timestamp:
- Sep 26, 2016, 1:45:54 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/stringh.c
r335 r426 23 23 24 24 /* 25 * Copyright (C) 1997-20 06 Ulrich Mller.25 * Copyright (C) 1997-2016 Ulrich Mller. 26 26 * Parts Copyright (C) 1991-1999 iMatix Corporation. 27 27 * This file is part of the "XWorkplace helpers" source package. … … 1322 1322 *@@changed WarpIN V1.0.11 (2006-08-29) [pr]: handle attrib names in quoted strings @@fixes 718 1323 1323 *@@changed WarpIN V1.0.12 (2006-09-07) [pr]: fix attrib handling again @@fixes 718 @@fixes 836 1324 *@@changed WarpIN V1.0.23 (2016-09-23) [pr]: fix single quote handling and allow escaping @@fixes 1244 1324 1325 */ 1325 1326 … … 1331 1332 ulLength = strlen(pszSearchIn); 1332 1333 BOOL fInQuote = FALSE; 1334 CHAR cQuote = '\0', cPrev = '\0'; 1333 1335 1334 1336 // use alloca(), so memory is freed on function exit … … 1339 1341 for (p = pszSearchIn2; *p == '\'' || *p == '"' || *p == ' ' 1340 1342 || *p == '\n' || *p == '\r' || *p == '\t'; p++); 1341 for (pszStart = p; *p; p++)1343 for (pszStart = p; *p; cPrev = *(p++)) 1342 1344 { 1343 1345 if (fInQuote) 1344 1346 { 1345 1347 // V1.0.12 (2006-09-07) [pr]: allow end of line to terminate a (broken) quote 1346 if ( *p == '"'|| *p == '\n' || *p == '\r')1348 if ((*p == cQuote && cPrev != '\\') || *p == '\n' || *p == '\r') 1347 1349 fInQuote = FALSE; 1348 1350 } 1349 1351 else 1350 1352 { 1351 if (*p == '"') 1353 if (*p == '"' || *p == '\'') 1354 { 1352 1355 fInQuote = TRUE; 1356 cQuote = *p; 1357 } 1353 1358 else 1354 1359 { … … 1448 1453 *@@added V0.9.0 [umoeller] 1449 1454 *@@changed V1.0.13 (2006-09-10) [pr]: improved parsing 1455 *@@changed WarpIN V1.0.23 (2016-09-23) [pr]: allow escaping @@fixes 1244 1450 1456 */ 1451 1457 … … 1463 1469 { 1464 1470 // determine end character to search for: a space 1465 CHAR cEnd = ' ' ;1471 CHAR cEnd = ' ', cPrev = '\0'; 1466 1472 // V1.0.3 (2004-11-10) [pr]: @@fixes 461 1467 1473 // V1.0.13 (2006-09-10) [pr]: optimized 1468 if ((*pParam == ' \"') || (*pParam == '\''))1474 if ((*pParam == '"') || (*pParam == '\'')) 1469 1475 { 1470 1476 // or, if the data is enclosed in quotes, a quote or single quote … … 1484 1490 if ( ( (cEnd == ' ') 1485 1491 && ((*pParam == ' ') || (*pParam == '\r') || (*pParam == '\n'))) 1486 || ( *pParam == cEnd)1492 || ((*pParam == cEnd) && (cPrev != '\\')) 1487 1493 ) 1488 1494 // end character found … … 1499 1505 break; 1500 1506 } 1507 1501 1508 ulCount++; 1502 pParam++; 1503 } 1504 1505 // copy attribute to new buffer 1506 if (ulCount) 1507 { 1508 prc = (PSZ)malloc(ulCount+1); 1509 memcpy(prc, pParam2, ulCount); 1510 *(prc+ulCount) = 0; 1509 cPrev = *(pParam++); 1510 } 1511 1512 // copy attribute to new buffer, de-escaping if necessary 1513 if (ulCount && (prc = (PSZ) malloc(ulCount+1))) 1514 { 1515 ULONG i = 0, j = 0; 1516 1517 for(cPrev = '\0'; i < ulCount; ++i, ++j) 1518 { 1519 if (cEnd != ' ' && pParam2[i] == cEnd && cPrev == '\\') 1520 --j; 1521 1522 cPrev = prc[j] = pParam2[i]; 1523 } 1524 1525 prc[j] = '\0'; 1511 1526 } 1512 1527 }
Note:
See TracChangeset
for help on using the changeset viewer.