Adding match mode for id search to MassiveCraftCore and improving the faction argument readers.

This commit is contained in:
Olof Larsson
2011-10-22 14:39:01 +02:00
parent e6d45a6aa2
commit 5bf38ab0aa
7 changed files with 97 additions and 45 deletions

View File

@@ -280,4 +280,36 @@ public class TextUtil
return ""+num+" "+unit+" "+agofromnow;
}
// -------------------------------------------- //
// String comparison
// -------------------------------------------- //
public static int commonStartLength(String a, String b)
{
int len = a.length() > b.length() ? a.length() : b.length();
int i;
for (i = 0; i < len; i++)
{
if (a.charAt(i) != b.charAt(i)) break;
}
return i;
}
public static String getWhereLongestCommonStartCI(Collection<String> candidates, String pattern)
{
String ret = null;
int best = 0;
pattern = pattern.toLowerCase();
for (String candidate : candidates)
{
int csl = commonStartLength(pattern, candidate.toLowerCase());
if (csl > best)
{
best = csl;
ret = candidate;
}
}
return ret;
}
}