Handle Unicode characters in input.

This commit is contained in:
Michael Jumper 2013-10-03 15:38:22 -07:00
parent 1915b107ea
commit e66a64be26

View File

@ -95,6 +95,7 @@ int guac_instruction_append(guac_instruction* instr,
/* If period, switch to parsing content */ /* If period, switch to parsing content */
else if (c == '.') { else if (c == '.') {
instr->__element_length = parsed_length; instr->__element_length = parsed_length;
instr->__elementv[instr->__elementc++] = char_buffer;
instr->state = GUAC_INSTRUCTION_PARSE_CONTENT; instr->state = GUAC_INSTRUCTION_PARSE_CONTENT;
break; break;
} }
@ -118,35 +119,50 @@ int guac_instruction_append(guac_instruction* instr,
/* Parse element content */ /* Parse element content */
if (instr->state == GUAC_INSTRUCTION_PARSE_CONTENT) { if (instr->state == GUAC_INSTRUCTION_PARSE_CONTENT) {
/* If enough data given, finish element */ while (bytes_parsed < length && instr->__element_length >= 0) {
if (length - bytes_parsed > instr->__element_length) {
/* Pull terminator */ /* Get length of current character */
char terminator = char_buffer[instr->__element_length]; char c = *char_buffer;
int char_length = guac_utf8_charsize((unsigned char) c);
/* Store reference to string within elementv */ /* If full character not present in buffer, stop now */
instr->__elementv[instr->__elementc++] = char_buffer; if (char_length + bytes_parsed > length)
char_buffer[instr->__element_length] = '\0'; break;
bytes_parsed += instr->__element_length+1; /* Record character as parsed */
bytes_parsed += char_length;
/* If semicolon, store end-of-instruction */ /* If end of element, handle terminator */
if (terminator == ';') { if (instr->__element_length == 0) {
instr->state = GUAC_INSTRUCTION_PARSE_COMPLETE;
instr->opcode = instr->__elementv[0];
instr->argv = &(instr->__elementv[1]);
instr->argc = instr->__elementc - 1;
}
/* If comma, move on to next element */ *char_buffer = '\0';
else if (terminator == ',')
instr->state = GUAC_INSTRUCTION_PARSE_LENGTH;
/* Otherwise, parse error */ /* If semicolon, store end-of-instruction */
else { if (c == ';') {
instr->state = GUAC_INSTRUCTION_PARSE_ERROR; instr->state = GUAC_INSTRUCTION_PARSE_COMPLETE;
return 0; instr->opcode = instr->__elementv[0];
} instr->argv = &(instr->__elementv[1]);
instr->argc = instr->__elementc - 1;
break;
}
/* If comma, move on to next element */
else if (c == ',') {
instr->state = GUAC_INSTRUCTION_PARSE_LENGTH;
break;
}
/* Otherwise, parse error */
else {
instr->state = GUAC_INSTRUCTION_PARSE_ERROR;
return 0;
}
} /* end if end of element */
/* Advance to next character */
instr->__element_length--;
char_buffer += char_length;
} }