Changeset 18552 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Mar 30, 2009 2:46:47 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/utf-8.cpp
r18544 r18552 1371 1371 1372 1372 1373 RTDECL(char *) RTStrStr(const char *pszHaystack, const char *pszNeedle) 1374 { 1375 /* Any NULL strings means NULL return. (In the RTStrCmp tradition.) */ 1376 if (!pszHaystack) 1377 return NULL; 1378 if (!pszNeedle) 1379 return NULL; 1380 1381 /* The rest is CRT. */ 1382 return strstr(pszHaystack, pszNeedle); 1383 } 1384 1385 1386 RTDECL(char *) RTStrIStr(const char *pszHaystack, const char *pszNeedle) 1387 { 1388 /* Any NULL strings means NULL return. (In the RTStrCmp tradition.) */ 1389 if (!pszHaystack) 1390 return NULL; 1391 if (!pszNeedle) 1392 return NULL; 1393 1394 /* The empty string matches everything. */ 1395 if (*pszNeedle) 1396 return (char *)pszHaystack; 1397 1398 /* 1399 * The search strategy is to pick out the first char of the needle, fold it, 1400 * and match it against the haystack code point by code point. When encountering 1401 * a matching code point we use RTStrNICmp for the remainder (if any) of the needle. 1402 */ 1403 const char * const pszNeedleStart = pszNeedle; 1404 RTUNICP Cp0; 1405 RTStrGetCpEx(&pszNeedle, &Cp0); /* pszNeedle is advanced one code point. */ 1406 size_t const cchNeedle = strlen(pszNeedle); 1407 size_t const cchNeedleCp0= pszNeedle - pszNeedleStart; 1408 RTUNICP const Cp0Lower = RTUniCpToLower(Cp0); 1409 RTUNICP const Cp0Upper = RTUniCpToUpper(Cp0); 1410 if ( Cp0Lower == Cp0Upper 1411 && Cp0Lower == Cp0) 1412 { 1413 /* Cp0 is not a case sensitive char. */ 1414 for (;;) 1415 { 1416 RTUNICP Cp; 1417 RTStrGetCpEx(&pszHaystack, &Cp); 1418 if (!Cp) 1419 break; 1420 if ( Cp == Cp0 1421 && !RTStrNICmp(pszHaystack, pszNeedle, cchNeedle)) 1422 return (char *)pszHaystack - cchNeedleCp0; 1423 } 1424 } 1425 else if ( Cp0Lower == Cp0 1426 || Cp0Upper != Cp0) 1427 { 1428 /* Cp0 is case sensitive */ 1429 for (;;) 1430 { 1431 RTUNICP Cp; 1432 RTStrGetCpEx(&pszHaystack, &Cp); 1433 if (!Cp) 1434 break; 1435 if ( ( Cp == Cp0Upper 1436 || Cp == Cp0Lower) 1437 && !RTStrNICmp(pszHaystack, pszNeedle, cchNeedle)) 1438 return (char *)pszHaystack - cchNeedleCp0; 1439 } 1440 } 1441 else 1442 { 1443 /* Cp0 is case sensitive and folds to two difference chars. (paranoia) */ 1444 for (;;) 1445 { 1446 RTUNICP Cp; 1447 RTStrGetCpEx(&pszHaystack, &Cp); 1448 if (!Cp) 1449 break; 1450 if ( ( Cp == Cp0 1451 || Cp == Cp0Upper 1452 || Cp == Cp0Lower) 1453 && !RTStrNICmp(pszHaystack, pszNeedle, cchNeedle)) 1454 return (char *)pszHaystack - cchNeedleCp0; 1455 } 1456 } 1457 1458 1459 return NULL; 1460 } 1461 1462 1373 1463 RTDECL(char *) RTStrToLower(char *psz) 1374 1464 {
Note:
See TracChangeset
for help on using the changeset viewer.