Here you can find the source of extractArrayData(String input, StringBuilder output)
public static Map<String, StringBuilder> extractArrayData(String input, StringBuilder output)
//package com.java2s; /*//from ww w . ja v a2 s. co m * Copyright 2013-2015 Technology Concepts & Design, Inc * * 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.*; public class Main { public static Map<String, StringBuilder> extractArrayData(String input, StringBuilder output) { Map<String, StringBuilder> arrayData = new HashMap<>(); StringBuilder currentArray = null; String currentArrayName = null; boolean inArrayData = false; char nextChar; for (int i = 0, many = input.length(); i < many; i++) { char ch = Character.toLowerCase(input.charAt(i)); nextChar = i < many - 1 ? input.charAt(i + 1) : 0; switch (ch) { case '[': if (nextChar == '[' && !inArrayData) { inArrayData = true; currentArrayName = "$" + arrayData.size(); currentArray = new StringBuilder(); i++; } break; case ']': if (nextChar == ']' && inArrayData) { arrayData.put(currentArrayName, currentArray); output.append("[[").append(currentArrayName).append("]"); inArrayData = false; i++; } break; } if (inArrayData) currentArray.append(ch); else output.append(ch); } return arrayData; } }