Java XML Parse String parse(String line)

Here you can find the source of parse(String line)

Description

parse

License

LGPL

Declaration

public static String[] parse(String line) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

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

public class Main {
    public static String[] parse(String line) {
        if (line == null || line.length() == 0)
            return new String[0];
        List<String> out = new ArrayList<String>();
        String rest = line.trim();
        int lastpos = 0;
        while (rest.length() > 0) {
            if (rest.length() < 28) {
                out.add(rest);/*from   w  ww . ja v a  2s. c o m*/
                rest = "";
                continue;
            }
            int pos = rest.indexOf(' ', lastpos + 1);
            boolean zulang = (pos > 28) || pos == -1;
            // 1. Fall: Durchgehender Text mit mehr als 27 Zeichen ohne Space
            if (lastpos == 0 && zulang) {
                out.add(rest.substring(0, 27));
                rest = rest.substring(27).trim();
                continue;
            }
            // 2. Fall Wenn der String immer noch passt, weitersuchen
            if (!zulang) {
                lastpos = pos;
                continue;
            }
            // Bis zum Space aus dem vorherigen Schritt den String herausschneiden
            out.add(rest.substring(0, lastpos));
            rest = rest.substring(lastpos + 1).trim();
            lastpos = 0;
        }
        return out.toArray(new String[0]);
    }
}

Related

  1. parse(final String line)
  2. parse(final String xmlContent)
  3. parse(String input)
  4. parse(String input, char delim, char esc)
  5. parse(String line)
  6. parse(String s)
  7. parse(String text)
  8. parse(String xml)
  9. parse(String xml)