Java XML Parse String parse(String input, char delim, char esc)

Here you can find the source of parse(String input, char delim, char esc)

Description

parse

License

Open Source License

Declaration

public static List<String> parse(String input, char delim, char esc) 

Method Source Code


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

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

public class Main {
    public static List<String> parse(String input, char delim, char esc) {
        assert delim != esc : "Delimiter is the same as escaping character: " + delim;
        List<String> ret = new ArrayList<String>();

        StringBuilder cur = new StringBuilder();
        boolean escflag = false;
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (c == esc) {
                if (escflag) {
                    cur.append(c);//from   w  w  w.  ja v  a2 s  .c  om
                    escflag = false;
                } else {
                    escflag = true;
                }
            } else if (c == delim) {
                if (escflag) {
                    cur.append(c);
                } else {
                    ret.add(cur.toString());
                    cur = new StringBuilder();
                }
                escflag = false;
            } else {
                cur.append(c);
                escflag = false;
            }
        }
        if (cur.length() > 0) {
            ret.add(cur.toString());
        }

        return ret;
    }
}

Related

  1. parse(final String content)
  2. parse(final String line)
  3. parse(final String xmlContent)
  4. parse(String input)
  5. parse(String line)
  6. parse(String line)
  7. parse(String s)
  8. parse(String text)