2 using System.Text.RegularExpressions;
\r
4 namespace NaGet.Packages
\r
6 // TODO Debian-aptのコードを利用しているのでGPLになるのに注意
\r
8 // 引用元: apt-pkg/deb/debversion.cc,v 1.8 2003/09/10 23:39:49 mdz Exp
\r
9 // Debian Version - Versioning system for Debian
\r
10 // This implements the standard Debian versioning system.
\r
11 // Copyright (C) yyyy name of author
\r
13 // This program is free software; you can redistribute it and/or
\r
14 // modify it under the terms of the GNU General Public License
\r
15 // as published by the Free Software Foundation; either version 2
\r
16 // of the License, or (at your option) any later version.
\r
18 // This program is distributed in the hope that it will be useful,
\r
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 // GNU General Public License for more details.
\r
23 // You should have received a copy of the GNU General Public License
\r
24 // along with this program; if not, write to the Free Software
\r
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
28 /// バージョン比較をするためのメソッドを含むクラス
\r
30 public class VersionComparetor : System.Collections.Generic.IComparer<string>
\r
32 public VersionComparetor()
\r
36 private static int order(char x)
\r
38 return (char.IsDigit(x) ? 0
\r
40 : char.IsLetter(x) ? (x)
\r
44 public int Compare(string a, string b)
\r
49 if (Regex.IsMatch(a, @"\.0*$"))
\r
50 Regex.Replace(a, @"\.0*$", string.Empty);
\r
51 if (Regex.IsMatch(b, @"\.0*$"))
\r
52 Regex.Replace(b, @"\.0*$", string.Empty);
\r
59 int apos = 0, bpos = 0;
\r
60 int alen = a.Length, blen = b.Length;
\r
62 while ((apos < alen) && (bpos < blen)) {
\r
65 while ((apos < alen) && (bpos < blen) &&
\r
66 (!char.IsDigit(a[apos]) || !char.IsDigit(b[bpos])) ) {
\r
67 int vc = order(a[apos]);
\r
68 int rc = order(b[bpos]);
\r
74 if (a[apos] == '0') apos ++;
\r
75 if (b[bpos] == '0') bpos ++;
\r
77 while ((apos < alen) && (bpos < blen) &&
\r
78 char.IsDigit(a[apos]) && char.IsDigit(b[bpos])) {
\r
79 if (first_diff == 0)
\r
80 first_diff = a[apos] - b[bpos];
\r
84 if (apos < alen && char.IsDigit(a[apos])) {
\r
86 } else if (bpos < blen && char.IsDigit(b[bpos])) {
\r
88 } else if (first_diff != 0) {
\r
93 if (apos == alen && bpos == blen) {
\r
95 } else if (apos == alen) {
\r
97 } else if (bpos == blen) {
\r
100 return 1; // Shouldnt happen
\r