2 using System.Text.RegularExpressions;
\r
4 namespace NaGet.Packages
\r
6 // TODO Debian-apt
\82Ì
\83R
\81[
\83h
\82ð
\97\98\97p
\82µ
\82Ä
\82¢
\82é
\82Ì
\82ÅGPL
\82É
\82È
\82é
\82Ì
\82É
\92\8d\88Ó
\r
9 public class VersionComparetor : System.Collections.Generic.IComparer<string>
\r
11 public VersionComparetor()
\r
15 private static int order(char x)
\r
17 return (char.IsDigit(x) ? 0
\r
19 : char.IsLetter(x) ? (x)
\r
23 public int Compare(string a, string b)
\r
28 if (Regex.IsMatch(a, @"\.0*$"))
\r
29 Regex.Replace(a, @"\.0*$", string.Empty);
\r
30 if (Regex.IsMatch(b, @"\.0*$"))
\r
31 Regex.Replace(b, @"\.0*$", string.Empty);
\r
38 int apos = 0, bpos = 0;
\r
39 int alen = a.Length, blen = b.Length;
\r
41 while ((apos < alen) && (bpos < blen)) {
\r
44 while ((apos < alen) && (bpos < blen) &&
\r
45 (!char.IsDigit(a[apos]) || !char.IsDigit(b[bpos])) ) {
\r
46 int vc = order(a[apos]);
\r
47 int rc = order(b[bpos]);
\r
53 if (a[apos] == '0') apos ++;
\r
54 if (b[bpos] == '0') bpos ++;
\r
56 while ((apos < alen) && (bpos < blen) &&
\r
57 char.IsDigit(a[apos]) && char.IsDigit(b[bpos])) {
\r
58 if (first_diff == 0)
\r
59 first_diff = a[apos] - b[bpos];
\r
63 if (apos < alen && char.IsDigit(a[apos])) {
\r
65 } else if (bpos < blen && char.IsDigit(b[bpos])) {
\r
67 } else if (first_diff != 0) {
\r
72 if (apos == alen && bpos == blen) {
\r
74 } else if (apos == alen) {
\r
76 } else if (bpos == blen) {
\r
79 return 1; // Shouldnt happen
\r