| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // System.Collections.CaseInsensitiveHashCodeProvider
- //
- // Author:
- // Sergey Chaban ([email protected])
- //
- using System;
- using System.Collections;
- namespace System.Collections {
- public class CaseInsensitiveHashCodeProvider : IHashCodeProvider {
- private static CaseInsensitiveHashCodeProvider singleton;
- // Class constructor
- static CaseInsensitiveHashCodeProvider ()
- {
- singleton=new CaseInsensitiveHashCodeProvider ();
- }
- // Public instance constructor
- public CaseInsensitiveHashCodeProvider ()
- {
- }
- //
- // Public static properties
- //
- public static CaseInsensitiveHashCodeProvider Default {
- get {
- return singleton;
- }
- }
- //
- // Instance methods
- //
- public override string ToString ()
- {
- return "mono::System.Collections.CaseInsensitiveHashCodeProvider";
- }
- //
- // IHashCodeProvider
- //
- public virtual int GetHashCode (object obj)
- {
- if (obj == null) {
- throw new ArgumentNullException ("obj is null");
- }
- string str = obj as string;
- if (str == null) {
- // FIXME:
- return 0;
- }
- int h = 0;
- char c;
- if (str.Length > 0) {
- for (int i = 0;i<str.Length;i++) {
- c = str [i];
- if (Char.IsLetter (c))
- c = Char.ToLower (c);
- h = h * 31 + c;
- }
- }
- return h;
- }
- } // CaseInsensitiveHashCodeProvider
- }
|