| 3151 | |
| 3152 | |
| 3153 | int CompareVersion(LPCTSTR a, LPCTSTR b) |
| 3154 | { |
| 3155 | while (*a || *b) |
| 3156 | { |
| 3157 | // 1.1-a001 < 1.1 = 1.1.0 = 1.1.0+foo |
| 3158 | LPTSTR pa, pb; |
| 3159 | int ia = _tcstol(a, &pa, 10); |
| 3160 | int ib = _tcstol(b, &pb, 10); |
| 3161 | // If *pa is not in the set .-+\0, this component is non-numeric (and not empty). |
| 3162 | // Treat non-numeric as greater than numeric (but assume any absent component is 0). |
| 3163 | if (!_tcschr(_T(".-+"), *pa)) ia = INT_MAX; else a = pa; |
| 3164 | if (!_tcschr(_T(".-+"), *pb)) ib = INT_MAX; else b = pb; |
| 3165 | if (ia < ib) return -1; |
| 3166 | if (ia > ib) return 1; |
| 3167 | // They are either equal or both non-numeric. |
| 3168 | if (*a == '.' || *b == '.') |
| 3169 | { |
| 3170 | if (*a == '.') ++a; |
| 3171 | if (*b == '.') ++b; |
| 3172 | continue; // On to the next component. |
| 3173 | } |
| 3174 | // Give -pre-release lower precedence. |
| 3175 | if (*a == '-' && *b != '-') return -1; |
| 3176 | if (*b == '-' && *a != '-') return 1; |
| 3177 | for (;; ++a, ++b) |
| 3178 | { |
| 3179 | auto ac = *a == '+' || *a == '.' ? '\0' : *a; // Ignore any + suffix (treat as terminator). |
| 3180 | auto bc = *b == '+' || *b == '.' ? '\0' : *b; |
| 3181 | if (ac != bc) return ac < bc ? -1 : 1; |
| 3182 | if (!ac) // End of both components. |
| 3183 | { |
| 3184 | if (*a == '.' || *b == '.') |
| 3185 | break; // Try to compare the next component as numeric. |
| 3186 | return 0; // Both reached the end; a and b are equal. |
| 3187 | } |
| 3188 | } |
| 3189 | } |
| 3190 | return 0; |
| 3191 | } |
| 3192 | |
| 3193 | |
| 3194 |
no outgoing calls
no test coverage detected