if (m_originalVersion.IsEmpty())
m_originalVersion = "0.0.0";
const char *epoch_end = strchr(m_originalVersion.c_str(), ':');
- if (epoch_end != NULL) {
+ if (epoch_end != NULL)
mEpoch = atoi(m_originalVersion.c_str());
- } else {
+ else
mEpoch = 0;
- }
const char *upstream_start;
- if (epoch_end) {
+ if (epoch_end)
upstream_start = epoch_end + 1;
- } else {
+ else
upstream_start = m_originalVersion.c_str();
- }
const char *upstream_end = strrchr(upstream_start, '-');
size_t upstream_size;
- if (upstream_end == NULL) {
+ if (upstream_end == NULL)
upstream_size = strlen(upstream_start);
- } else {
+ else
upstream_size = upstream_end - upstream_start;
- }
mUpstream = (char*) malloc(upstream_size + 1);
strncpy(mUpstream, upstream_start, upstream_size);
mUpstream[upstream_size] = '\0';
- if (upstream_end == NULL) {
+ if (upstream_end == NULL)
mRevision = strdup("0");
- } else {
+ else
mRevision = strdup(upstream_end + 1);
- }
}
/**Compare two components of a Debian-style version. Return -1, 0, or 1
*/
int AddonVersion::CompareComponent(const char *a, const char *b)
{
- while (*a && *b) {
-
- while (*a && *b && !isdigit(*a) && !isdigit(*b)) {
- if (*a != *b) {
+ while (*a && *b)
+ {
+ while (*a && *b && !isdigit(*a) && !isdigit(*b))
+ {
+ if (*a != *b)
+ {
if (*a == '~') return -1;
if (*b == '~') return 1;
return *a < *b ? -1 : 1;
a++;
b++;
}
- if (*a && *b && (!isdigit(*a) || !isdigit(*b))) {
+ if (*a && *b && (!isdigit(*a) || !isdigit(*b)))
+ {
if (*a == '~') return -1;
if (*b == '~') return 1;
return isdigit(*a) ? -1 : 1;
char *next_a, *next_b;
long int num_a = strtol(a, &next_a, 10);
long int num_b = strtol(b, &next_b, 10);
- if (num_a != num_b) {
+ if (num_a != num_b)
return num_a < num_b ? -1 : 1;
- }
+
a = next_a;
b = next_b;
-
}
- if (!*a && !*b) {
+ if (!*a && !*b)
return 0;
- } else if (*a) {
+ if (*a)
return *a == '~' ? -1 : 1;
- } else {
+ else
return *b == '~' ? 1 : -1;
- }
}
bool AddonVersion::operator<(const AddonVersion& other) const
{
- if (Epoch() != other.Epoch()) {
+ if (Epoch() != other.Epoch())
return Epoch() < other.Epoch();
- }
int result = CompareComponent(Upstream(), other.Upstream());
- if (result) {
- return -1 == result;
- }
+ if (result)
+ return (-1 == result);
- return -1 == CompareComponent(Revision(), other.Revision());
+ return (-1 == CompareComponent(Revision(), other.Revision()));
}
CStdString AddonVersion::Print() const