- Timestamp:
- Mar 10, 2008 4:58:12 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 28856
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/string.h
r7420 r7421 1104 1104 * as they are used in some languages, just simple upper & lower case compares. 1105 1105 * 1106 * The result is the difference between the mismatching codepoints after they 1107 * both have been lower cased. 1108 * 1109 * If the string encoding is invalid the function will assert (strict builds) 1110 * and use RTStrCmp for the remainder of the string. 1111 * 1106 1112 * @returns < 0 if the first string less than the second string. 1107 1113 * @returns 0 if the first string identical to the second string. -
trunk/src/VBox/Runtime/common/string/utf-8.cpp
r7420 r7421 996 996 * as they are used in some languages, just simple upper & lower case compares. 997 997 * 998 * The result is the difference between the mismatching codepoints after they 999 * both have been lower cased. 1000 * 1001 * If the string encoding is invalid the function will assert (strict builds) 1002 * and use RTStrCmp for the remainder of the string. 1003 * 998 1004 * @returns < 0 if the first string less than the second string. 999 1005 * @returns 0 if the first string identical to the second string. … … 1011 1017 return 1; 1012 1018 1013 /** @todo implement proper UTF-8 case-insensitive string comparison. */ 1019 #if 1 /* new */ 1020 const char *pszStart1 = psz1; 1021 for (;;) 1022 { 1023 /* Get the codepoints */ 1024 RTUNICP cp1; 1025 int rc = RTStrGetCpEx(&psz1, &cp1); 1026 if (RT_FAILURE(rc)) 1027 { 1028 AssertRC(rc); 1029 psz1--; 1030 break; 1031 } 1032 1033 RTUNICP cp2; 1034 rc = RTStrGetCpEx(&psz2, &cp2); 1035 if (RT_FAILURE(rc)) 1036 { 1037 AssertRC(rc); 1038 psz2--; 1039 psz1 = RTStrPrevCp(pszStart1, psz1); 1040 break; 1041 } 1042 1043 /* compare */ 1044 int iDiff = cp1 - cp2; 1045 if (iDiff) 1046 { 1047 iDiff = RTUniCpToUpper(cp1) != RTUniCpToUpper(cp2); 1048 if (iDiff) 1049 { 1050 iDiff = RTUniCpToLower(cp1) - RTUniCpToLower(cp2); /* lower case diff last! */ 1051 if (iDiff) 1052 return iDiff; 1053 } 1054 } 1055 1056 /* hit the terminator? */ 1057 if (!cp1) 1058 return 0; 1059 } 1060 1061 /* Hit some bad encoding, continue in case insensitive mode. */ 1062 return RTStrCmp(psz1, psz2); 1063 #else /* old */ 1014 1064 #ifdef RT_OS_WINDOWS 1015 1065 return stricmp(psz1, psz2); … … 1017 1067 return strcasecmp(psz1, psz2); 1018 1068 #endif /* !RT_OS_WINDOWS */ 1019 } 1069 #endif 1070 } -
trunk/src/VBox/Runtime/testcase/tstUtf8.cpp
r7418 r7421 795 795 796 796 /** 797 * Test the RTStr*Cmp functions. 798 */ 799 void TstRTStrXCmp(void) 800 { 801 RTPrintf("tstUtf8: TESTING RTStr*Cmp\n"); 802 #define CHECK_DIFF(expr, op) \ 803 do \ 804 { \ 805 int iDiff = expr; \ 806 if (!(iDiff op 0)) \ 807 { \ 808 RTPrintf("tstUtf8(%d): failure - %d " #op " 0: %s\n", __LINE__, iDiff, #expr); \ 809 g_cErrors++; \ 810 } \ 811 } while (0) 812 813 /** @todo test the non-ascii bits. */ 814 815 CHECK_DIFF(RTStrCmp(NULL, NULL), == ); 816 CHECK_DIFF(RTStrCmp(NULL, ""), < ); 817 CHECK_DIFF(RTStrCmp("", NULL), > ); 818 CHECK_DIFF(RTStrCmp("", ""), == ); 819 CHECK_DIFF(RTStrCmp("abcdef", "abcdef"), == ); 820 CHECK_DIFF(RTStrCmp("abcdef", "abcde"), > ); 821 CHECK_DIFF(RTStrCmp("abcde", "abcdef"), < ); 822 CHECK_DIFF(RTStrCmp("abcdeg", "abcdef"), > ); 823 CHECK_DIFF(RTStrCmp("abcdef", "abcdeg"), < ); 824 CHECK_DIFF(RTStrCmp("abcdeF", "abcdef"), < ); 825 CHECK_DIFF(RTStrCmp("abcdef", "abcdeF"), > ); 826 827 828 CHECK_DIFF(RTStrICmp(NULL, NULL), == ); 829 CHECK_DIFF(RTStrICmp(NULL, ""), < ); 830 CHECK_DIFF(RTStrICmp("", NULL), > ); 831 CHECK_DIFF(RTStrICmp("", ""), == ); 832 CHECK_DIFF(RTStrICmp("abcdef", "abcdef"), == ); 833 CHECK_DIFF(RTStrICmp("abcdef", "abcde"), > ); 834 CHECK_DIFF(RTStrICmp("abcde", "abcdef"), < ); 835 CHECK_DIFF(RTStrICmp("abcdeg", "abcdef"), > ); 836 CHECK_DIFF(RTStrICmp("abcdef", "abcdeg"), < ); 837 838 CHECK_DIFF(RTStrICmp("abcdeF", "abcdef"), == ); 839 CHECK_DIFF(RTStrICmp("abcdef", "abcdeF"), ==); 840 CHECK_DIFF(RTStrICmp("ABCDEF", "abcdef"), ==); 841 CHECK_DIFF(RTStrICmp("abcdef", "ABCDEF"), ==); 842 CHECK_DIFF(RTStrICmp("AbCdEf", "aBcDeF"), ==); 843 CHECK_DIFF(RTStrICmp("AbCdEg", "aBcDeF"), > ); 844 CHECK_DIFF(RTStrICmp("AbCdEG", "aBcDef"), > ); /* diff performed on the lower case cp. */ 845 } 846 847 848 849 /** 797 850 * Benchmark stuff. 798 851 */ … … 855 908 test2(); 856 909 test3(); 910 TstRTStrXCmp(); 857 911 Benchmarks(); 858 912
Note:
See TracChangeset
for help on using the changeset viewer.