VirtualBox

Changeset 93103 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Dec 30, 2021 11:29:37 PM (3 years ago)
Author:
vboxsync
Message:

IPRT: Implemented RTUtf16NCmp and RTUtf16NCmpUtf8, adding RTUtf16GetCpNEx.

File:
1 edited

Legend:

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

    r83837 r93103  
    11701170
    11711171/**
     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 */
     1185RTDECL(int) RTUtf16GetCpNExInternal(PCRTUTF16 *ppwsz, size_t *pcwc, PRTUNICP pCp);
     1186
     1187/**
    11721188 * Get the unicode code point at the given string position, big endian.
    11731189 *
     
    12401256    }
    12411257    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 */
     1274DECLINLINE(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);
    12421290}
    12431291
Note: See TracChangeset for help on using the changeset viewer.

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