1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package org.coach.idltree; 26 27 import java.util.*; 28 29 34 public class Util { 35 public static String unscopeName(String name) { 36 if (name == null) { 37 return name; 38 } 39 int idx = name.lastIndexOf("::"); 40 if (idx >= 0) { 41 return name.substring(idx + 2); 42 } 43 return name; 44 } 45 46 52 public static String [] splitName(String name) { 53 return splitName(name, "."); 54 } 55 56 63 public static String [] splitName(String name, String separator) { 64 if (name == null) { 65 return new String [0]; 66 } 67 StringTokenizer st = new StringTokenizer(name, separator); 68 Vector v = new Vector(); 69 if (name.startsWith(separator)) { 70 v.addElement(""); 71 } 72 while (st.hasMoreTokens()) { 73 v.addElement(st.nextToken()); 74 } 75 String [] s = new String [v.size()]; 76 v.copyInto(s); 77 return s; 78 } 79 80 86 public static String combineName(String [] split) { 87 return combineName(split, "."); 88 } 89 90 97 public static String combineName(String [] split, String separator) { 98 String s = ""; 99 for (int i = 0; i < split.length; i++) { 100 if (i != 0) { 101 s += separator; 102 } 103 s += split[i]; 104 } 105 return s; 106 } 107 108 public static String replaceAll(String source, String what, String into) { 109 int index = source.indexOf(what); 110 if (index == -1) return source; 111 String s1 = source.substring(0, index); 112 String s2 = source.substring(index + what.length(), source.length()); 113 return s1 + into + replaceAll(s2, what, into); 114 } 115 } 116 | Popular Tags |