VirtualBox

Changeset 6041 in vbox


Ignore:
Timestamp:
Dec 10, 2007 7:11:19 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
26676
Message:

Added RTUtf16CalcUtf8Len and RTUtf16CalcUtf8LenEx.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/string.h

    r5999 r6041  
    13111311RTDECL(int)  RTUtf16ToUtf8Ex(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch);
    13121312
     1313/**
     1314 * Calculates the length of the UTF-16 string in UTF-8 chars (bytes).
     1315 *
     1316 * This function will validate the string, and incorrectly encoded UTF-16
     1317 * strings will be rejected. The primary purpose of this function is to
     1318 * help allocate buffers for RTUtf16ToUtf8() of the correct size. For most
     1319 * other puroses RTUtf16ToUtf8Ex() should be used.
     1320 *
     1321 * @returns Number of char (bytes).
     1322 * @returns 0 if the string was incorrectly encoded.
     1323 * @param   pwsz        The UTF-16 string.
     1324 */
     1325RTDECL(size_t) RTUtf16CalcUtf8Len(PCRTUTF16 pwsz);
     1326
     1327/**
     1328 * Calculates the length of the UTF-16 string in UTF-8 chars (bytes).
     1329 *
     1330 * This function will validate the string, and incorrectly encoded UTF-16
     1331 * strings will be rejected.
     1332 *
     1333 * @returns iprt status code.
     1334 * @param   pwsz        The string.
     1335 * @param   cwc         The max string length. Use RTSTR_MAX to process the entire string.
     1336 * @param   pcch        Where to store the string length (in bytes). Optional.
     1337 *                      This is undefined on failure.
     1338 */
     1339RTDECL(int) RTUtf16CalcUtf8LenEx(PCRTUTF16 pwsz, size_t cwc, size_t *pcch);
    13131340
    13141341/**
  • trunk/src/VBox/Runtime/common/string/utf-16.cpp

    r5999 r6041  
    510510
    511511
     512RTDECL(size_t) RTUtf16CalcUtf8Len(PCRTUTF16 pwsz)
     513{
     514    size_t cch;
     515    int rc = rtUtf16CalcUtf8Length(pwsz, RTSTR_MAX, &cch);
     516    return RT_SUCCESS(rc) ? cch : 0;
     517}
     518
     519
     520RTDECL(int) RTUtf16CalcUtf8LenEx(PCRTUTF16 pwsz, size_t cwc, size_t *pcch)
     521{
     522    size_t cch;
     523    int rc = rtUtf16CalcUtf8Length(pwsz, cwc, &cch);
     524    if (pcch)
     525        *pcch = RT_SUCCESS(rc) ? cch : ~(size_t)0;
     526    return rc;
     527}
     528
     529
    512530RTDECL(RTUNICP) RTUtf16GetCpInternal(PCRTUTF16 pwsz)
    513531{
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette