Here you can find the source of splitWithBreakingBrace(String str, char separator, char braceStart, char braceEnd)
public static String[] splitWithBreakingBrace(String str, char separator, char braceStart, char braceEnd)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static String[] splitWithBreakingBrace(String str, char separator, char braceStart, char braceEnd) { return splitWithBreakingBrace(str, new char[] { separator }, braceStart, braceEnd); }// w w w . ja v a 2 s . c o m public static String[] splitWithBreakingBrace(String str, char[] separators, char braceStart, char braceEnd) { List<String> strs = new ArrayList<String>(); StringBuffer sb = new StringBuffer(); int index = 0; String sepStr = new String(separators); while (index < str.length()) { char ch = str.charAt(index); if (sepStr.indexOf(ch) >= 0) { strs.add(sb.toString()); sb = new StringBuffer(); } else { if (ch == braceStart) { sb.append(ch); index++; while (index < str.length()) { ch = str.charAt(index); sb.append(ch); if (ch == braceEnd) { break; } index++; } } else { sb.append(ch); } } index++; } String endStr = sb.toString(); if (endStr.length() > 0) { strs.add(endStr); } return strs.toArray(new String[] {}); } }