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,29 +119,38 @@ 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 end of element, handle terminator */
if (instr->__element_length == 0) {
*char_buffer = '\0';
/* If semicolon, store end-of-instruction */ /* If semicolon, store end-of-instruction */
if (terminator == ';') { if (c == ';') {
instr->state = GUAC_INSTRUCTION_PARSE_COMPLETE; instr->state = GUAC_INSTRUCTION_PARSE_COMPLETE;
instr->opcode = instr->__elementv[0]; instr->opcode = instr->__elementv[0];
instr->argv = &(instr->__elementv[1]); instr->argv = &(instr->__elementv[1]);
instr->argc = instr->__elementc - 1; instr->argc = instr->__elementc - 1;
break;
} }
/* If comma, move on to next element */ /* If comma, move on to next element */
else if (terminator == ',') else if (c == ',') {
instr->state = GUAC_INSTRUCTION_PARSE_LENGTH; instr->state = GUAC_INSTRUCTION_PARSE_LENGTH;
break;
}
/* Otherwise, parse error */ /* Otherwise, parse error */
else { else {
@ -148,6 +158,12 @@ int guac_instruction_append(guac_instruction* instr,
return 0; return 0;
} }
} /* end if end of element */
/* Advance to next character */
instr->__element_length--;
char_buffer += char_length;
} }
} /* end parse content */ } /* end parse content */