|
|
Home » U++ Library support » U++ Core » [solved] CParser GetColumn bugfix
[solved] CParser GetColumn bugfix [message #52555] |
Tue, 22 October 2019 11:24  |
cbpporter
Messages: 1427 Registered: September 2007
|
Ultimate Contributor |
|
|
Calling GetColumn when the internal CParser::lineptr points to another line (which is rare in practice, but possible, can provide test case but don't think its needed) does not handle new-lines.
Fix:
int CParser::Pos::GetColumn(int tabsize) const
{
int pos = 1;
for(const char *s = lineptr; s < ptr; s++) {
if(*s == CParser::LINEINFO_ESC) {
s++;
while(s < ptr && *s != CParser::LINEINFO_ESC)
if(*s++ == '\3')
pos = atoi(s);
}
else
if(*s == '\n')
pos = 0; // FIX
else
if(*s == '\t')
pos = (pos + tabsize - 1) / tabsize * tabsize + 1;
else
pos++;
}
return pos;
}
Additionally, I'm using CParser to parse more complicated input where simple SkipSpaces(true) doesn't works so I'm manually skipping whitespaces, but comments are still automatic.
I added the following overload to handle this:
CParser::CParser(const char *ptr, bool skipSpaces)
: term(ptr), wspc(ptr), lineptr(ptr)
{
line = 1;
skipspaces = skipSpaces;
skipcomments = true;
nestcomments = false;
uescape = true;
if (skipSpaces)
Spaces();
}
I need a solution that support hundreds of CParser created on the spot for random code jumping that do not eat whitespaces since they are syntactically significant.
[Updated on: Thu, 31 October 2019 11:34] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri May 09 12:02:39 CEST 2025
Total time taken to generate the page: 0.04012 seconds
|
|
|