Changeset 35076 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Dec 14, 2010 1:31:41 PM (14 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/strversion.cpp
r28800 r35076 56 56 const char *psz = *ppszVer; 57 57 58 /* Check for end-of-string. */ 58 /* 59 * Check for end-of-string. 60 */ 59 61 if (!*psz) 60 62 { … … 64 66 } 65 67 68 /* 69 * Try convert the block to a number the simple way. 70 */ 71 char ch; 66 72 bool fNumeric = RT_C_IS_DIGIT(*psz); 67 73 if (fNumeric) 68 74 { 69 75 do 70 psz++;71 while ( *psz && RT_C_IS_DIGIT(*psz));76 ch = *++psz; 77 while (ch && RT_C_IS_DIGIT(ch)); 72 78 73 79 int rc = RTStrToInt32Ex(*ppszVer, NULL, 10, pi32Value); … … 81 87 else 82 88 { 89 /* 90 * Find the end of the current string. Make a special case for SVN 91 * revision numbers that immediately follows a release tag string. 92 */ 83 93 do 84 psz++; 85 while (*psz && !RT_C_IS_DIGIT(*psz) && !RTSTRVER_IS_PUNCTUACTION(*psz)); 94 ch = *++psz; 95 while ( ch 96 && !RT_C_IS_DIGIT(ch) 97 && !RTSTRVER_IS_PUNCTUACTION(ch)); 98 86 99 size_t cchBlock = psz - *ppszVer; 87 88 /* Translate standard pre release terms to negative values. */ 89 int32_t iVal1; 90 if ( cchBlock == 2 && !RTStrNICmp(*ppszVer, "RC", 2)) 91 iVal1 = -100000; 92 else if (cchBlock == 3 && !RTStrNICmp(*ppszVer, "PRE", 3)) 93 iVal1 = -200000; 94 else if (cchBlock == 5 && !RTStrNICmp(*ppszVer, "GAMMA", 5)) 95 iVal1 = -300000; 96 else if (cchBlock == 4 && !RTStrNICmp(*ppszVer, "BETA", 4)) 97 iVal1 = -400000; 98 else if (cchBlock == 5 && !RTStrNICmp(*ppszVer, "ALPHA", 5)) 99 iVal1 = -500000; 100 else 101 iVal1 = 0; 100 if ( cchBlock > 1 101 && psz[-1] == 'r' 102 && RT_C_IS_DIGIT(*psz)) 103 { 104 psz--; 105 cchBlock--; 106 } 107 108 109 /* 110 * Translate standard pre release terms to negative values. 111 */ 112 static const struct 113 { 114 size_t cch; 115 const char *psz; 116 int32_t iValue; 117 } s_aTerms[] = 118 { 119 { 2, "RC", -100000 }, 120 { 3, "PRE", -200000 }, 121 { 5, "GAMMA", -300000 }, 122 { 4, "BETA", -400000 }, 123 { 5, "ALPHA", -500000 } 124 }; 125 126 int32_t iVal1 = 0; 127 for (unsigned i = 0; i < RT_ELEMENTS(s_aTerms); i++) 128 if ( cchBlock == s_aTerms[i].cch 129 && !RTStrNCmp(s_aTerms[i].psz, *ppszVer, cchBlock)) 130 { 131 iVal1 = s_aTerms[i].iValue; 132 break; 133 } 102 134 if (iVal1 != 0) 103 135 { 104 /* Trailing number? Add it assuming BETA == BETA1. */ 136 /* 137 * Does the prelease term have a trailing number? 138 * Add it assuming BETA == BETA1. 139 */ 105 140 if (RT_C_IS_DIGIT(*psz)) 106 141 { 107 142 const char *psz2 = psz; 108 143 do 109 psz++; 110 while (*psz && !RT_C_IS_DIGIT(*psz) && !RTSTRVER_IS_PUNCTUACTION(*psz)); 144 ch = *++psz; 145 while ( ch 146 && RT_C_IS_DIGIT(ch) 147 && !RTSTRVER_IS_PUNCTUACTION(ch)); 111 148 112 149 int rc = RTStrToInt32Ex(psz2, NULL, 10, pi32Value); … … 125 162 *pcchBlock = psz - *ppszVer; 126 163 127 /* skip punctuation */ 164 /* 165 * Skip trailing punctuation. 166 */ 128 167 if (RTSTRVER_IS_PUNCTUACTION(*psz)) 129 168 psz++; -
trunk/src/VBox/Runtime/testcase/tstRTStrVersion.cpp
r28800 r35076 86 86 { "3.1.0_BETA-r12345", "3.1.2", -1 }, 87 87 { "3.1.0_BETA1r12345", "3.1.0", -1 }, 88 { "3.1.0_BETAr12345", "3.1.0", 1 }, /* not considered a beta because of missing punctuation */88 { "3.1.0_BETAr12345", "3.1.0", -1 }, 89 89 { "3.1.0_BETA-r12345", "3.1.0", -1 }, 90 90 { "3.1.0_BETA-r12345", "3.1.0", -1 }, … … 99 99 { "3.1.0_BETA2", "3.1.0_ABC", -1 }, /* ABC isn't indicating a prerelease, BETA does */ 100 100 { "3.1.0_BETA", "3.1.0_ATEB", -1 }, 101 { "4.0.0_ALPHAr68482", "4.0.0_ALPHAr68483", -1 }, 102 { "4.0.0_ALPHA1r68482", "4.0.0_ALPHAr68482", 0 }, 103 { "4.0.0_ALPHA-r68482", "4.0.0_ALPHAr68482", 0 }, 104 { "4.0.0_ALPHAr68483", "4.0.0_BETAr68783", -1 }, 105 { "4.0.0_ALPHAr68483", "4.0.0_BETA1r68783", -1 }, 106 { "4.0.0_ALPHAr68483", "4.0.0_BETA2r68783", -1 }, 107 { "4.0.0_ALPHAr68483", "4.0.0_BETA2r68784", -1 }, 101 108 }; 102 109 for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests); iTest++)
Note:
See TracChangeset
for help on using the changeset viewer.