/* * CommonUtils.java * * * Copyright (c) 2004 David Hjelm <dhjelm@ling.gu.se>. * * * Project homepage: <http://sourceforge.net/projects/trindikit>. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ package se.gu.ling.trindikit.oaa.common; import java.util.*; public class CommonUtils{ //returns all elements in v as a String separated by sep public static String join(Vector v,String sep){ String joined=""; if(v!=null){ joined=v.elementAt(0).toString(); for(int i=1;i<v.size();++i) joined=joined+sep+v.elementAt(i).toString(); } return joined; } public static String unquote(String str){ //remove quotes (') from string if any String s = str; if(s.length()>0 && s.charAt(0) =='\'') s=s.substring(1); if(s.length()>0 && s.charAt(s.length()-1)=='\'') s=s.substring(0,s.length()-1); return s; } public static Vector splitOnWhitespace(String s){ Vector v = new Vector(); int i = s.indexOf(' '); if(i==-1){ v.add(s); } else{ v.add(s.substring(0,i)); v.addAll(splitOnWhitespace(s.substring(i+1))); } return v; } }