* Parses the access log string.
*/
private ArrayList<Segment> parseFormat(String format)
{
ArrayList<Segment> segments = new ArrayList<Segment>();
CharBuffer cb = new CharBuffer();
int i = 0;
while (i < _format.length()) {
char ch = _format.charAt(i++);
if (ch != '%' || i >= _format.length()) {
cb.append((char) ch);
continue;
}
String arg = null;
ch = _format.charAt(i++);
if (ch == '>')
ch = _format.charAt(i++);
else if (ch == '{') {
if (cb.length() > 0)
segments.add(new Segment(this, Segment.TEXT, cb.toString()));
cb.clear();
while (i < _format.length() && _format.charAt(i++) != '}')
cb.append(_format.charAt(i - 1));
arg = cb.toString();
cb.clear();
ch = _format.charAt(i++);
}
switch (ch) {
case 'b': case 'c':
case 'h': case 'i': case 'l': case 'n':
case 'r': case 's':
case 'T': case 'D': case 'o':
case 'u': case 'U':
case 'v': case 'S':
if (cb.length() > 0)
segments.add(new Segment(this, Segment.TEXT, cb.toString()));
cb.clear();
segments.add(new Segment(this, ch, arg));
break;
case 't':
if (cb.length() > 0)
segments.add(new Segment(this, Segment.TEXT, cb.toString()));
cb.clear();
if (arg != null)
_timeFormat = arg;
segments.add(new Segment(this, ch, arg));
break;
default:
cb.append('%');
i--;
break;
}
}
cb.append(CauchoSystem.getNewlineString());
segments.add(new Segment(this, Segment.TEXT, cb.toString()));
return segments;
}