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 |
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;
}
}
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 16:37:09 CET 2024
Total time taken to generate the page: 0.01431 seconds
|