|
From: <pat...@us...> - 2009-12-18 22:51:03
|
Revision: 995
http://cishell.svn.sourceforge.net/cishell/?rev=995&view=rev
Author: pataphil
Date: 2009-12-18 22:50:57 +0000 (Fri, 18 Dec 2009)
Log Message:
-----------
* Added StringUtilities.prefixIndex.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-17 20:26:50 UTC (rev 994)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-18 22:50:57 UTC (rev 995)
@@ -161,4 +161,18 @@
cleanedWord.substring(1).toLowerCase();
}
}
+
+ public static int prefixIndex(String target, String[] prefixes) {
+ /*
+ * Look for the prefixes in reverse order (so a longer one will win out over a shorter one
+ * if they both have a beginning in common).
+ */
+ for (int ii = (prefixes.length - 1); ii >= 0; ii--) {
+ if (target.startsWith(prefixes[ii])) {
+ return ii;
+ }
+ }
+
+ return -1;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|