Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [solved] CParser GetColumn bugfix
[solved] CParser GetColumn bugfix [message #52555] Tue, 22 October 2019 11:24 Go to previous message
cbpporter is currently offline  cbpporter
Messages: 1401
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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Long time running program and Vector
Next Topic: IsSpace() should be true on non breaking space
Goto Forum:
  


Current Time: Tue Apr 23 23:28:37 CEST 2024

Total time taken to generate the page: 0.02990 seconds