1 /*-------------------------------------------------------------------------- 2 * Copyright 2007 utgenome.org 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 *--------------------------------------------------------------------------*/ 16 //-------------------------------------- 17 // UTGBWidget Project 18 // 19 // StringUtil.java 20 // Since: Jun 26, 2007 21 // 22 // $URL$ 23 // $Author$ 24 //-------------------------------------- 25 package org.utgenome.gwt.widget.client; 26 27 import java.util.List; 28 29 /** 30 * Utiltiles for manipulating strings in GWT client codes 31 * 32 * @author leo 33 * 34 */ 35 public class StringUtil { 36 37 /** 38 * Non constractable 39 */ 40 private StringUtil() { 41 } 42 43 /** 44 * Join the given element list with the specified separator 45 * 46 * @param elementList 47 * a list of strings to join 48 * @param separator 49 * e.g., ",", " ", etc. 50 * @return the concatination of the strings in the elementList, separated by the separator 51 */ 52 public static String join(String[] elementList, String separator) { 53 StringBuffer b = new StringBuffer(); 54 for (int i = 0; i < elementList.length - 1; i++) { 55 b.append(elementList[i]); 56 b.append(separator); // white space 57 } 58 b.append(elementList[elementList.length - 1]); 59 return b.toString(); 60 } 61 62 public static String join(List elementList, String separator) { 63 StringBuffer b = new StringBuffer(); 64 for (int i = 0; i < elementList.size() - 1; i++) { 65 b.append(elementList.get(i)); 66 b.append(separator); // white space 67 } 68 b.append(elementList.get(elementList.size() - 1)); 69 return b.toString(); 70 } 71 72 /** 73 * 74 * @param elementList 75 * @return 76 */ 77 public static String joinWithWS(String[] elementList) { 78 return join(elementList, " "); 79 } 80 81 public static String unquote(String s) { 82 if (s.startsWith("\"") && s.endsWith("\"")) 83 return s.substring(1, s.length() - 1); 84 else 85 return s; 86 } 87 }