You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
9 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace UnityTest
|
||
|
{
|
||
|
public class StringComparer : ComparerBaseGeneric<string>
|
||
|
{
|
||
|
public enum CompareType
|
||
|
{
|
||
|
Equal,
|
||
|
NotEqual,
|
||
|
Shorter,
|
||
|
Longer
|
||
|
}
|
||
|
|
||
|
public CompareType compareType;
|
||
|
public StringComparison comparisonType = StringComparison.Ordinal;
|
||
|
public bool ignoreCase = false;
|
||
|
|
||
|
protected override bool Compare(string a, string b)
|
||
|
{
|
||
|
if (ignoreCase)
|
||
|
{
|
||
|
a = a.ToLower();
|
||
|
b = b.ToLower();
|
||
|
}
|
||
|
switch (compareType)
|
||
|
{
|
||
|
case CompareType.Equal:
|
||
|
return String.Compare(a, b, comparisonType) == 0;
|
||
|
case CompareType.NotEqual:
|
||
|
return String.Compare(a, b, comparisonType) != 0;
|
||
|
case CompareType.Longer:
|
||
|
return String.Compare(a, b, comparisonType) > 0;
|
||
|
case CompareType.Shorter:
|
||
|
return String.Compare(a, b, comparisonType) < 0;
|
||
|
}
|
||
|
throw new Exception();
|
||
|
}
|
||
|
}
|
||
|
}
|