VirtualBox

Changeset 66361 in vbox


Ignore:
Timestamp:
Mar 30, 2017 1:44:39 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114302
Message:

IPRT: Adding RTStrICmpAscii (mirrors RTUtf16ICmpAscii).

Location:
trunk
Files:
3 edited
1 copied

Legend:

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

    r65579 r66361  
    18381838# define RTStrHash1N                                    RT_MANGLER(RTStrHash1N)
    18391839# define RTStrICmp                                      RT_MANGLER(RTStrICmp)
     1840# define RTStrICmpAscii                                 RT_MANGLER(RTStrICmpAscii)
    18401841# define RTStrIStartsWith                               RT_MANGLER(RTStrIStartsWith)
    18411842# define RTStrIStr                                      RT_MANGLER(RTStrIStr)
  • trunk/include/iprt/string.h

    r66284 r66361  
    22122212
    22132213/**
     2214 * Performs a case insensitive string compare between a UTF-8 string and a 7-bit
     2215 * ASCII string.
     2216 *
     2217 * This is potentially faster than RTStrICmp and drags in less dependencies.  It
     2218 * is really handy for hardcoded inputs.
     2219 *
     2220 * If the string encoding is invalid the function will assert (strict builds)
     2221 * and use RTStrCmp for the remainder of the string.
     2222 *
     2223 * @returns < 0 if the first string less than the second string.
     2224 * @returns 0 if the first string identical to the second string.
     2225 * @returns > 0 if the first string greater than the second string.
     2226 * @param   psz1        First UTF-8 string. Null is allowed.
     2227 * @param   psz2        Second string, 7-bit ASCII. Null is allowed.
     2228 * @sa      RTUtf16ICmpAscii
     2229 */
     2230RTDECL(int) RTStrICmpAscii(const char *psz1, const char *psz2);
     2231
     2232/**
    22142233 * Checks whether @a pszString starts with @a pszStart.
    22152234 *
  • trunk/src/VBox/Runtime/Makefile.kmk

    r66072 r66361  
    538538        common/string/RTStrStartsWith.cpp \
    539539        common/string/RTStrIStartsWith.cpp \
     540        common/string/RTStrICmpAscii.cpp \
    540541        common/string/RTStrStr.cpp \
    541542        common/string/RTUtf16Copy.cpp \
     
    18831884        common/string/RTStrCopyP.cpp \
    18841885        common/string/RTStrCopyPEx.cpp \
     1886        common/string/RTStrCmp.cpp \
     1887        common/string/RTStrICmpAscii.cpp \
    18851888        common/string/RTStrNLen.cpp \
    18861889        common/string/RTStrNLenEx.cpp \
     
    20632066        common/string/RTStrCopyP.cpp \
    20642067        common/string/RTStrCopyPEx.cpp \
     2068        common/string/RTStrICmpAscii.cpp \
    20652069        common/string/RTStrNCmp.cpp \
    20662070        common/string/RTStrNLen.cpp \
     
    25942598        common/string/strprintf.cpp \
    25952599        common/string/strprintf2.cpp \
     2600        common/string/RTStrCmp.cpp \
    25962601        common/string/RTStrCopy.cpp \
    25972602        common/string/RTStrCopyEx.cpp \
     2603        common/string/RTStrICmpAscii.cpp \
    25982604        common/table/avllu32.cpp \
    25992605        common/table/avlou32.cpp \
  • trunk/src/VBox/Runtime/common/string/RTStrICmpAscii.cpp

    r66348 r66361  
    3636
    3737
    38 RTDECL(int) RTUtf16ICmpAscii(PCRTUTF16 pwsz1, const char *psz2)
     38RTDECL(int) RTStrICmpAscii(const char *psz1, const char *psz2)
    3939{
     40    if (psz1 == psz2)
     41        return 0;
     42    if (!psz1)
     43        return -1;
     44    if (!psz2)
     45        return 1;
     46
    4047    for (;;)
    4148    {
    42         RTUTF16         wc1  = *pwsz1++;
    43         unsigned char   uch2 = *psz2++; Assert(uch2 < 0x80);
    44         if (wc1 != uch2)
     49        RTUNICP uc1;
     50        int rc = RTStrGetCpEx(&psz1, &uc1);
     51        if (RT_SUCCESS(rc))
    4552        {
    46             if (wc1 >= 0x80)
    47                 return 1;
    48             if (RT_C_TO_LOWER(wc1) != RT_C_TO_LOWER(uch2))
    49                 return wc1 < uch2 ? -1 : 1;
     53            unsigned char uch2 = *psz2++; Assert(uch2 < 0x80);
     54
     55            /* compare */
     56            int iDiff = uc1 - uch2;
     57            if (iDiff)
     58            {
     59                if (uc1 >= 0x80)
     60                    return 1;
     61
     62                iDiff = RT_C_TO_LOWER(uc1) - RT_C_TO_LOWER(uch2); /* Return lower cased diff! */
     63                if (iDiff)
     64                    return iDiff;
     65            }
     66
     67            if (uch2)
     68            { /* likely */ }
     69            else
     70                return 0;
    5071        }
    51         if (!uch2)
    52             return 0;
     72        /* Hit some bad encoding, continue in case sensitive mode. */
     73        else
     74            return RTStrCmp(psz1 - 1, psz2);
    5375    }
    5476}
    55 RT_EXPORT_SYMBOL(RTUtf16ICmpAscii);
     77RT_EXPORT_SYMBOL(RTStrICmpAscii);
    5678
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