* @param text a Chset representing a character in a quoted pair.
* @param qtext a Chset representing a character that need not be quoted.
*/
static Parser<MimeContentHeader> createParameterParser(
Chset text, Chset qtext) {
Chset special = new Chset(TSPECIAL_CHARS);
Chset token = Chset.difference(Chset.difference(Chset.ANYCHAR,
Chset.WHITESPACE),
special);
// TODO(spencer): handling of quoted pairs is not correct in this parser.
// They are simply left as \CHAR. Changing this now, however, would cause
// existing servers to get different (possibly incompatible) inputs.
// See ChunkHeader.java for a correct implementation.
Parser<MimeContentHeader> quotedPair =
Parser.sequence(new Chset('\\'), text);
Parser<MimeContentHeader> quotedString =
Parser.alternative(qtext, quotedPair);
quotedString = quotedString.star().action(new ParamValueAction());
quotedString = Parser.sequence(new Chset('"'), quotedString);
quotedString = Parser.sequence(quotedString, new Chset('"'));
Parser<MimeContentHeader> name =
token.plus().action(new ParamNameAction());
Parser<MimeContentHeader> value =
token.plus().action(new ParamValueAction());
value = Parser.alternative(value, quotedString);
Parser<Object> wsp = Chset.WHITESPACE.star();
Parser<MimeContentHeader> parameters =
Parser.sequence(wsp, new Chset(';'));
parameters = Parser.sequence(parameters, wsp);
parameters = Parser.sequence(parameters, name);
parameters = Parser.sequence(parameters, wsp);
parameters = Parser.sequence(parameters, new Chset('='));
parameters = Parser.sequence(parameters, wsp);
parameters = Parser.sequence(parameters, value);
return parameters.star();
}