Here you can find the source of splitHelperName(String name)
Parameter | Description |
---|---|
name | a parameter |
static Iterator<String> splitHelperName(String name)
//package com.java2s; /*/*w ww .ja v a 2 s. com*/ * Copyright 2013 Martin Kouba * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { /** * This implementation is quite naive and should be possibly rewritten. * * @param name * @return */ static Iterator<String> splitHelperName(String name) { boolean literal = false; boolean whitespace = false; List<String> parts = new ArrayList<String>(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < name.length(); i++) { if (name.charAt(i) == ' ') { if (!whitespace) { if (!literal) { parts.add(buffer.toString()); buffer = new StringBuilder(); whitespace = true; } else { buffer.append(name.charAt(i)); } } } else { if (name.charAt(i) == '"') { if (literal) { literal = false; } else { literal = true; } } whitespace = false; buffer.append(name.charAt(i)); } } if (buffer.length() > 0) { parts.add(buffer.toString()); } return parts.iterator(); } }