儲存庫 vbox 的更動 18552
圖例:
- 未更動
- 新增
- 刪除
-
trunk/include/iprt/string.h
r18544 r18552 884 884 885 885 /** 886 * Locates a case insensitive substring. 887 * 888 * If any of the two strings are NULL, then NULL is returned. If the needle is 889 * an empty string, then the haystack is returned (i.e. matches anything). 890 * 891 * @returns Pointer to the first occurance of the substring if found, NULL if 892 * not. 893 * 894 * @param pszHaystack The string to search. 895 * @param pszNeedle The substring to search for. 896 * 897 * @remarks The difference between this and strstr is the handling of NULL 898 * pointers.s 899 */ 900 RTDECL(char *) RTStrStr(const char *pszHaystack, const char *pszNeedle); 901 902 /** 903 * Locates a case insensitive substring. 904 * 905 * If any of the two strings are NULL, then NULL is returned. If the needle is 906 * an empty string, then the haystack is returned (i.e. matches anything). 907 * 908 * @returns Pointer to the first occurance of the substring if found, NULL if 909 * not. 910 * 911 * @param pszHaystack The string to search. 912 * @param pszNeedle The substring to search for. 913 * 914 */ 915 RTDECL(char *) RTStrIStr(const char *pszHaystack, const char *pszNeedle); 916 917 /** 918 * Converts the string to lower case. 919 * 920 * @returns Pointer to the converted string. 921 * @param psz The string to convert. 922 */ 923 RTDECL(char *) RTStrToLower(char *psz); 924 925 /** 926 * Converts the string to upper case. 927 * 928 * @returns Pointer to the converted string. 929 * @param psz The string to convert. 930 */ 931 RTDECL(char *) RTStrToUpper(char *psz); 932 933 /** 886 934 * Find the length of a zero-terminated byte string, given 887 935 * a max string length. … … 969 1017 const char *pszString, size_t cchString, 970 1018 size_t *poffPattern); 971 972 /**973 * Converts the string to lower case.974 *975 * @returns Pointer to the converted string.976 * @param psz The string to convert.977 */978 RTDECL(char *) RTStrToLower(char *psz);979 980 /**981 * Converts the string to upper case.982 *983 * @returns Pointer to the converted string.984 * @param psz The string to convert.985 */986 RTDECL(char *) RTStrToUpper(char *psz);987 1019 988 1020 -
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 {
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器