MCPcopy Create free account
hub / github.com/antlr/codebuff / add

Method add

corpus/java/training/guava/io/LineBuffer.java:50–84  ·  view source on GitHub ↗

Process additional characters from the stream. When a line separator is found the contents of the line and the line separator itself are passed to the abstract #handleLine method. @param cbuf the character buffer to process @param off the offset into the buffer @param len the number of char

(char[] cbuf, int off, int len)

Source from the content-addressed store, hash-verified

48 * @see #finish
49 */
50 protected void add(char[] cbuf, int off, int len) throws IOException {
51 int pos = off;
52 if (sawReturn && len > 0) {
53 // Last call to add ended with a CR; we can handle the line now.
54 if (finishLine(cbuf[pos] == '\n')) {
55 pos++;
56 }
57 }
58
59 int start = pos;
60 for (int end = off + len; pos < end; pos++) {
61 switch (cbuf[pos]) {
62 case '\r':
63 line.append(cbuf, start, pos - start);
64 sawReturn = true;
65 if (pos + 1 < end) {
66 if (finishLine(cbuf[pos + 1] == '\n')) {
67 pos++;
68 }
69 }
70 start = pos + 1;
71 break;
72
73 case '\n':
74 line.append(cbuf, start, pos - start);
75 finishLine(true);
76 start = pos + 1;
77 break;
78
79 default:
80 // do nothing
81 }
82 }
83 line.append(cbuf, start, off + len - start);
84 }
85
86 /** Called when a line is complete. */
87 @CanIgnoreReturnValue

Callers

nothing calls this directly

Calls 2

finishLineMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected