Changeset 93103 in vbox
- Timestamp:
- Dec 30, 2021 11:29:37 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/utf16.h
r83837 r93103 1170 1170 1171 1171 /** 1172 * Get the unicode code point at the given string position with length 1173 * restriction. 1174 * 1175 * @returns iprt status code. 1176 * @param ppwsz Pointer to the string pointer. This will be updated to 1177 * point to the char following the current code point. 1178 * @param pcwc Pointer to the max string length. This will be 1179 * decremented corrsponding to the advancement of @a ppwsz. 1180 * @param pCp Where to store the code point. 1181 * RTUNICP_INVALID is stored here on failure. 1182 * 1183 * @remark This is an internal worker for RTUtf16GetCpNEx(). 1184 */ 1185 RTDECL(int) RTUtf16GetCpNExInternal(PCRTUTF16 *ppwsz, size_t *pcwc, PRTUNICP pCp); 1186 1187 /** 1172 1188 * Get the unicode code point at the given string position, big endian. 1173 1189 * … … 1240 1256 } 1241 1257 return RTUtf16GetCpExInternal(ppwsz, pCp); 1258 } 1259 1260 /** 1261 * Get the unicode code point at the given string position. 1262 * 1263 * @returns iprt status code. 1264 * @param ppwsz Pointer to the string pointer. This will be updated to 1265 * point to the char following the current code point. 1266 * @param pcwc Pointer to the max string length. This will be 1267 * decremented corrsponding to the advancement of @a ppwsz. 1268 * @param pCp Where to store the code point. RTUNICP_INVALID is stored 1269 * here on failure. 1270 * 1271 * @remark We optimize this operation by using an inline function for 1272 * everything which isn't a surrogate pair or and endian indicator. 1273 */ 1274 DECLINLINE(int) RTUtf16GetCpNEx(PCRTUTF16 *ppwsz, size_t *pcwc, PRTUNICP pCp) 1275 { 1276 const size_t cwc = *pcwc; 1277 if (cwc > 0) 1278 { 1279 const PCRTUTF16 pwsz = *ppwsz; 1280 const RTUTF16 wc = *pwsz; 1281 if (wc < 0xd800 || (wc > 0xdfff && wc < 0xfffe)) 1282 { 1283 *pCp = wc; 1284 *pcwc = cwc - 1; 1285 *ppwsz = pwsz + 1; 1286 return VINF_SUCCESS; 1287 } 1288 } 1289 return RTUtf16GetCpNExInternal(ppwsz, pcwc, pCp); 1242 1290 } 1243 1291 -
trunk/src/VBox/Runtime/Makefile.kmk
r93081 r93103 617 617 common/string/RTUtf16ICmpAscii.cpp \ 618 618 common/string/RTUtf16End.cpp \ 619 common/string/RTUtf16NCmp.cpp \ 619 620 common/string/RTUtf16NCmpAscii.cpp \ 621 common/string/RTUtf16NCmpUtf8.cpp \ 620 622 common/string/RTUtf16NICmpAscii.cpp \ 621 623 common/string/RTUtf16NLen.cpp \ -
trunk/src/VBox/Runtime/common/string/utf-16.cpp
r90794 r93103 1187 1187 1188 1188 1189 RTDECL(int) RTUtf16GetCpNExInternal(PCRTUTF16 *ppwsz, size_t *pcwc, PRTUNICP pCp) 1190 { 1191 int rc; 1192 const size_t cwc = *pcwc; 1193 if (cwc > 0) 1194 { 1195 PCRTUTF16 pwsz = *ppwsz; 1196 const RTUTF16 wc = **ppwsz; 1197 1198 /* simple */ 1199 if (wc < 0xd800 || (wc > 0xdfff && wc < 0xfffe)) 1200 { 1201 *pCp = wc; 1202 *pcwc = cwc - 1; 1203 *ppwsz = pwsz + 1; 1204 return VINF_SUCCESS; 1205 } 1206 1207 if (wc < 0xfffe) 1208 { 1209 /* surrogate pair */ 1210 if (wc < 0xdc00) 1211 { 1212 if (cwc >= 2) 1213 { 1214 const RTUTF16 wc2 = pwsz[1]; 1215 if (wc2 >= 0xdc00 && wc2 <= 0xdfff) 1216 { 1217 *pCp = 0x10000 + (((wc & 0x3ff) << 10) | (wc2 & 0x3ff)); 1218 *pcwc = cwc - 2; 1219 *ppwsz = pwsz + 2; 1220 return VINF_SUCCESS; 1221 } 1222 1223 RTStrAssertMsgFailed(("wc=%#08x wc2=%#08x - invalid 2nd char in surrogate pair\n", wc, wc2)); 1224 } 1225 else 1226 RTStrAssertMsgFailed(("wc=%#08x - incomplete surrogate pair\n", wc)); 1227 } 1228 else 1229 RTStrAssertMsgFailed(("wc=%#08x - invalid surrogate pair order\n", wc)); 1230 rc = VERR_INVALID_UTF16_ENCODING; 1231 } 1232 else 1233 { 1234 RTStrAssertMsgFailed(("wc=%#08x - endian indicator\n", wc)); 1235 rc = VERR_CODE_POINT_ENDIAN_INDICATOR; 1236 } 1237 *pcwc = cwc - 1; 1238 *ppwsz = pwsz + 1; 1239 } 1240 else 1241 rc = VERR_END_OF_STRING; 1242 *pCp = RTUNICP_INVALID; 1243 return rc; 1244 } 1245 RT_EXPORT_SYMBOL(RTUtf16GetCpNExInternal); 1246 1247 1189 1248 RTDECL(int) RTUtf16BigGetCpExInternal(PCRTUTF16 *ppwsz, PRTUNICP pCp) 1190 1249 {
Note:
See TracChangeset
for help on using the changeset viewer.