forked from runuo/runuo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsensitive.cs
77 lines (63 loc) · 2.08 KB
/
Insensitive.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/***************************************************************************
* Insensitive.cs
* -------------------
* begin : May 1, 2002
* copyright : (C) The RunUO Software Team
* email : [email protected]
*
* $Id$
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
using System;
using System.Collections;
namespace Server
{
public static class Insensitive
{
private static IComparer m_Comparer = CaseInsensitiveComparer.Default;
public static IComparer Comparer
{
get{ return m_Comparer; }
}
public static int Compare( string a, string b )
{
return m_Comparer.Compare( a, b );
}
public static bool Equals( string a, string b )
{
if ( a == null && b == null )
return true;
else if ( a == null || b == null || a.Length != b.Length )
return false;
return ( m_Comparer.Compare( a, b ) == 0 );
}
public static bool StartsWith( string a, string b )
{
if ( a == null || b == null || a.Length < b.Length )
return false;
return ( m_Comparer.Compare( a.Substring( 0, b.Length ), b ) == 0 );
}
public static bool EndsWith( string a, string b )
{
if ( a == null || b == null || a.Length < b.Length )
return false;
return ( m_Comparer.Compare( a.Substring( a.Length - b.Length ), b ) == 0 );
}
public static bool Contains( string a, string b )
{
if ( a == null || b == null || a.Length < b.Length )
return false;
a = a.ToLower();
b = b.ToLower();
return ( a.IndexOf( b ) >= 0 );
}
}
}