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 » Do you need a read character literal in CParser?
Do you need a read character literal in CParser? [message #44722] Fri, 05 June 2015 10:50 Go to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
I am using one in my code. If you need it, I could clean it up and make it full featured. Right now it is a bit bare bones and not necessarily pretty:

uint32 Parser::ReadChar() {
	if (term[0] != '\'')
		return -1;
	if (term[1] == '\\') {
		term += 2;
		uint32 c = -1;
		if (*term == 't') {
			c = '\t';
			term += 1;
		}
		else if (*term == 'n') {
			c = '\n';
			term += 1;
		}
		else if (*term == 'r') {
			c = '\r';	
			term += 1;
		}
		else if (*term == 'u') {
			term += 1;
			c = 0;
			for(int i = 0; i < 6; i++) {				
				uint32 cc = ctoi(*term);		
				if(cc < 0 || cc >= 16)
					return -1;
				c = 16 * c + cc;				
				term++;
			}
		}
		else
			return -1;
		if (*term != '\'')					
			return -1;
		term += 1;			
		Spaces();
		return c;
	}
	else {
		term += 1;
		uint32 c = (byte)*term;
		if (c == 0)
			return -1;
		if (c < 0x80)			 
			term += 1;
		else if (c < 0xC0)
			return -1;
		else if (c < 0xE0) {
			c = ((c - 0xC0) << 6) + (byte)term[1] - 0x80;
			term += 2;
		}
		else if (c < 0xF0) {
			c = ((c - 0xE0) << 12) + (((byte)term[1] - 0x80) << 6) + (byte)term[2] - 0x80;
			term += 3;
		}
		if (*term != '\'')					
			return -1;			
		term += 1;
		Spaces();
		return c;
	}
}
Re: Do you need a read character literal in CParser? [message #44723 is a reply to message #44722] Fri, 05 June 2015 10:59 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I have to say I have always cheated here, using

CParser::ReadString('\'');

(but if would have checked that the result length is exactly 1, it would not be that much cheating...)
Previous Topic: [c++11] Problem with executing callback with Vector
Next Topic: Trobule with Algo.h in the U++ Core
Goto Forum:
  


Current Time: Fri Mar 29 16:37:09 CET 2024

Total time taken to generate the page: 0.01431 seconds