Here you can find the source of splitWithoutEscaped(String str, String sep)
public static String[] splitWithoutEscaped(String str, String sep)
//package com.java2s; /* /* w w w . j ava 2 s.co m*/ * ============================================================= * Copyright (C) 2007-2011 Edgenius (http://www.edgenius.com) * ============================================================= * License Information: http://www.edgenius.com/licensing/edgenius/2.0/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2.0 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * http://www.gnu.org/licenses/gpl.txt * * **************************************************************** */ import java.util.ArrayList; import java.util.List; public class Main { /** * @return */ public static String[] splitWithoutEscaped(String str, String sep) { if (str == null || "".equals(str)) return new String[] { "" }; List<String> list = new ArrayList<String>(); int end = indexSeparatorWithoutEscaped(str, sep); while (end != -1) { list.add(str.substring(0, end)); str = str.substring(end + sep.length()); end = indexSeparatorWithoutEscaped(str, sep); } list.add(str); return list.toArray(new String[list.size()]); } public static boolean equals(String str1, String str2) { return str1 == null ? str2 == null : str1.equals(str2); } /** * find char index of sep, but not start with odd number '\' */ public static int indexSeparatorWithoutEscaped(String str, String sep) { int start = 0; int idx; boolean found = false; do { idx = indexOf(str, sep, start); if (idx == 0) { //line of start found = true; break; } if (idx != -1) { int count = 0; for (int reIdx = idx - 1; reIdx >= 0; reIdx--) { if ((str.charAt(reIdx) != '\\')) { break; } count++; } if (count % 2 == 0) { found = true; break; } } start = idx + 1; } while (idx != -1); return found ? idx : -1; } public static int indexOf(String str, String searchChar, int startPos) { if (isEmpty(str)) { return -1; } return str.indexOf(searchChar, startPos); } public static boolean isEmpty(String str) { return str == null || str.length() == 0; } }