2 using System
.Globalization
;
4 using Uni
= Mono
.Globalization
.Unicode
.MSCompatUnicodeTable
;
6 namespace Mono
.Globalization
.Unicode
10 SimpleCollator coll
= new SimpleCollator (CultureInfo
.InvariantCulture
);
14 static void Main (string [] args
)
16 if (args
.Length
> 0 && args
[0] == "--generate")
17 new TestDriver ().Generate ();
18 if (args
.Length
> 0 && args
[0] == "--check")
19 new TestDriver ().CheckCultures ();
21 new TestDriver ().Run ();
26 foreach (CultureInfo ci
in CultureInfo
.GetCultures (
27 CultureTypes
.AllCultures
))
28 Console
.WriteLine ("Culture {0}({1}) : OK: {2}", ci
.LCID
, ci
.Name
, new SimpleCollator (ci
));
33 LastIndexOf ("\u30D1\u30FC", "\u30A2", CompareOptions
.IgnoreNonSpace
);
37 DumpSortKey ("\u00C6");
38 DumpSortKey ("ABCABC", 5, 1, CompareOptions.IgnoreCase);
41 DumpSortKey ("A-B-C");
42 DumpSortKey ("A\u0304");
43 DumpSortKey ("\u0100");
47 Compare ("A", "a", CompareOptions.IgnoreCase);
48 Compare ("\uFF10", "0", CompareOptions.IgnoreWidth);
49 Compare ("\uFF21", "a", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
51 Compare ("AE", "\u00C6");
52 Compare ("AB\u01c0C", "A\u01c0B\u01c0C", CompareOptions.IgnoreSymbols);
53 Compare ("A\u0304", "\u0100"); // diacritical weight addition
54 Compare ("ABCABC", 5, 1, "c", 0, 1, CompareOptions.IgnoreCase);
55 Compare ("-d:NET_1_1", 0, 1, "-", 0, 1, CompareOptions.None);
57 IndexOf ("ABC", '1', CompareOptions.None);
58 IndexOf ("ABCABC", 'c', CompareOptions.IgnoreCase);
59 IndexOf ("ABCABC", '\uFF22', CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
60 IndexOf ("ABCDE", '\u0117', CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
61 IndexOf ("ABCABC", 'B', 1, 5, CompareOptions.IgnoreCase);
62 IndexOf ("\u00E6", 'a', CompareOptions.None);
64 LastIndexOf ("ABC", '1', CompareOptions.None);
65 LastIndexOf ("ABCABC", 'c', CompareOptions.IgnoreCase);
66 LastIndexOf ("ABCABC", '\uFF22', CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
67 LastIndexOf ("ABCDE", '\u0117', CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
69 IsPrefix ("ABC", "c", CompareOptions.IgnoreCase);
70 IsPrefix ("BC", "c", CompareOptions.IgnoreCase);
71 IsPrefix ("C", "c", CompareOptions.IgnoreCase);
72 IsPrefix ("EDCBA", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
73 IsPrefix ("ABC", "AB", CompareOptions.IgnoreCase);
74 IsPrefix ("ae", "\u00E6", CompareOptions.None);
75 IsPrefix ("\u00E6", "ae", CompareOptions.None);
76 IsPrefix ("\u00E6", "a", CompareOptions.None);
77 IsPrefix ("\u00E6s", "ae", CompareOptions.None);
78 IsPrefix ("\u00E6", "aes", CompareOptions.None);
79 IsPrefix ("--start", "--", CompareOptions.None);
80 IsPrefix ("-d:NET_1_1", "-", CompareOptions.None);
81 IsPrefix ("-d:NET_1_1", "@", CompareOptions.None);
83 IsSuffix ("ABC", "c", CompareOptions.IgnoreCase);
84 IsSuffix ("BC", "c", CompareOptions.IgnoreCase);
85 IsSuffix ("CBA", "c", CompareOptions.IgnoreCase);
86 IsSuffix ("ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
87 IsSuffix ("\u00E6", "a", CompareOptions.None);
88 IsSuffix ("\u00E6", "e", CompareOptions.None);
89 IsSuffix ("\u00E6", "ae", CompareOptions.None);
90 IsSuffix ("ae", "\u00E6", CompareOptions.None);
91 IsSuffix ("e", "\u00E6", CompareOptions.None);
93 IndexOf ("ABC", "1", CompareOptions.None);
94 IndexOf ("ABCABC", "c", CompareOptions.IgnoreCase);
95 IndexOf ("ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
96 IndexOf ("ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
97 IndexOf ("ABCABC", "BC", CompareOptions.IgnoreCase);
98 IndexOf ("BBCBBC", "BC", CompareOptions.IgnoreCase);
99 IndexOf ("ABCDEF", "BCD", 0, 3, CompareOptions.IgnoreCase);
100 IndexOf ("-ABC", "-", CompareOptions.None);
101 IndexOf ("--ABC", "--", CompareOptions.None);
103 LastIndexOf ("ABC", "1", CompareOptions.None);
104 LastIndexOf ("ABCABC", "c", CompareOptions.IgnoreCase);
105 LastIndexOf ("ABCABC", "\uFF22", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth);
106 LastIndexOf ("ABCDE", "\u0117", CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase);
107 LastIndexOf ("ABCABC", "BC", CompareOptions.IgnoreCase);
108 LastIndexOf ("BBCBBC", "BC", CompareOptions.IgnoreCase);
109 LastIndexOf ("original", "rig", CompareOptions.None);
110 LastIndexOf ("\u00E6", "ae", CompareOptions.None);
111 LastIndexOf ("-ABC", "-", CompareOptions.None);
112 LastIndexOf ("--ABC", "--", CompareOptions.None);
115 coll
= new SimpleCollator (new CultureInfo ("hu"));
116 DumpSortKey ("ZSAZS1");
117 IsSuffix ("zs", "z", CompareOptions
.None
);
118 IsSuffix ("zs", "s", CompareOptions
.None
);
119 IsSuffix ("zs", "zs", CompareOptions
.None
);
120 IsSuffix ("sz", "z", CompareOptions
.None
);
121 IsSuffix ("sz", "s", CompareOptions
.None
);
122 IsSuffix ("--ABC", "--", CompareOptions
.None
);
123 IsSuffix ("ABC--", "--", CompareOptions
.None
);
126 coll = new SimpleCollator (new CultureInfo (""));
127 Compare ("c\u00F4te", "cot\u00E9");
128 DumpSortKey ("c\u00F4te");
129 DumpSortKey ("cot\u00E9");
130 coll = new SimpleCollator (new CultureInfo ("fr"));
131 Compare ("c\u00F4te", "cot\u00E9");
132 DumpSortKey ("c\u00F4te");
133 DumpSortKey ("cot\u00E9");
139 // dump sortkey for every single character.
140 for (int i
= 0; i
<= char.MaxValue
; i
++) {
141 byte [] data
= coll
.GetSortKey (new string ((char) i
, 1), CompareOptions
.StringSort
).KeyData
;
142 if (data
.Length
== 5 && data
[0] == 1 && data
[1] == 1 &&
143 data
[2] == 1 && data
[3] == 1 && data
[4] == 0)
145 foreach (byte b
in data
)
146 Console
.Write ("{0:X02} ", b
);
147 Console
.WriteLine (" : {0:X04}, {1}",
148 i
, Char
.GetUnicodeCategory ((char) i
));
152 void Compare (string s1
, string s2
)
154 Compare (s1
, s2
, CompareOptions
.None
);
157 void Compare (string s1
, string s2
, CompareOptions opt
)
159 Console
.Error
.WriteLine ("compare ({3}): {0} {1} / {2}",
160 coll
.Compare (s1
, s2
, opt
), s1
, s2
, opt
);
163 void Compare (string s1
, int idx1
, int len1
, string s2
, int idx2
, int len2
, CompareOptions opt
)
165 Console
.Error
.WriteLine ("compare ({3} {4} {5} {6} {7}): {0} {1} / {2}",
166 coll
.Compare (s1
, idx1
, len1
, s2
, idx2
, len2
, opt
), s1
, s2
,
167 opt
, idx1
, len1
, idx2
, len2
);
170 void IndexOf (string s
, char c
, CompareOptions opt
)
172 IndexOf (s
, c
, 0, s
.Length
, opt
);
175 void IndexOf (string s
, char c
, int idx
, int len
, CompareOptions opt
)
177 Console
.Error
.WriteLine ("cIndex ({3} {4} {5}): {0} {1} / {2}",
178 coll
.IndexOf (s
, c
, idx
, len
, opt
), s
, c
, opt
, idx
, len
);
181 void IndexOf (string s1
, string s2
, CompareOptions opt
)
183 IndexOf (s1
, s2
, 0, s1
.Length
, opt
);
186 void IndexOf (string s1
, string s2
, int idx
, int len
, CompareOptions opt
)
188 Console
.Error
.WriteLine ("sIndex ({3} {4} {5}): {0} {1} / {2}",
189 coll
.IndexOf (s1
, s2
, idx
, len
, opt
), s1
, s2
, opt
, idx
, len
);
192 void IsPrefix (string s1
, string s2
, CompareOptions opt
)
194 Console
.Error
.WriteLine ("prefix ({3}): {0} {1} / {2}",
195 coll
.IsPrefix (s1
, s2
, opt
), s1
, s2
, opt
);
198 void LastIndexOf (string s
, char c
, CompareOptions opt
)
200 Console
.Error
.WriteLine ("cLast ({3}): {0} {1} / {2}",
201 coll
.LastIndexOf (s
, c
, opt
), s
, c
, opt
);
204 void LastIndexOf (string s1
, string s2
, CompareOptions opt
)
206 Console
.Error
.WriteLine ("sLast ({3}): {0} {1} / {2}",
207 coll
.LastIndexOf (s1
, s2
, opt
), s1
, s2
, opt
);
210 void LastIndexOf (string s1
, string s2
, int idx
, int len
, CompareOptions opt
)
212 Console
.Error
.WriteLine ("sLast ({3},{4},{5}): {0} {1} / {2}",
213 coll
.LastIndexOf (s1
, s2
, idx
, len
, opt
), s1
, s2
, opt
, idx
, len
);
216 void IsSuffix (string s1
, string s2
, CompareOptions opt
)
218 Console
.Error
.WriteLine ("suffix ({3}): {0} {1} / {2}",
219 coll
.IsSuffix (s1
, s2
, opt
), s1
, s2
, opt
);
222 void DumpSortKey (string s
)
224 DumpSortKey (s
, 0, s
.Length
, CompareOptions
.None
);
227 void DumpSortKey (string s
, int idx
, int len
, CompareOptions opt
)
229 byte [] data
= coll
.GetSortKey (s
, idx
, len
, opt
).KeyData
;
230 foreach (byte b
in data
)
231 Console
.Error
.Write ("{0:X02} ", b
);
232 Console
.Error
.WriteLine (" : {0} ({1} {2} {3})", s
, opt
, idx
, len
);