예제 #1
0
 private List<Directive> parseDirectives(final StringBuilder buffer, final ParserCursor cursor) {
   List<Directive> elements = new ArrayList<Directive>();
   while (!cursor.atEnd()) {
     Directive element = parseDirective(buffer, cursor);
     if (!(element.getName().length() == 0 && element.getValue() == null)) {
       elements.add(element);
     }
   }
   return elements;
 }
예제 #2
0
  private List<Parameter> parseParameters(final StringBuilder buffer, final ParserCursor cursor) {

    if (buffer == null) {
      throw new IllegalArgumentException("Char array buffer may not be null");
    }
    if (cursor == null) {
      throw new IllegalArgumentException("Parser cursor may not be null");
    }

    int pos = cursor.getPos();
    int indexTo = cursor.getUpperBound();

    while (pos < indexTo) {
      char ch = buffer.charAt(pos);
      if (isWhitespace(ch)) {
        pos++;
      } else {
        break;
      }
    }
    cursor.updatePos(pos);
    if (cursor.atEnd()) {
      return Collections.emptyList();
    }

    List<Parameter> params = new ArrayList<Parameter>();
    while (!cursor.atEnd()) {
      params.add(parseParameter(buffer, cursor, ALL_DELIMITERS));
      char ch = buffer.charAt(cursor.getPos() - 1);
      if (ch == ELEM_DELIMITER) {
        break;
      }
    }

    return params;
  }
예제 #3
0
 private Directive parseDirective(final StringBuilder buffer, final ParserCursor cursor) {
   Parameter parameter = parseParameter(buffer, cursor, ALL_DELIMITERS);
   List<Parameter> params = Collections.emptyList();
   if (!cursor.atEnd()) {
     char ch = buffer.charAt(cursor.getPos() - 1);
     if (ch != ELEM_DELIMITER) {
       params = parseParameters(buffer, cursor);
     }
   }
   if (parameter instanceof QuotedParameter) {
     return createDirective(
         parameter.getName(), ((QuotedParameter) parameter).getQuotedValue(), params);
   }
   return createDirective(parameter.getName(), parameter.getValue(), params);
 }