+// VersionCompare - Comparison for versions /*{{{*/
+// ---------------------------------------------------------------------
+/* This fragments the version into E:V-R triples and compares each
+ portion seperately. */
+int pkgVersionCompare(const char *A, const char *AEnd, const char *B,
+ const char *BEnd)
+{
+ // Strip off the epoch and compare it
+ const char *lhs = A;
+ const char *rhs = B;
+ for (;lhs != AEnd && *lhs != ':'; lhs++);
+ for (;rhs != BEnd && *rhs != ':'; rhs++);
+ if (lhs == AEnd)
+ lhs = A;
+ if (rhs == BEnd)
+ rhs = B;
+
+ // Compare the epoch
+ int Res = iVersionCompare(A,lhs,B,rhs);
+ if (Res != 0)
+ return Res;
+
+ // Skip the :
+ if (lhs != A)
+ lhs++;
+ if (rhs != B)
+ rhs++;
+
+ // Find the last -
+ const char *dlhs = AEnd-1;
+ const char *drhs = BEnd-1;
+ for (;dlhs > lhs && *dlhs != '-'; dlhs--);
+ for (;drhs > rhs && *drhs != '-'; drhs--);
+
+ if (dlhs == lhs)
+ dlhs = AEnd;
+ if (drhs == rhs)
+ drhs = BEnd;
+
+ // Compare the main version
+ Res = iVersionCompare(lhs,dlhs,rhs,drhs);
+ if (Res != 0)
+ return Res;
+
+ // Skip the -
+ if (dlhs != lhs)
+ dlhs++;
+ if (drhs != rhs)
+ drhs++;
+ return iVersionCompare(dlhs,AEnd,drhs,BEnd);
+}
+ /*}}}*/