Java String Extract extractArrayData(String input, StringBuilder output)

Here you can find the source of extractArrayData(String input, StringBuilder output)

Description

extract Array Data

License

Apache License

Declaration

public static Map<String, StringBuilder> extractArrayData(String input, StringBuilder output) 

Method Source Code

//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;
    }
}

Related

  1. extract(final String grammarString, final char separator)
  2. extract(Properties p, String prefix)
  3. extract_tokens(String in_string, String delimiters)
  4. extractAggregationPrimKeysFromSql( final String sql)
  5. extractArrayData(String input, StringBuilder output)
  6. extractCharNgram(String content, int n)
  7. extractCommands(String fileContents)
  8. extractData(String message)
  9. extractField(int position, String regex, String source)