VirtualBox

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


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.

Location:
trunk/src/VBox/Runtime
Files:
2 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    }
  • trunk/src/VBox/Runtime/testcase/tstRTStrVersion.cpp

    r25014 r25029  
    5454    } const aTests[] =
    5555    {
    56         { "", "",                         0 },
    57         { "asdf", "",                     1 }, /* "asdf" is bigger than "" */
    58         { "asdf234", "1.4.5",             1 },
    59         { "12.foo006", "12.6",            1 }, /* "12.foo006" is bigger than "12.6" */
    60         { "1", "1",                       0 },
    61         { "1", "100",                     -1},
    62         { "100", "1",                     1 },
    63         { "3", "4",                       -1},
    64         { "1", "0.1",                     1 },
    65         { "1", "0.0.0.0.10000",           1 },
    66         { "0100", "100",                  0 },
    67         { "1.0.0", "1",                   0 },
    68         { "1.0.0", "100.0.0",             -1},
    69         { "1", "1.0.3.0",                 -1},
    70         { "1.4.5", "1.2.3",               1 },
    71         { "1.2.3", "1.4.5",               -1},
    72         { "1.2.3", "4.5.6",               -1},
    73         { "1.0.4", "1.0.3",               1 },
    74         { "0.1", "0.0.1",                 1 },
    75         { "0.0.1", "0.1.1",               -1},
    76         { "3.1.0", "3.0.14",              1 },
    77         { "2.0.12", "3.0.14",             -1},
    78         { "3.1", "3.0.22",                1 },
    79         { "3.0.14", "3.1.0",              -1},
    80         { "45.63", "04.560.30",           1 },
    81         { "45.006", "45.6",               0 },
    82         { "23.206", "23.06",              1 },
    83         { "23.2", "23.060",               -1},
     56        { "",           "",                 0 },
     57        { "asdf",       "",                 1 },
     58        { "asdf234",    "1.4.5",            1 },
     59        { "12.foo006",  "12.6",             1 },
     60        { "1",          "1",                0 },
     61        { "1",          "100",              -1},
     62        { "100",        "1",                1 },
     63        { "3",          "4",                -1},
     64        { "1",          "0.1",              1 },
     65        { "1",          "0.0.0.0.10000",    1 },
     66        { "0100",       "100",              0 },
     67        { "1.0.0",      "1",                0 },
     68        { "1.0.0",      "100.0.0",          -1},
     69        { "1",          "1.0.3.0",          -1},
     70        { "1.4.5",      "1.2.3",            1 },
     71        { "1.2.3",      "1.4.5",            -1},
     72        { "1.2.3",      "4.5.6",            -1},
     73        { "1.0.4",      "1.0.3",            1 },
     74        { "0.1",        "0.0.1",            1 },
     75        { "0.0.1",      "0.1.1",            -1},
     76        { "3.1.0",      "3.0.14",           1 },
     77        { "2.0.12",     "3.0.14",           -1},
     78        { "3.1",        "3.0.22",           1 },
     79        { "3.0.14",     "3.1.0",            -1},
     80        { "45.63",      "04.560.30",        1 },
     81        { "45.006",     "45.6",             0 },
     82        { "23.206",     "23.06",            1 },
     83        { "23.2",       "23.060",           -1},
    8484
    85         { "VirtualBox-2.0.8-Beta2", "VirtualBox-2.0.8_Beta3-r12345", -1},
    86         { "VirtualBox-2.2.4-Beta2", "VirtualBox-2.2.2", 1 },
    87         { "VirtualBox-2.2.4-Beta3", "VirtualBox-2.2.2-Beta4", 1 },
    88         { "VirtualBox-3.1.8-Alpha1", "VirtualBox-3.1.8-Alpha1-r61454", -1},
    89         { "VirtualBox-3.1.0", "VirtualBox-3.1.2_Beta1", -1},
    90         { "3.1.0_BETA-r12345", "3.1.2", -1},
     85        { "VirtualBox-2.0.8-Beta2",     "VirtualBox-2.0.8_Beta3-r12345",    -1 },
     86        { "VirtualBox-2.2.4-Beta2",     "VirtualBox-2.2.2",                  1 },
     87        { "VirtualBox-2.2.4-Beta3",     "VirtualBox-2.2.2-Beta4",            1 },
     88        { "VirtualBox-3.1.8-Alpha1",    "VirtualBox-3.1.8-Alpha1-r61454",   -1 },
     89        { "VirtualBox-3.1.0",           "VirtualBox-3.1.2_Beta1",           -1 },
     90        { "3.1.0_BETA-r12345",          "3.1.2",                            -1 },
     91        { "3.1.0_BETA-r12345",          "3.1.0",                            -1 },
     92        { "3.1.0_BETA-r12345",          "3.1.0",                            -1 },
     93        { "3.1.0_BETA-r12345",          "3.1.0r12345",                      -1 },
    9194    };
    9295    for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests); iTest++)
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