protected List<VariableSet> findVariableSets(final ParserData parserData, final String input, final char startDelim,
            final char endDelim) {
        final StringBuilder varLine = new StringBuilder(input);
        final List<VariableSet> retValue = new ArrayList<VariableSet>();
        int startPos = 0;
        VariableSet set = ProcessorUtilities.findVariableSet(input, startDelim, endDelim, startPos);

        while (set != null && set.getContents() != null) {
            /*
             * Check if we've found the end of a set. If we have add the set to the
             * list and try and see if another set exists. If not then get the next line
             * in the content spec and keep processing the set until the end of the set
             * is found or the end of the content spec.
             */
            if (set.getEndPos() != null) {
                retValue.add(set);

                final String nextLine = parserData.getLines().peek();
                startPos = set.getEndPos() + 1;
                set = ProcessorUtilities.findVariableSet(varLine.toString(), startDelim, endDelim, startPos);

                /*
                 * If the next set and/or its contents are empty then it means we found all the sets
                 * for the input line. However the next line in the content spec maybe a continuation
                 * but we couldn't find it originally because of a missing separator. So peek at the next
                 * line and see if it's a continuation (ie another relationship) and if it is then add the
                 * line and continue to find sets.
                 */
                if ((set == null || set.getContents() == null) && (nextLine != null && nextLine.trim().toUpperCase(Locale.ENGLISH).matches(
                        "^\\" + startDelim + "[ ]*(R|L|P|T|B).*"))) {
                    final String line = parserData.getLines().poll();
                    parserData.setLineCount(parserData.getLineCount() + 1);

                    if (line != null) {
                        varLine.append("\n").append(line);

                        set = ProcessorUtilities.findVariableSet(varLine.toString(), startDelim, endDelim, startPos);
                    }
                }
            } else {
                final String line = parserData.getLines().poll();
                parserData.setLineCount(parserData.getLineCount() + 1);

                if (line != null) {
                    varLine.append("\n").append(line);

                    set = ProcessorUtilities.findVariableSet(varLine.toString(), startDelim, endDelim, startPos);
                } else {
                    retValue.add(set);
                    break;
                }
            }
        }
        return retValue;
    }
protected List < VariableSet > findVariableSets ( final ParserData parserData , final String input , final char startDelim , final char endDelim ) { final StringBuilder varLine = new StringBuilder ( input ) ; final List < VariableSet > retValue = new ArrayList < VariableSet > ( ) ; int startPos = 0 ; VariableSet set = ProcessorUtilities . findVariableSet ( input , startDelim , endDelim , startPos ) ; while ( set != null && set . getContents ( ) != null ) { if ( set . getEndPos ( ) != null ) { retValue . add ( set ) ; final String nextLine = parserData . getLines ( ) . peek ( ) ; startPos = set . getEndPos ( ) + 1 ; set = ProcessorUtilities . findVariableSet ( varLine . toString ( ) , startDelim , endDelim , startPos ) ; if ( ( set == null || set . getContents ( ) == null ) && ( nextLine != null && nextLine . trim ( ) . toUpperCase ( Locale . ENGLISH ) . matches ( "^\\" + startDelim + "[ ]*(R|L|P|T|B).*" ) ) ) { final String line = parserData . getLines ( ) . poll ( ) ; parserData . setLineCount ( parserData . getLineCount ( ) + 1 ) ; if ( line != null ) { varLine . append ( "\n" ) . append ( line ) ; set = ProcessorUtilities . findVariableSet ( varLine . toString ( ) , startDelim , endDelim , startPos ) ; } } } else { final String line = parserData . getLines ( ) . poll ( ) ; parserData . setLineCount ( parserData . getLineCount ( ) + 1 ) ; if ( line != null ) { varLine . append ( "\n" ) . append ( line ) ; set = ProcessorUtilities . findVariableSet ( varLine . toString ( ) , startDelim , endDelim , startPos ) ; } else { retValue . add ( set ) ; break ; } } } return retValue ; }
Finds a List of variable sets within a string. If the end of a set
can't be determined then it will continue to parse the following
lines until the end is found.

@param parserData
@param input      The string to find the sets in.
@param startDelim The starting character of the set.
@param endDelim   The ending character of the set.
@return A list of VariableSets that contain the contents of each set
and the start and end position of the set.