/* * StringLib.java * * Copyright (C) 2003 Miika Nurminen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * * @author minurmin */ public class StringLib { /** Creates a new instance of StringLib */ public StringLib() { } /** * Checks if any string in s equals any string in i. * Returns first matching index or -1 if not found. */ public static int arrayIndexOf(String[] hayStack, String[] n, boolean ignorecase) { if ((hayStack==null) || (hayStack.length==0) || (n==null) || (n.length==0)) return -1; for (int i=0; is.length()) || (s.lastIndexOf(toCat)<(s.length()-toCat.length()))) { return s+toCat; } return s; } public static boolean testEndStr(String name, String postfix) { return name.indexOf(postfix)==(name.length()-(postfix.length())); } public static String removePostfix(String src,String postfix) { int i = src.lastIndexOf(postfix); if (i>=0) { return src.substring(0,i); } return src; } public static String removePrefix(String src,String prefix) { int i = src.indexOf(prefix); if (i==0) { return src.substring(prefix.length()); } return src; } /** * Unit test. */ public static void main(String[] args) { /* String[] s = { "testi","toinen",null,"","yet" }; System.out.println(arrayIndexOf(s,"")); System.out.println(arrayIndexOf(s,null)); System.out.println(arrayIndexOf(s,"yet")); System.out.println(arrayIndexOf(s,"not found")); System.out.println(arrayIndexOf(s,"Toinen")); System.out.println(arrayIndexOf(s,"Toinen",true));*/ System.out.println("Testing catOnce"); String[] t = {"","testi","testi+",null,"l"}; for (int i=0; i