VirtualBox

Ignore:
Timestamp:
Jan 6, 2019 7:11:08 PM (6 years ago)
Author:
vboxsync
Message:

RTPathCalcRelative: Extended case-insensitivity from 7-bit ascii to full unicode.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/path/RTPathCalcRelative.cpp

    r76595 r76660  
    3333
    3434#include <iprt/assert.h>
    35 #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
    36 # include <iprt/ctype.h>
    37 #endif
    3835#include <iprt/errcore.h>
    3936#include <iprt/string.h>
     37#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
     38# include <iprt/uni.h>
     39#endif
    4040#include "internal/path.h"
    4141
     42
     43#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
     44/** Helper for doing case insensitive comparison of a mismatching codepoint. */
     45DECLINLINE(bool) rtPathCalcRelativeEqualICaseCodepoint(const char *pszPathFromStart, const char *pszPathFrom,
     46                                                       const char *pszPathToStart,   const char *pszPathTo)
     47{
     48    RTUNICP ucFrom = RTStrGetCp(RTStrPrevCp(pszPathFromStart, pszPathFrom));
     49    RTUNICP ucTo   = RTStrGetCp(RTStrPrevCp(pszPathToStart,   pszPathTo));
     50    return ucFrom == ucTo
     51        || RTUniCpToLower(ucFrom) == RTUniCpToLower(ucTo)
     52        || RTUniCpToUpper(ucFrom) == RTUniCpToUpper(ucTo);
     53}
     54#endif
    4255
    4356
     
    5063    AssertPtrReturn(pszPathFrom, VERR_INVALID_POINTER);
    5164    AssertPtrReturn(pszPathTo, VERR_INVALID_POINTER);
     65#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
     66    const char * const pszPathFromStart = pszPathFrom;
     67    const char * const pszPathToStart   = pszPathTo;
     68#endif
    5269
    5370    /*
     
    7087#else
    7188    if (RTStrNICmp(pszPathFrom, pszPathTo, offRootFrom))
    72         for (size_t off = 0; off < offRootFrom; off++)
    73         {
    74             char const chFrom = pszPathFrom[off];
    75             char const chTo   = pszPathTo[off];
    76             if (   chFrom != chTo
    77                 && RT_C_TO_LOWER(chFrom) != RT_C_TO_LOWER(chTo) /** @todo proper case insensitivity! */
    78                 && (!RTPATH_IS_SLASH(chFrom) || !RTPATH_IS_SLASH(chTo)) )
     89    {
     90        const char *pszFromCursor = pszPathFrom;
     91        const char *pszToCursor   = pszPathTo;
     92        while ((size_t)(pszFromCursor - pszPathFrom) < offRootFrom)
     93        {
     94            RTUNICP ucFrom;
     95            int rc = RTStrGetCpEx(&pszFromCursor, &ucFrom);
     96            AssertRCReturn(rc, rc);
     97
     98            RTUNICP ucTo;
     99            rc = RTStrGetCpEx(&pszToCursor, &ucTo);
     100            AssertRCReturn(rc, rc);
     101            if (   ucFrom != ucTo
     102                && RTUniCpToLower(ucFrom) != RTUniCpToLower(ucTo)
     103                && RTUniCpToUpper(ucFrom) != RTUniCpToUpper(ucTo)
     104                && (!RTPATH_IS_SLASH(ucFrom) || !RTPATH_IS_SLASH(ucTo)) )
    79105                return VERR_NOT_SUPPORTED;
    80106        }
     107    }
    81108#endif
    82109
     
    120147            }
    121148#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
    122             else if (RT_C_TO_LOWER(chFrom) == RT_C_TO_LOWER(chTo))
     149            else if (rtPathCalcRelativeEqualICaseCodepoint(pszPathFromStart, pszPathFrom + 1, pszPathToStart, pszPathTo + 1))
    123150            { /* if not likely, then simpler code structure wise. */ }
    124151#endif
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