dap4/d4core/src/main/java/dap4/core/dmr/parser/ParseUtil.java
static public List<String>
    collectValues(String text)
        throws ParseException
    {
        List<String> values = new ArrayList<String>();
        StringBuffer buf = new StringBuffer();
        text = text.trim() + '\0';
        int i = 0;
        for(; ; ) {
            char c = text.charAt(i++);
            if(c == '\0') break; // eos
            if(c <= ' ' || c == 127) // whitespace
                continue;
            if(c == '\'') {// collect char constant
                c = text.charAt(i++);
                if(c == '\0')
                    throw new ParseException("Malformed char constant: no final '''");
                else if(i >= 128)
                    throw new ParseException("Illegal char constant: " + (int) c);
                buf.append(c);
                values.add(buf.toString());
                buf.setLength(0);
            } else if(c == '"') { // collect quoted string
                for(; ; ) {
                    c = text.charAt(i++);
                    if(c == '\0') {
                        i--;
                        break;
                    }
                    if(c == '\\') {
                        c = text.charAt(i++);
                    } else if(c == '"') break;
                    buf.append(c);
                }
                if(c == '\0')
                    throw new ParseException("Malformed string: no final '\"'");
                values.add(buf.toString());
                buf.setLength(0);
            } else {// collect upto next whitespace or eos
                do {
                    if(c == '\\') {
                        c = text.charAt(i++);
                    }
                    buf.append(c);
                    c = text.charAt(i++);
                } while(c > ' ' && c != 127);
                values.add(buf.toString());
                buf.setLength(0);
                if(c == 0) i--; // So we never move past the trailing eol
            }
        }
        return values;
    }
static public List<String>
    collectValues(String text)
        throws ParseException
    {
        List<String> values = new ArrayList<String>();
        StringBuffer buf = new StringBuffer();
        text = text.trim() + '\0';
        int i = 0;
        for(; ; ) {
            char c = text.charAt(i++);
            if(c == '\0') break; // eos
            if(c <= ' ' || c == 127) // whitespace
                continue;
            if(c == '\'') {// collect char constant
                c = text.charAt(i++);
                if(c == '\0')
                    throw new ParseException("Malformed char constant: no final '''");
                else if(i >= 128)
                    throw new ParseException("Illegal char constant: " + (int) c);
                buf.append(c);
                values.add(buf.toString());
                buf.setLength(0);
            } else if(c == '"') { // collect quoted string
                for(; ; ) {
                    c = text.charAt(i++);
                    if(c == '\0') {
                        i--;
                        break;
                    }
                    if(c == '\\') {
                        c = text.charAt(i++);
                    } else if(c == '"') break;
                    buf.append(c);
                }
                if(c == '\0')
                    throw new ParseException("Malformed string: no final '\"'");
                values.add(buf.toString());
                buf.setLength(0);
            } else {// collect upto next whitespace or eos
                do {
                    if(c == '\\') {
                        c = text.charAt(i++);
                    }
                    buf.append(c);
                    c = text.charAt(i++);
                } while(c > ' ' && c != 127);
                values.add(buf.toString());
                buf.setLength(0);
                if(c == 0) i--; // So we never move past the trailing eol
            }
        }
        return values;
    }
static public List < String > collectValues ( String text ) throws ParseException { List < String > values = new ArrayList < String > ( ) ; StringBuffer buf = new StringBuffer ( ) ; text = text . trim ( ) + ' ' ; int i = 0 ; for ( ; ; ) { char c = text . charAt ( i ++ ) ; if ( c == ' ' ) break ; // eos if ( c <= ' ' || c == 127 ) // whitespace continue ; if ( c == ' ' ) { // collect char constant c = text . charAt ( i ++ ) ; if ( c == ' ' ) throw new ParseException ( "Malformed char constant: no final '''" ) ; else if ( i >= 128 ) throw new ParseException ( "Illegal char constant: " + ( int ) c ) ; buf . append ( c ) ; values . add ( buf . toString ( ) ) ; buf . setLength ( 0 ) ; } else if ( c == ' ' ) { // collect quoted string for ( ; ; ) { c = text . charAt ( i ++ ) ; if ( c == ' ' ) { i -- ; break ; } if ( c == ' ' ) { c = text . charAt ( i ++ ) ; } else if ( c == ' ' ) break ; buf . append ( c ) ; } if ( c == ' ' ) throw new ParseException ( "Malformed string: no final '\"'" ) ; values . add ( buf . toString ( ) ) ; buf . setLength ( 0 ) ; } else { // collect upto next whitespace or eos do { if ( c == ' ' ) { c = text . charAt ( i ++ ) ; } buf . append ( c ) ; c = text . charAt ( i ++ ) ; } while ( c > ' ' && c != 127 ) ; values . add ( buf . toString ( ) ) ; buf . setLength ( 0 ) ; if ( c == 0 ) i -- ; // So we never move past the trailing eol } } return values ; }
Split a <Value>...</Value> into its component strings.
Generally, type checking is not performed. String quotes
are obeyed and backslash escapes are removed.
Split a <Value > ... < / Value > into its component strings . Generally type checking is not performed . String quotes are obeyed and backslash escapes are removed .