Changeset 442
- Timestamp:
- Jan 17, 2019, 7:12:23 PM (7 years ago)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/branch-1-0/src/helpers/stringh.c
r427 r442 23 23 24 24 /* 25 * Copyright (C) 1997-20 16 Ulrich Mller.25 * Copyright (C) 1997-2006 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 12441325 1324 */ 1326 1325 … … 1332 1331 ulLength = strlen(pszSearchIn); 1333 1332 BOOL fInQuote = FALSE; 1334 CHAR cQuote = '\0', cPrev = '\0';1335 1333 1336 1334 // use alloca(), so memory is freed on function exit … … 1341 1339 for (p = pszSearchIn2; *p == '\'' || *p == '"' || *p == ' ' 1342 1340 || *p == '\n' || *p == '\r' || *p == '\t'; p++); 1343 for (pszStart = p; *p; cPrev = *(p++))1341 for (pszStart = p; *p; p++) 1344 1342 { 1345 1343 if (fInQuote) 1346 1344 { 1347 1345 // V1.0.12 (2006-09-07) [pr]: allow end of line to terminate a (broken) quote 1348 if ( (*p == cQuote && cPrev != '\\')|| *p == '\n' || *p == '\r')1346 if (*p == '"' || *p == '\n' || *p == '\r') 1349 1347 fInQuote = FALSE; 1350 1348 } 1351 1349 else 1352 1350 { 1353 if (*p == '"' || *p == '\'') 1354 { 1351 if (*p == '"') 1355 1352 fInQuote = TRUE; 1356 cQuote = *p;1357 }1358 1353 else 1359 1354 { … … 1453 1448 *@@added V0.9.0 [umoeller] 1454 1449 *@@changed V1.0.13 (2006-09-10) [pr]: improved parsing 1455 *@@changed WarpIN V1.0.23 (2016-09-23) [pr]: allow escaping @@fixes 12441456 1450 */ 1457 1451 … … 1469 1463 { 1470 1464 // determine end character to search for: a space 1471 CHAR cEnd = ' ' , cPrev = '\0';1465 CHAR cEnd = ' '; 1472 1466 // V1.0.3 (2004-11-10) [pr]: @@fixes 461 1473 1467 // V1.0.13 (2006-09-10) [pr]: optimized 1474 if ((*pParam == ' "') || (*pParam == '\''))1468 if ((*pParam == '\"') || (*pParam == '\'')) 1475 1469 { 1476 1470 // or, if the data is enclosed in quotes, a quote or single quote … … 1490 1484 if ( ( (cEnd == ' ') 1491 1485 && ((*pParam == ' ') || (*pParam == '\r') || (*pParam == '\n'))) 1492 || ( (*pParam == cEnd) && (cPrev != '\\'))1486 || (*pParam == cEnd) 1493 1487 ) 1494 1488 // end character found … … 1505 1499 break; 1506 1500 } 1507 1508 1501 ulCount++; 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'; 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; 1526 1511 } 1527 1512 } -
trunk/src/helpers/stringh.c
r426 r442 23 23 24 24 /* 25 * Copyright (C) 1997-20 16 Ulrich Mller.25 * Copyright (C) 1997-2006 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 12441325 1324 */ 1326 1325 … … 1332 1331 ulLength = strlen(pszSearchIn); 1333 1332 BOOL fInQuote = FALSE; 1334 CHAR cQuote = '\0', cPrev = '\0';1335 1333 1336 1334 // use alloca(), so memory is freed on function exit … … 1341 1339 for (p = pszSearchIn2; *p == '\'' || *p == '"' || *p == ' ' 1342 1340 || *p == '\n' || *p == '\r' || *p == '\t'; p++); 1343 for (pszStart = p; *p; cPrev = *(p++))1341 for (pszStart = p; *p; p++) 1344 1342 { 1345 1343 if (fInQuote) 1346 1344 { 1347 1345 // V1.0.12 (2006-09-07) [pr]: allow end of line to terminate a (broken) quote 1348 if ( (*p == cQuote && cPrev != '\\')|| *p == '\n' || *p == '\r')1346 if (*p == '"' || *p == '\n' || *p == '\r') 1349 1347 fInQuote = FALSE; 1350 1348 } 1351 1349 else 1352 1350 { 1353 if (*p == '"' || *p == '\'') 1354 { 1351 if (*p == '"') 1355 1352 fInQuote = TRUE; 1356 cQuote = *p;1357 }1358 1353 else 1359 1354 { … … 1453 1448 *@@added V0.9.0 [umoeller] 1454 1449 *@@changed V1.0.13 (2006-09-10) [pr]: improved parsing 1455 *@@changed WarpIN V1.0.23 (2016-09-23) [pr]: allow escaping @@fixes 12441456 1450 */ 1457 1451 … … 1469 1463 { 1470 1464 // determine end character to search for: a space 1471 CHAR cEnd = ' ' , cPrev = '\0';1465 CHAR cEnd = ' '; 1472 1466 // V1.0.3 (2004-11-10) [pr]: @@fixes 461 1473 1467 // V1.0.13 (2006-09-10) [pr]: optimized 1474 if ((*pParam == ' "') || (*pParam == '\''))1468 if ((*pParam == '\"') || (*pParam == '\'')) 1475 1469 { 1476 1470 // or, if the data is enclosed in quotes, a quote or single quote … … 1490 1484 if ( ( (cEnd == ' ') 1491 1485 && ((*pParam == ' ') || (*pParam == '\r') || (*pParam == '\n'))) 1492 || ( (*pParam == cEnd) && (cPrev != '\\'))1486 || (*pParam == cEnd) 1493 1487 ) 1494 1488 // end character found … … 1505 1499 break; 1506 1500 } 1507 1508 1501 ulCount++; 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'; 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; 1526 1511 } 1527 1512 }
Note:
See TracChangeset
for help on using the changeset viewer.