Changeset 60481 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Apr 13, 2016 8:14:41 PM (9 years ago)
- Location:
- trunk/src/VBox/Runtime/common/string
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/utf-16-case.cpp
r57358 r60481 106 106 107 107 108 RTDECL(int) RTUtf16ICmpUtf8(PCRTUTF16 pwsz1, const char *psz2) 109 { 110 /* 111 * NULL and empty strings are all the same. 112 */ 113 if (!pwsz1) 114 return !psz2 || !*psz2 ? 0 : -1; 115 if (!psz2) 116 return !*pwsz1 ? 0 : 1; 117 118 /* 119 * Compare with a UTF-8 string by enumerating them char by char. 120 */ 121 for (;;) 122 { 123 RTUNICP uc1; 124 int rc = RTUtf16GetCpEx(&pwsz1, &uc1); 125 AssertRCReturn(rc, 1); 126 127 RTUNICP uc2; 128 rc = RTStrGetCpEx(&psz2, &uc2); 129 AssertRCReturn(rc, -1); 130 if (uc1 == uc2) 131 { 132 if (uc1) 133 continue; 134 return 0; 135 } 136 137 if (RTUniCpToUpper(uc1) == RTUniCpToUpper(uc2)) 138 continue; 139 if (RTUniCpToLower(uc1) == RTUniCpToLower(uc2)) 140 continue; 141 return uc1 < uc2 ? -1 : 1; 142 } 143 } 144 RT_EXPORT_SYMBOL(RTUtf16CmpIUtf8); 145 146 108 147 RTDECL(PRTUTF16) RTUtf16ToLower(PRTUTF16 pwsz) 109 148 { -
trunk/src/VBox/Runtime/common/string/utf-16.cpp
r57358 r60481 114 114 115 115 116 RTDECL(int) RTUtf16ReallocTag(PRTUTF16 *ppwsz, size_t cbNew, const char *pszTag) 117 { 118 PRTUTF16 pwszOld = *ppwsz; 119 cbNew = RT_ALIGN_Z(cbNew, sizeof(RTUTF16)); 120 if (!cbNew) 121 { 122 RTMemFree(pwszOld); 123 *ppwsz = NULL; 124 } 125 else if (pwszOld) 126 { 127 PRTUTF16 pwszNew = (PRTUTF16)RTMemReallocTag(pwszOld, cbNew, pszTag); 128 if (!pwszNew) 129 return VERR_NO_STR_MEMORY; 130 pwszNew[cbNew / sizeof(RTUTF16) - 1] = '\0'; 131 *ppwsz = pwszNew; 132 } 133 else 134 { 135 PRTUTF16 pwszNew = (PRTUTF16)RTMemAllocTag(cbNew, pszTag); 136 if (!pwszNew) 137 return VERR_NO_UTF16_MEMORY; 138 pwszNew[0] = '\0'; 139 pwszNew[cbNew / sizeof(RTUTF16) - 1] = '\0'; 140 *ppwsz = pwszNew; 141 } 142 return VINF_SUCCESS; 143 } 144 RT_EXPORT_SYMBOL(RTUtf16ReallocTag); 145 146 116 147 RTDECL(void) RTUtf16Free(PRTUTF16 pwszString) 117 148 { … … 183 214 } 184 215 RT_EXPORT_SYMBOL(RTUtf16Cmp); 216 217 218 RTDECL(int) RTUtf16CmpUtf8(PCRTUTF16 pwsz1, const char *psz2) 219 { 220 /* 221 * NULL and empty strings are all the same. 222 */ 223 if (!pwsz1) 224 return !psz2 || !*psz2 ? 0 : -1; 225 if (!psz2) 226 return !*pwsz1 ? 0 : 1; 227 228 /* 229 * Compare with a UTF-8 string by enumerating them char by char. 230 */ 231 for (;;) 232 { 233 RTUNICP uc1; 234 int rc = RTUtf16GetCpEx(&pwsz1, &uc1); 235 AssertRCReturn(rc, 1); 236 237 RTUNICP uc2; 238 rc = RTStrGetCpEx(&psz2, &uc2); 239 AssertRCReturn(rc, -1); 240 if (uc1 == uc2) 241 { 242 if (uc1) 243 continue; 244 return 0; 245 } 246 return uc1 < uc2 ? -1 : 1; 247 } 248 } 249 RT_EXPORT_SYMBOL(RTUtf16CmpUtf8); 185 250 186 251
Note:
See TracChangeset
for help on using the changeset viewer.