Java String Split splitObjectString(String str)

Here you can find the source of splitObjectString(String str)

Description

split Object String

License

Open Source License

Declaration

public static String[] splitObjectString(String str) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String[] splitObjectString(String str) {
        List<String> ret2 = new ArrayList<String>();
        int i;/*from   w ww .j a va2 s.  c o m*/
        char chr;
        int ignoreValue = 0;
        StringBuilder strBuf = new StringBuilder();
        boolean ignStr = false;
        for (i = 0; i < str.length(); i++) {
            chr = str.charAt(i);

            if (chr == '"') {
                ignStr = !ignStr;
            }

            if (chr == '[' || chr == '{') {
                ignoreValue++;
            }
            if (chr == ']' || chr == '}') {
                ignoreValue--;
            }
            if (ignoreValue == 0 && !ignStr && (chr == ':' || chr == ',')) {
                ret2.add(strBuf.toString());
                strBuf = new StringBuilder();
            } else {
                if ((int) chr != 0x20) { // ignore whitespaces TODO: ignore tabs & newlines 
                    strBuf = strBuf.append(chr);
                }
            }
        }
        ret2.add(strBuf.toString());
        return ret2.toArray(new String[0]);
    }
}

Related

  1. splitMacros(String s)
  2. splitManagedBean(String el)
  3. splitMultiMessageString( String multiMessageString, String messageSplitter)
  4. splitName(String name)
  5. splitNames(final String string)
  6. splitOgnl(String ognl)
  7. splitOn(String toSplit, String splitter)
  8. splitOnNoWiki(String s)
  9. splitOnTokens(String text)