VirtualBox

Changeset 25029 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Nov 26, 2009 7:39:10 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
55350
Message:

RTStrVersionCompare: Some todos for dealing with beta releases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/strversion.cpp

    r25014 r25029  
    5353 * @returns true if numeric, false if not.
    5454 * @param   ppszVer             The string cursor, IN/OUT.
    55  * @param   pu32Value           Where to return the value if numeric.
     55 * @param   pi32Value           Where to return the value if numeric.
    5656 * @param   pcchBlock           Where to return the block length.
    5757 */
    58 static bool rtStrVersionParseBlock(const char **ppszVer, uint32_t *pu32Value, size_t *pcchBlock)
     58static bool rtStrVersionParseBlock(const char **ppszVer, int32_t *pi32Value, size_t *pcchBlock)
    5959{
    6060    const char *psz = *ppszVer;
     
    6363    if (!*psz)
    6464    {
    65         *pu32Value = 0;
     65        *pi32Value = 0;
    6666        *pcchBlock = 0;
    6767        return false;
     
    7676
    7777        char *pszNext;
    78         int rc = RTStrToUInt32Ex(*ppszVer, &pszNext, 10, pu32Value);
     78        int rc = RTStrToInt32Ex(*ppszVer, &pszNext, 10, pi32Value);
    7979        AssertRC(rc);
    8080        Assert(pszNext == psz);
     
    8282        {
    8383            fNumeric = false;
    84             *pu32Value = 0;
     84            *pi32Value = 0;
    8585        }
     86        *pcchBlock = psz - *ppszVer;
    8687    }
    8788    else
     
    9091            psz++;
    9192        while (*psz && !RT_C_IS_DIGIT(*psz) && !RTSTRVER_IS_PUNCTUACTION(*psz));
    92         *pu32Value = 0;
     93        *pcchBlock = psz - *ppszVer;
     94
     95        /* Translate standard pre release terms to negative values. */
     96        if (   *pcchBlock == 2
     97            && !RTStrNICmp(*ppszVer, "RC", 4))
     98            *pi32Value = -100;
     99        else if (   *pcchBlock == 3
     100            && !RTStrNICmp(*ppszVer, "PRE", 3))
     101            *pi32Value = -200;
     102        else if (   *pcchBlock == 5
     103            && !RTStrNICmp(*ppszVer, "GAMMA", 5))
     104            *pi32Value = -300;
     105        else if (   *pcchBlock == 4
     106            && !RTStrNICmp(*ppszVer, "BETA", 4))
     107            *pi32Value = -400;
     108        else if (   *pcchBlock == 5
     109                 && !RTStrNICmp(*ppszVer, "ALPHA", 4))
     110            *pi32Value = -500;
     111        else
     112            *pi32Value = 0;
     113        if (*pi32Value < 0)
     114        {
     115            /* Trailing number, if so add it? */
     116        }
    93117    }
    94     *pcchBlock = psz - *ppszVer;
    95118
    96119    /* skip punctuation */
     
    115138        const char *pszBlock1 = pszVer1;
    116139        size_t      cchBlock1;
    117         uint32_t    uVal1;
    118         bool        fNumeric1 = rtStrVersionParseBlock(&pszVer1, &uVal1, &cchBlock1);
     140        int32_t     iVal1;
     141        bool        fNumeric1 = rtStrVersionParseBlock(&pszVer1, &iVal1, &cchBlock1);
    119142
    120143        const char *pszBlock2 = pszVer2;
    121144        size_t      cchBlock2;
    122         uint32_t    uVal2;
    123         bool        fNumeric2 = rtStrVersionParseBlock(&pszVer2, &uVal2, &cchBlock2);
     145        int32_t     iVal2;
     146        bool        fNumeric2 = rtStrVersionParseBlock(&pszVer2, &iVal2, &cchBlock2);
    124147
    125148        if (fNumeric1 && fNumeric2)
    126149        {
    127             if (uVal1 != uVal2)
    128                 return uVal1 < uVal2 ? -1 : 1;
     150            if (iVal1 != iVal2)
     151                return iVal1 < iVal2 ? -1 : 1;
    129152        }
    130         else if (   !fNumeric1 && fNumeric2 && uVal2 == 0 && cchBlock1 == 0
    131                  || !fNumeric2 && fNumeric1 && uVal1 == 0 && cchBlock2 == 0
     153        else if (   !fNumeric1 && fNumeric2 && iVal2 <= 0 && cchBlock1 == 0
     154                 || !fNumeric2 && fNumeric1 && iVal1 <= 0 && cchBlock2 == 0
    132155                )
    133156        {
     
    140163                iDiff = cchBlock1 < cchBlock2 ? -1 : 1;
    141164            if (iDiff)
     165            {
     166                /*
     167                 * Special hacks for dealing with 3.1.0_BETA1-r99 vs 3.1.0r99.
     168                 * Note that 3.1.0_BETA1 vs 3.0.1 is handled above with help of
     169                 * negative values returned by the parser.
     170                 */
     171/** @todo finish at home */
     172
    142173                return iDiff < 0 ? -1 : 1;
     174            }
    143175        }
    144176    }
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