DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SystemCollatorFactory.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 using System;
17 using System.Globalization;
18 
19 namespace Deveel.Data.Text {
20  public sealed class SystemCollatorFactory : ICollatorFactory {
21  #region ICollatorFactory Members
22  public ICollator CreateCollator(CultureInfo locale, CollationStrength strength, CollationDecomposition decomposition) {
23  return new SystemCollator(locale);
24  }
25  #endregion
26 
27  #region SystemCollator
28  class SystemCollator : ICollator {
29  #region .ctor
30  public SystemCollator(CultureInfo locale) {
31  this.locale = locale;
32  }
33  #endregion
34 
35  #region Fields
36  private CultureInfo locale;
37  #endregion
38 
39  #region Properties
40  public CollationDecomposition Decomposition {
41  get { return CollationDecomposition.Canonical; }
42  }
43 
44  public CollationStrength Strength {
45  get { return CollationStrength.Identical; }
46  }
47  #endregion
48 
49  #region Public Methods
50  public int Compare(string s1, string s2) {
51  return locale.CompareInfo.Compare(s1, s2);
52  }
53 
54  public bool Equals(string s1, string s2) {
55  return String.Compare(s1, s2, false, locale) == 0;
56  }
57 
58  public CollationKey GetCollationKey(string source) {
59  throw new NotSupportedException();
60  }
61 
62  public int Compare(object x, object y) {
63  return Compare(x.ToString(), y.ToString());
64  }
65 
66  public object Clone() {
67  return new SystemCollator((CultureInfo)locale.Clone());
68  }
69  #endregion
70  }
71  #endregion
72  }
73 }
ICollator CreateCollator(CultureInfo locale, CollationStrength strength, CollationDecomposition decomposition)