Here you can find the source of extractArrayData(String input, StringBuilder output)
public static Map<String, String> extractArrayData(String input, StringBuilder output)
//package com.java2s; /*/*w ww .ja v a2 s. c o m*/ * Portions Copyright 2013-2015 Technology Concepts & Design, Inc * Portions Copyright 2015-2017 ZomboDB, LLC * * 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, String> extractArrayData(String input, StringBuilder output) { Map<String, String> arrayData = new HashMap<>(); boolean inArrayData = false; int arrStart = -1; int blockStart = -1; for (int i = 0, many = input.length(); i < many; i++) { char ch = input.charAt(i); char nextChar = i < many - 1 ? input.charAt(i + 1) : 0; switch (ch) { case '[': if (nextChar == '[' && !inArrayData) { output.append(input.substring(blockStart, i)); blockStart = -1; inArrayData = true; i++; arrStart = i + 1; // plus one to skip the double brackets at start of array: [[ } break; case ']': if (nextChar == ']' && inArrayData) { String arrayName = "$" + arrayData.size(); arrayData.put(arrayName, input.substring(arrStart, i)); if (blockStart != -1) { output.append(input.substring(blockStart, i)); blockStart = -1; } output.append("[[").append(arrayName).append("]]"); inArrayData = false; i++; } break; default: if (!inArrayData && blockStart == -1) blockStart = i; break; } } if (blockStart != -1) output.append(input.substring(blockStart, input.length())); return arrayData; } }