src/tokeniser/tokeniser.c
hubbub_error hubbub_tokeniser_handle_character_reference_data(
		hubbub_tokeniser *tokeniser)
{
	assert(tokeniser->context.pending == 0);

	if (tokeniser->context.match_entity.complete == false) {
		return hubbub_tokeniser_consume_character_reference(tokeniser,
				tokeniser->context.pending);
	} else {
		hubbub_token token;

		uint8_t utf8[6];
		uint8_t *utf8ptr = utf8;
		size_t len = sizeof(utf8);

		token.type = HUBBUB_TOKEN_CHARACTER;

		if (tokeniser->context.match_entity.codepoint) {
			parserutils_charset_utf8_from_ucs4(
				tokeniser->context.match_entity.codepoint,
				&utf8ptr, &len);

			token.data.character.ptr = utf8;
			token.data.character.len = sizeof(utf8) - len;

			hubbub_tokeniser_emit_token(tokeniser, &token);

			/* +1 for ampersand */
			parserutils_inputstream_advance(tokeniser->input,
					tokeniser->context.match_entity.length
							+ 1);
		} else {
			parserutils_error error;
			const uint8_t *cptr = NULL;

			error = parserutils_inputstream_peek(
					tokeniser->input,
					tokeniser->context.pending,
					&cptr,
					&len);
			if (error != PARSERUTILS_OK) {
				return hubbub_error_from_parserutils_error(
						error);
			}

			token.data.character.ptr = cptr;
			token.data.character.len = len;

			hubbub_tokeniser_emit_token(tokeniser, &token);
			parserutils_inputstream_advance(tokeniser->input, len);
		}

		/* Reset for next time */
		tokeniser->context.match_entity.complete = false;

		tokeniser->state = STATE_DATA;
	}

	return HUBBUB_OK;
}
/* emit any pending tokens before calling */
emit any pending tokens before calling
emit any pending tokens before calling
hubbub_error hubbub_tokeniser_handle_character_reference_data(
		hubbub_tokeniser *tokeniser)
{
	assert(tokeniser->context.pending == 0);
	if (tokeniser->context.match_entity.complete == false) {
		return hubbub_tokeniser_consume_character_reference(tokeniser,
				tokeniser->context.pending);
	} else {
		hubbub_token token;
		uint8_t utf8[6];
		uint8_t *utf8ptr = utf8;
		size_t len = sizeof(utf8);
		token.type = HUBBUB_TOKEN_CHARACTER;
		if (tokeniser->context.match_entity.codepoint) {
			parserutils_charset_utf8_from_ucs4(
				tokeniser->context.match_entity.codepoint,
				&utf8ptr, &len);
			token.data.character.ptr = utf8;
			token.data.character.len = sizeof(utf8) - len;
			hubbub_tokeniser_emit_token(tokeniser, &token);
			parserutils_inputstream_advance(tokeniser->input,
					tokeniser->context.match_entity.length
							+ 1);
		} else {
			parserutils_error error;
			const uint8_t *cptr = NULL;
			error = parserutils_inputstream_peek(
					tokeniser->input,
					tokeniser->context.pending,
					&cptr,
					&len);
			if (error != PARSERUTILS_OK) {
				return hubbub_error_from_parserutils_error(
						error);
			}
			token.data.character.ptr = cptr;
			token.data.character.len = len;
			hubbub_tokeniser_emit_token(tokeniser, &token);
			parserutils_inputstream_advance(tokeniser->input, len);
		}
		tokeniser->context.match_entity.complete = false;
		tokeniser->state = STATE_DATA;
	}
	return HUBBUB_OK;
}
hubbub_error hubbub_tokeniser_handle_character_reference_data ( hubbub_tokeniser * tokeniser ) { assert ( tokeniser -> context . pending == 0 ) ; if ( tokeniser -> context . match_entity . complete == false ) { return hubbub_tokeniser_consume_character_reference ( tokeniser , tokeniser -> context . pending ) ; } else { hubbub_token token ; uint8_t utf8 [ 6 ] ; uint8_t * utf8ptr = utf8 ; size_t len = sizeof ( utf8 ) ; token . type = HUBBUB_TOKEN_CHARACTER ; if ( tokeniser -> context . match_entity . codepoint ) { parserutils_charset_utf8_from_ucs4 ( tokeniser -> context . match_entity . codepoint , & utf8ptr , & len ) ; token . data . character . ptr = utf8 ; token . data . character . len = sizeof ( utf8 ) - len ; hubbub_tokeniser_emit_token ( tokeniser , & token ) ; parserutils_inputstream_advance ( tokeniser -> input , tokeniser -> context . match_entity . length + 1 ) ; } else { parserutils_error error ; const uint8_t * cptr = NULL ; error = parserutils_inputstream_peek ( tokeniser -> input , tokeniser -> context . pending , & cptr , & len ) ; if ( error != PARSERUTILS_OK ) { return hubbub_error_from_parserutils_error ( error ) ; } token . data . character . ptr = cptr ; token . data . character . len = len ; hubbub_tokeniser_emit_token ( tokeniser , & token ) ; parserutils_inputstream_advance ( tokeniser -> input , len ) ; } tokeniser -> context . match_entity . complete = false ; tokeniser -> state = STATE_DATA ; } return HUBBUB_OK ; }
emit any pending tokens before calling
emit any pending tokens before calling
/* +1 for ampersand */ /* Reset for next time */