2005-07-14 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / corlib / Mono.Globalization.Unicode / SortKey.cs
1 using System;
2 using System.IO;
3 using System.Globalization;
4
5 namespace System.Globalization
6 {
7         public class SortKey
8         {
9                 #region Static members
10                 public static int Compare (SortKey sk1, SortKey sk2)
11                 {
12                         if (Object.ReferenceEquals (sk1, sk2)
13                                 || Object.ReferenceEquals (sk1.OriginalString,
14                                 sk2.OriginalString))
15                                 return 0;
16
17                         byte [] d1 = sk1.KeyData;
18                         byte [] d2 = sk2.KeyData;
19
20                         int len = d1.Length > d2.Length ? d2.Length : d1.Length;
21                         for (int i = 0; i < len; i++)
22                                 if (d1 [i] != d2 [i])
23                                         return d1 [i] < d2 [i] ? -1 : 1;
24                         return d1.Length == d2.Length ? 0 : d1.Length < d2.Length ? -1 : 1;
25                 }
26                 #endregion
27
28                 readonly string source;
29                 readonly CompareOptions options;
30                 readonly byte [] key;
31                 readonly int lcid;
32                 /*
33                 readonly int lv1Length;
34                 readonly int lv2Length;
35                 readonly int lv3Length;
36                 readonly int kanaSmallLength;
37                 readonly int markTypeLength;
38                 readonly int katakanaLength;
39                 readonly int kanaWidthLength;
40                 readonly int identLength;
41                 */
42
43                 // for legacy unmanaged one
44                 internal SortKey (int lcid, string source, CompareOptions opt)
45                 {
46                         this.lcid = lcid;
47                         this.source = source;
48                         this.options = opt;
49                 }
50
51                 internal SortKey (int lcid, string source, byte [] buffer, CompareOptions opt,
52                         int lv1Length, int lv2Length, int lv3Length,
53                         int kanaSmallLength, int markTypeLength,
54                         int katakanaLength, int kanaWidthLength,
55                         int identLength)
56                 {
57                         this.lcid = lcid;
58                         this.source = source;
59                         this.key = buffer;
60                         this.options = opt;
61                         /*
62                         this.lv1Length = lv1Length;
63                         this.lv2Length = lv2Length;
64                         this.lv3Length = lv3Length;
65                         this.kanaSmallLength = kanaSmallLength;
66                         this.markTypeLength = markTypeLength;
67                         this.katakanaLength = katakanaLength;
68                         this.kanaWidthLength = kanaWidthLength;
69                         this.identLength = identLength;
70                         */
71                 }
72
73                 public string OriginalString {
74                         get { return source; }
75                 }
76
77                 public byte [] KeyData {
78                         get { return key; }
79                 }
80 /*
81                 internal int Level1Length {
82                         get { return lv1Length; }
83                 }
84
85                 internal int Level2Index {
86                         get { return lv1Length + 1; }
87                 }
88
89                 internal int Level2Length {
90                         get { return lv2Length; }
91                 }
92
93                 internal int Level3Index {
94                         get { return lv1Length + lv2Length + 2; }
95                 }
96
97                 internal int Level3Length {
98                         get { return lv3Length; }
99                 }
100
101                 internal int Level4Index {
102                         get { return lv1Length + lv2Length + lv3Length + 3; }
103                 }
104
105                 internal int MarkTypeLength {
106                         get { return markTypeLength; }
107                 }
108
109                 internal int KatakanaLength {
110                         get { return katakanaLength; }
111                 }
112
113                 internal int KanaWidthLength {
114                         get { return kanaWidthLength; }
115                 }
116
117                 internal int IdenticalIndex {
118                         get { return key.Length - identLength - 1; }
119                 }
120
121                 internal int IdenticalLength {
122                         get { return identLength; }
123                 }
124 */
125
126                 // copy from original SortKey.cs
127                 public override bool Equals (object value)
128                 {
129                         SortKey other = (value as SortKey);
130                         if(other!=null) {
131                                 if((this.lcid==other.lcid) &&
132                                    (this.options==other.options) &&
133                                    (Compare (this, other)==0)) {
134                                         return(true);
135                                 }
136                         }
137
138                         return(false);
139                 }
140
141                 public override int GetHashCode()
142                 {
143                         return(source.GetHashCode ());
144                 }
145
146                 public override string ToString()
147                 {
148                         return("SortKey - "+lcid+", "+options+", "+source);
149                 }
150         }
151 }