From: Eric P. <th...@us...> - 2010-03-01 19:10:27
|
Update of /cvsroot/sandev/sand/apps/basics/src/org/sandev/basics/util In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv22460 Modified Files: StringUtil.java Log Message: Added multiContains and multiStartsWith utilities. Found I needed this and seemed like they might be generally useful. Index: StringUtil.java =================================================================== RCS file: /cvsroot/sandev/sand/apps/basics/src/org/sandev/basics/util/StringUtil.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** StringUtil.java 27 Jan 2010 23:33:06 -0000 1.38 --- StringUtil.java 1 Mar 2010 19:10:17 -0000 1.39 *************** *** 1452,1455 **** --- 1452,1492 ---- } + + /** + * Return true if one of the candidate tokens exist in the source + * string, false otherwise. If delimeter is not null, then only + * test subparts of the source beginning with the delimiter. + */ + public static boolean multiContains(String src,String[] tokens, + Character delimiter) + { + boolean justReadDelimiter=(delimiter==null); + int srclen=src.length(); + for(int i=0;i<srclen;i++) { + if(delimiter!=null) { + if((src.charAt(i)==delimiter.charValue())&&((i+1)<srclen)) { + if(multiStartsWith(src.substring(i),tokens)) { + return true; } } + continue; } + else { //null delimiter + if(multiStartsWith(src.substring(i),tokens)) { + return true; } } } + return false; + } + + + /** + * Return true if the given source string starts with one of the + * given tokens, false otherwise. + */ + public static boolean multiStartsWith(String src,String[] tokens) + { + for(int i=0;i<tokens.length;i++) { + if(src.startsWith(tokens[i])) { + return true; } } + return false; + } + + } |