1 10 package org.mmbase.util; 11 12 import java.util.ArrayList ; 13 import java.util.List ; 14 15 22 public class StringSplitter { 23 24 31 static public List split(String string, String delimiter) { 32 List result = new ArrayList (); 33 if (string == null) return result; 34 String [] values = string.split(delimiter); 35 for (int i = 0; i < values.length; i++) { 36 result.add(values[i].trim()); 37 } 38 return result; 39 } 40 41 42 48 static public List split(String string) { 49 return split(string, ","); 50 } 51 52 57 static public List splitFunctions(CharSequence attribute) { 58 int commaPos = 0; 59 int nested = 0; 60 List result = new ArrayList (); 61 int i; 62 int length = attribute.length(); 63 for(i = 0; i < length; i++) { 64 char c = attribute.charAt(i); 65 if ((c == ',') || (c == ';')){ 66 if(nested == 0) { 67 result.add(attribute.subSequence(commaPos, i).toString().trim()); 68 commaPos = i + 1; 69 } 70 } else if (c == '(') { 71 nested++; 72 } else if (c == ')') { 73 nested--; 74 } 75 } 76 if (i > 0) { 77 result.add(attribute.toString().substring(commaPos).trim()); 78 } 79 return result; 80 } 81 82 83 } 84 | Popular Tags |