7 void ArrayCopy(
T* src,
int src_offset,
T*
dest,
int dest_offset,
int len) {
8 for (
int i = 0; i < len; i++) {
9 dest[dest_offset + i] = src[src_offset + i];
17 size_t count = str_.copy(bufptr + offset, len > max_ ? max_ : len, cur_);
22 virtual ~StringReaderStream() {}
37 int startcolumn,
int buffersize) {
38 StringReaderStream *
stream =
new StringReaderStream(str);
39 ReInit(stream, startline, startcolumn, buffersize);
44 int startcolumn,
int buffersize) {
53 available = bufsize = buffersize;
55 bufline =
new int[buffersize];
56 bufcolumn =
new int[buffersize];
59 inputStream = input_stream;
61 prevCharIsLF = prevCharIsCR =
false;
62 tokenBegin = inBuf = maxNextCharInd = 0;
67 void CharStream::DeleteBuffers() {
73 void CharStream::adjustBeginLineColumn(
int newLine,
int newCol) {
74 int start = tokenBegin;
77 if (bufpos >= tokenBegin) {
78 len = bufpos - tokenBegin + inBuf + 1;
80 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
83 int i = 0, j = 0,
k = 0;
84 int nextColDiff = 0, columnDiff = 0;
86 while (i < len && bufline[j = start % bufsize] ==
87 bufline[
k = (start + 1) % bufsize]) {
89 nextColDiff = columnDiff + bufcolumn[
k] - bufcolumn[j];
90 bufcolumn[j] = newCol + columnDiff;
91 columnDiff = nextColDiff;
97 bufline[j] = newLine++;
98 bufcolumn[j] = newCol + columnDiff;
101 if (bufline[j = start % bufsize] != bufline[(start + 1) % bufsize])
102 bufline[j] = newLine++;
113 void CharStream::ExpandBuff(
bool wrapAround) {
115 int *newbufline =
new int[bufsize + 2048];
116 int *newbufcolumn =
new int[bufsize + 2048];
119 ArrayCopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
120 ArrayCopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
121 ArrayCopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
122 ArrayCopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
123 ArrayCopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
124 ArrayCopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
125 bufpos += (bufsize - tokenBegin);
127 ArrayCopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
128 ArrayCopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
129 ArrayCopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
130 bufpos -= tokenBegin;
133 maxNextCharInd = bufpos;
136 bufline = newbufline;
137 bufcolumn = newbufcolumn;
143 void CharStream::FillBuff() {
144 if (maxNextCharInd == available) {
145 if (available == bufsize) {
146 if (tokenBegin > 2048) {
147 bufpos = maxNextCharInd = 0;
148 available = tokenBegin;
149 }
else if (tokenBegin < 0) {
150 bufpos = maxNextCharInd = 0;
154 }
else if (available > tokenBegin) {
156 }
else if ((tokenBegin - available) < 2048) {
159 available = tokenBegin;
163 int i = inputStream->read(buffer, maxNextCharInd, available - maxNextCharInd);
169 if (tokenBegin == -1) {
178 prevCharIsLF =
false;
181 }
else if (prevCharIsCR) {
182 prevCharIsCR =
false;
206 bufline[bufpos] =
line;
207 bufcolumn[bufpos] =
column;
#define JAVACC_STRING_TYPE
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
virtual size_t read(JAVACC_CHAR_TYPE *, int, size_t)
virtual bool endOfInput()
void line(double t, double *p, double &x, double &y, double &z)
std::vector< std::string > column