Changeset 329 for trunk/src/helpers/stringh.c
- Timestamp:
- Aug 31, 2006, 11:23:54 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/stringh.c
r263 r329 23 23 24 24 /* 25 * Copyright (C) 1997-200 2Ulrich 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. … … 1320 1320 *@@changed V0.9.3 (2000-05-19) [umoeller]: some speed optimizations 1321 1321 *@@changed V0.9.12 (2001-05-22) [umoeller]: fixed space bug, thanks Yuri Dario 1322 *@@changed WarpIN V1.0.11 (2006-08-29) [pr]: handle attrib names in quoted strings @@fixes 718 1322 1323 */ 1323 1324 1324 1325 PSZ strhFindAttribValue(const char *pszSearchIn, const char *pszAttrib) 1325 1326 { 1326 PSZ prc = 0; 1327 PSZ pszSearchIn2, p; 1328 ULONG cbAttrib = strlen(pszAttrib), 1329 ulLength = strlen(pszSearchIn); 1330 1331 // use alloca(), so memory is freed on function exit 1332 pszSearchIn2 = (PSZ)alloca(ulLength + 1); 1333 memcpy(pszSearchIn2, pszSearchIn, ulLength + 1); 1334 1335 // 1) find token, (space char, \n, \r, \t) 1336 p = strtok(pszSearchIn2, " \n\r\t"); 1337 while (p) 1338 { 1339 CHAR c2; 1340 PSZ pOrig; 1341 1342 // check tag name 1343 if (!strnicmp(p, pszAttrib, cbAttrib)) 1344 { 1345 // position in original string 1346 pOrig = (PSZ)pszSearchIn + (p - pszSearchIn2); 1347 1348 // yes: 1349 prc = pOrig + cbAttrib; 1350 c2 = *prc; 1351 while ( ( (c2 == ' ') 1352 || (c2 == '=') 1353 || (c2 == '\n') 1354 || (c2 == '\r') 1355 ) 1356 && (c2 != 0) 1357 ) 1358 c2 = *++prc; 1359 1360 break; 1361 } 1362 1363 p = strtok(NULL, " \n\r\t"); 1364 } 1365 1366 return prc; 1367 } 1368 1369 /* PSZ strhFindAttribValue(const char *pszSearchIn, const char *pszAttrib) 1370 { 1371 PSZ prc = 0; 1372 PSZ pszSearchIn2 = (PSZ)pszSearchIn, 1373 p, 1374 p2; 1375 ULONG cbAttrib = strlen(pszAttrib); 1376 1377 // 1) find space char 1378 while ((p = strchr(pszSearchIn2, ' '))) 1379 { 1380 CHAR c; 1381 p++; 1382 if (strlen(p) >= cbAttrib) // V0.9.9 (2001-03-27) [umoeller] 1383 { 1384 c = *(p+cbAttrib); // V0.9.3 (2000-05-19) [umoeller] 1385 // now check whether the p+strlen(pszAttrib) 1386 // is a valid end-of-tag character 1387 if ( (memicmp(p, (PVOID)pszAttrib, cbAttrib) == 0) 1388 && ( (c == ' ') 1389 || (c == '>') 1390 || (c == '=') 1391 || (c == '\r') 1392 || (c == '\n') 1393 || (c == 0) 1394 ) 1395 ) 1327 PSZ prc = 0; 1328 PSZ pszSearchIn2, p, pszStart, pszName, pszValue; 1329 ULONG cbAttrib = strlen(pszAttrib), 1330 ulLength = strlen(pszSearchIn); 1331 BOOL fInQuote = FALSE; 1332 1333 // use alloca(), so memory is freed on function exit 1334 pszSearchIn2 = (PSZ)alloca(ulLength + 1); 1335 memcpy(pszSearchIn2, pszSearchIn, ulLength + 1); 1336 1337 for (p = pszSearchIn2; *p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'; p++); 1338 for (pszStart = p; *p; p++) 1339 { 1340 if (fInQuote) 1341 { 1342 if (*p == '"') 1343 fInQuote = FALSE; 1344 } 1345 else 1346 { 1347 if (*p == '"') 1348 fInQuote = TRUE; 1349 else 1396 1350 { 1397 // yes: 1398 CHAR c2; 1399 p2 = p + cbAttrib; 1400 c2 = *p2; 1401 while ( ( (c2 == ' ') 1402 || (c2 == '=') 1403 || (c2 == '\n') 1404 || (c2 == '\r') 1405 ) 1406 && (c2 != 0) 1407 ) 1408 c2 = *++p2; 1409 1410 prc = p2; 1411 break; // first while 1351 if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') 1352 { 1353 *p = '\0'; 1354 pszName = strtok(pszStart, "=>"); 1355 pszStart = p + 1; 1356 if (pszName && !stricmp(pszName, pszAttrib)) 1357 { 1358 pszValue = strtok(NULL, ""); 1359 if (pszValue) 1360 prc = (PSZ)pszSearchIn + (pszValue - pszSearchIn2); 1361 else 1362 prc = (PSZ)pszSearchIn + (pszName - pszSearchIn2) + cbAttrib; 1363 1364 return(prc); 1365 } 1366 } 1412 1367 } 1413 1368 } 1414 else 1415 break; 1416 1417 pszSearchIn2++; 1418 } 1369 } 1370 1371 if (pszStart != p) 1372 { 1373 pszName = strtok(pszStart, "=>"); 1374 if (pszName && !stricmp(pszName, pszAttrib)) 1375 { 1376 pszValue = strtok(NULL, ""); 1377 if (pszValue) 1378 prc = (PSZ)pszSearchIn + (pszValue - pszSearchIn2); 1379 else 1380 prc = (PSZ)pszSearchIn + (pszName - pszSearchIn2) + cbAttrib; 1381 } 1382 } 1383 1419 1384 return prc; 1420 } */1385 } 1421 1386 1422 1387 /*
Note:
See TracChangeset
for help on using the changeset viewer.