1 3 package com.sshtools.util; 4 5 import java.util.Vector ; 6 7 8 11 public class Util { 12 13 private Util() { 14 super(); 15 } 16 17 public static void main(String [] args) { 18 } 19 20 public static String [] splitString(String str, char delim) { 21 return splitString(str, delim, (char) -1, (char) -1); 22 } 23 24 public static String [] splitString(String str, char delim, char quote, 25 char escape) { 26 Vector v = new Vector (); 27 StringBuffer str1 = new StringBuffer (); 28 char ch = ' '; 29 boolean inQuote = false; 30 boolean escaped = false; 31 32 for (int i = 0; i < str.length(); i++) { 33 ch = str.charAt(i); 34 35 if ((escape != -1) && (ch == escape) && !escaped) { 36 escaped = true; 37 } else { 38 if ((quote != -1) && (ch == quote) && !escaped) { 39 inQuote = !inQuote; 40 } else if (!inQuote && (ch == delim && !escaped)) { 41 v.addElement(str1.toString()); 42 str1.setLength(0); 43 } else { 44 str1.append(ch); 45 } 46 if(escaped) { 47 escaped = false; 48 } 49 } 50 } 51 52 if (str.length() > 0) { 53 v.addElement(str1.toString()); 54 55 } 56 String [] array; 57 array = new String [v.size()]; 58 v.copyInto(array); 59 60 return array; 61 } 62 63 public static void sort(Vector v, SortComparator comparator) { 64 int i, j, c; 66 boolean s; 67 for (i = v.size(); --i >= 0;) { 68 s = false; 69 for (j = 0; j < i; j++) { 70 Object o1 = v.elementAt(j); 71 Object o2 = v.elementAt(j + 1); 72 c = comparator.sortCompare(o1, o2); 73 if (c > 0) { 74 v.setElementAt(o2, j); 75 v.setElementAt(o1, j + 1); 76 s = true; 77 } 78 } 79 if (!s) { 80 return; 81 } 82 } 83 } 84 } 85 | Popular Tags |