01: /*
02: * This is free software, licensed under the Gnu Public License (GPL)
03: * get a copy from <http://www.gnu.org/licenses/gpl.html>
04: *
05: * author: Henner Zeller <H.Zeller@acm.org>
06: */
07: package henplus.importparser;
08:
09: public final class QuotedStringParser extends TypeParser {
10: private final int _field;
11:
12: public QuotedStringParser(int field) {
13: _field = field;
14: }
15:
16: /**
17: * parse the value from the character buffer starting from the given
18: * offset and with the given length. Store the result in the
19: * ValueRecipient.
20: */
21: public void parse(char[] buffer, int offset, int len,
22: ValueRecipient recipient) throws Exception {
23: final char start = buffer[offset];
24: final char end = buffer[offset + len - 1];
25: if (len >= 2 && (start == '\'' || start == '"') && start == end) {
26: offset += 1;
27: len -= 2;
28: }
29: recipient.setString(_field, new String(buffer, offset, len));
30: }
31: }
|