src/tokeniser/tokeniser.c
hubbub_error hubbub_tokeniser_handle_bogus_comment(hubbub_tokeniser *tokeniser)
{
	size_t len;
	const uint8_t *cptr;
	parserutils_error error;
	uint8_t c;

	error = parserutils_inputstream_peek(tokeniser->input,
			tokeniser->context.pending, &cptr, &len);

	if (error != PARSERUTILS_OK) {
		if (error == PARSERUTILS_EOF) {
			tokeniser->state = STATE_DATA;
			return emit_current_comment(tokeniser);
		} else {
			return hubbub_error_from_parserutils_error(error);
		}
	}

	c = *cptr;

	if (c == '>') {
		tokeniser->context.pending += len;
		tokeniser->state = STATE_DATA;
		return emit_current_comment(tokeniser);
	} else if (c == '\0') {
		error = parserutils_buffer_append(tokeniser->buffer,
				u_fffd, sizeof(u_fffd));
		if (error != PARSERUTILS_OK)
			return hubbub_error_from_parserutils_error(error);

		tokeniser->context.pending += len;
	} else if (c == '\r') {
		error = parserutils_inputstream_peek(
				tokeniser->input,
				tokeniser->context.pending,
				&cptr,
				&len);

		if (error != PARSERUTILS_OK && error != PARSERUTILS_EOF) {
			return hubbub_error_from_parserutils_error(error);
		} else if (error == PARSERUTILS_EOF || *cptr != '\n') {
			error = parserutils_buffer_append(tokeniser->buffer,
					&lf, sizeof(lf));
			if (error != PARSERUTILS_OK) {
				return hubbub_error_from_parserutils_error(
						error);
			}
		}
		tokeniser->context.pending += len;
	} else {
		error = parserutils_buffer_append(tokeniser->buffer,
				(uint8_t *) cptr, len);
		if (error != PARSERUTILS_OK)
			return hubbub_error_from_parserutils_error(error);

		tokeniser->context.pending += len;
	}

	return HUBBUB_OK;
}
/* this state expects tokeniser->context.chars to be empty on first entry */
this state expects tokeniser->context.chars to be empty on first entry
this state expects tokeniser - > context . chars to be empty on first entry
hubbub_error hubbub_tokeniser_handle_bogus_comment(hubbub_tokeniser *tokeniser)
{
	size_t len;
	const uint8_t *cptr;
	parserutils_error error;
	uint8_t c;
	error = parserutils_inputstream_peek(tokeniser->input,
			tokeniser->context.pending, &cptr, &len);
	if (error != PARSERUTILS_OK) {
		if (error == PARSERUTILS_EOF) {
			tokeniser->state = STATE_DATA;
			return emit_current_comment(tokeniser);
		} else {
			return hubbub_error_from_parserutils_error(error);
		}
	}
	c = *cptr;
	if (c == '>') {
		tokeniser->context.pending += len;
		tokeniser->state = STATE_DATA;
		return emit_current_comment(tokeniser);
	} else if (c == '\0') {
		error = parserutils_buffer_append(tokeniser->buffer,
				u_fffd, sizeof(u_fffd));
		if (error != PARSERUTILS_OK)
			return hubbub_error_from_parserutils_error(error);
		tokeniser->context.pending += len;
	} else if (c == '\r') {
		error = parserutils_inputstream_peek(
				tokeniser->input,
				tokeniser->context.pending,
				&cptr,
				&len);
		if (error != PARSERUTILS_OK && error != PARSERUTILS_EOF) {
			return hubbub_error_from_parserutils_error(error);
		} else if (error == PARSERUTILS_EOF || *cptr != '\n') {
			error = parserutils_buffer_append(tokeniser->buffer,
					&lf, sizeof(lf));
			if (error != PARSERUTILS_OK) {
				return hubbub_error_from_parserutils_error(
						error);
			}
		}
		tokeniser->context.pending += len;
	} else {
		error = parserutils_buffer_append(tokeniser->buffer,
				(uint8_t *) cptr, len);
		if (error != PARSERUTILS_OK)
			return hubbub_error_from_parserutils_error(error);
		tokeniser->context.pending += len;
	}
	return HUBBUB_OK;
}
hubbub_error hubbub_tokeniser_handle_bogus_comment ( hubbub_tokeniser * tokeniser ) { size_t len ; const uint8_t * cptr ; parserutils_error error ; uint8_t c ; error = parserutils_inputstream_peek ( tokeniser -> input , tokeniser -> context . pending , & cptr , & len ) ; if ( error != PARSERUTILS_OK ) { if ( error == PARSERUTILS_EOF ) { tokeniser -> state = STATE_DATA ; return emit_current_comment ( tokeniser ) ; } else { return hubbub_error_from_parserutils_error ( error ) ; } } c = * cptr ; if ( c == ' ' ) { tokeniser -> context . pending += len ; tokeniser -> state = STATE_DATA ; return emit_current_comment ( tokeniser ) ; } else if ( c == ' \0 ' ) { error = parserutils_buffer_append ( tokeniser -> buffer , u_fffd , sizeof ( u_fffd ) ) ; if ( error != PARSERUTILS_OK ) return hubbub_error_from_parserutils_error ( error ) ; tokeniser -> context . pending += len ; } else if ( c == ' \r ' ) { error = parserutils_inputstream_peek ( tokeniser -> input , tokeniser -> context . pending , & cptr , & len ) ; if ( error != PARSERUTILS_OK && error != PARSERUTILS_EOF ) { return hubbub_error_from_parserutils_error ( error ) ; } else if ( error == PARSERUTILS_EOF || * cptr != ' \n ' ) { error = parserutils_buffer_append ( tokeniser -> buffer , & lf , sizeof ( lf ) ) ; if ( error != PARSERUTILS_OK ) { return hubbub_error_from_parserutils_error ( error ) ; } } tokeniser -> context . pending += len ; } else { error = parserutils_buffer_append ( tokeniser -> buffer , ( uint8_t * ) cptr , len ) ; if ( error != PARSERUTILS_OK ) return hubbub_error_from_parserutils_error ( error ) ; tokeniser -> context . pending += len ; } return HUBBUB_OK ; }
this state expects tokeniser->context.chars to be empty on first entry
this state expects tokeniser - > context . chars to be empty on first entry