1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar.cpptasks.parser;
21
22 import java.io.IOException;
23 import java.io.Reader;
24
25
26
27
28
29
30 public abstract class AbstractParser {
31
32
33
34
35 protected AbstractParser() {
36 }
37
38 protected abstract void addFilename(String filename);
39
40 public abstract AbstractParserState getNewLineState();
41
42 protected void parse(final Reader reader) throws IOException {
43 final char[] buf = new char[4096];
44 final AbstractParserState newLineState = getNewLineState();
45 AbstractParserState state = newLineState;
46 int charsRead = -1;
47 do {
48 charsRead = reader.read(buf, 0, buf.length);
49 if (state == null) {
50 for (int i = 0; i < charsRead; i++) {
51 if (buf[i] == '\n') {
52 state = newLineState;
53 break;
54 }
55 }
56 }
57 if (state != null) {
58 for (int i = 0; i < charsRead; i++) {
59 state = state.consume(buf[i]);
60
61
62
63 if (state == null) {
64 for (; i < charsRead; i++) {
65 if (buf[i] == '\n') {
66 state = newLineState;
67 break;
68 }
69 }
70 }
71 }
72 }
73 } while (charsRead >= 0);
74 }
75 }