#include <apt-pkg/debversion.h>
#include <apt-pkg/pkgcache.h>
+#include <string.h>
#include <stdlib.h>
#include <ctype.h>
/*}}}*/
// debVS::CmpFragment - Compare versions /*{{{*/
// ---------------------------------------------------------------------
-/* This compares a fragment of the version. This is a slightly adapted
- version of what dpkg uses. */
-#define order(x) ((x) == '~' ? -1 \
- : isdigit((x)) ? 0 \
- : !(x) ? 0 \
- : isalpha((x)) ? (x) \
- : (x) + 256)
-int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
- const char *B,const char *BEnd)
+/* This compares a fragment of the version. This is a slightly adapted
+ version of what dpkg uses in dpkg/lib/dpkg/version.c.
+ In particular, the a | b = NULL check is removed as we check this in the
+ caller, we use an explicit end for a | b strings and we check ~ explicit. */
+static int order(char c)
{
- if (A >= AEnd && B >= BEnd)
+ if (isdigit(c))
return 0;
- if (A >= AEnd)
- {
- if (*B == '~') return 1;
+ else if (isalpha(c))
+ return c;
+ else if (c == '~')
return -1;
- }
- if (B >= BEnd)
- {
- if (*A == '~') return -1;
- return 1;
- }
-
+ else if (c)
+ return c + 256;
+ else
+ return 0;
+}
+int debVersioningSystem::CmpFragment(const char *A,const char *AEnd,
+ const char *B,const char *BEnd)
+{
/* Iterate over the whole string
What this does is to split the whole string into groups of
numeric and non numeric portions. For instance:
int rc = order(*rhs);
if (vc != rc)
return vc - rc;
- lhs++; rhs++;
+ ++lhs; ++rhs;
}
while (*lhs == '0')
- lhs++;
+ ++lhs;
while (*rhs == '0')
- rhs++;
+ ++rhs;
while (isdigit(*lhs) && isdigit(*rhs))
{
if (!first_diff)
first_diff = *lhs - *rhs;
- lhs++;
- rhs++;
+ ++lhs;
+ ++rhs;
}
if (isdigit(*lhs))
return 1;
}
- // Shouldnt happen
+ // Shouldn't happen
return 1;
}
/*}}}*/
return false;
Op &= 0x0F;
- size_t const lenPkgVer = strlen(PkgVer);
- size_t const lenDepVer = strlen(DepVer);
-
- // take a shortcut for equals which are string-equal as well
- if (Op == pkgCache::Dep::Equals && lenPkgVer == lenDepVer &&
- memcmp(PkgVer, DepVer, lenPkgVer) == 0)
- return true;
+ // fast track for (equal) strings [by location] which are by definition equal versions
+ if (PkgVer == DepVer)
+ return Op == pkgCache::Dep::Equals || Op == pkgCache::Dep::LessEq || Op == pkgCache::Dep::GreaterEq;
- // Perform the actual comparision.
- int const Res = DoCmpVersion(PkgVer, PkgVer + lenPkgVer, DepVer, DepVer + lenDepVer);
+ // Perform the actual comparison.
+ int const Res = CmpVersion(PkgVer, DepVer);
switch (Op)
{
case pkgCache::Dep::LessEq: