Here you can find the source of splitAndKeepEscapedSpaces(String string, boolean preserveEscapes, Collection
private static void splitAndKeepEscapedSpaces(String string, boolean preserveEscapes, Collection<String> into)
//package com.java2s; /*//from w ww. j a v a 2s . co m * Copyright (c) 2002-2016 "Neo Technology," * Network Engine for Objects in Lund AB [http://neotechnology.com] * * This file is part of Neo4j. * * Neo4j is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Collection; public class Main { private static void splitAndKeepEscapedSpaces(String string, boolean preserveEscapes, Collection<String> into) { StringBuilder current = new StringBuilder(); for (int i = 0; i < string.length(); i++) { char ch = string.charAt(i); if (ch == ' ') { boolean isGluedSpace = i > 0 && string.charAt(i - 1) == '\\'; if (!isGluedSpace) { into.add(current.toString()); current = new StringBuilder(); continue; } } if (preserveEscapes || ch != '\\') { current.append(ch); } } if (current.length() > 0) { into.add(current.toString()); } } }