examples/libxml.c
hubbub_error change_encoding(void *ctx, const char *charset)
{
	context *c = (context *) ctx;
	uint32_t source;
	const char *name;

	/* If we have an encoding here, it means we are *certain* */
	if (c->encoding != NULL) {
		return HUBBUB_OK;
	}

	/* Find the confidence otherwise (can only be from a BOM) */
	name = hubbub_parser_read_charset(c->parser, &source);

	if (source == HUBBUB_CHARSET_CONFIDENT) {
		c->enc_source = ENCODING_SOURCE_DETECTED;
		c->encoding = (char *) charset;
		return HUBBUB_OK;
	}

	/* So here we have something of confidence tentative... */
	/* http://www.whatwg.org/specs/web-apps/current-work/#change */

	/* 2. "If the new encoding is identical or equivalent to the encoding
	 * that is already being used to interpret the input stream, then set
	 * the confidence to confident and abort these steps." */

	/* Whatever happens, the encoding should be set here; either for
	 * reprocessing with a different charset, or for confirming that the
	 * charset is in fact correct */
	c->encoding = charset;
	c->enc_source = ENCODING_SOURCE_META;

	/* Equal encodings will have the same string pointers */
	return (charset == name) ? HUBBUB_OK : HUBBUB_ENCODINGCHANGE;
}
/**
 * Notification that a potential encoding change is required
 *
 * \param ctx      Our context
 * \param charset  The new charset for the source data
 * \return HUBBUB_OK to continue using the current input handler, 
 *         HUBBUB_ENCODINGCHANGE to stop processing immediately and 
 *                               return control to the client,
 *         appropriate error otherwise.
 */
Notification that a potential encoding change is required
\param ctx      Our context
\param charset  The new charset for the source data
\return HUBBUB_OK to continue using the current input handler,
HUBBUB_ENCODINGCHANGE to stop processing immediately and
return control to the client,
appropriate error otherwise.
Notification that a potential encoding change is required \ param ctx Our context \ param charset The new charset for the source data \ return HUBBUB_OK to continue using the current input handler HUBBUB_ENCODINGCHANGE to stop processing immediately and return control to the client appropriate error otherwise .
hubbub_error change_encoding(void *ctx, const char *charset)
{
	context *c = (context *) ctx;
	uint32_t source;
	const char *name;
	if (c->encoding != NULL) {
		return HUBBUB_OK;
	}
	name = hubbub_parser_read_charset(c->parser, &source);
	if (source == HUBBUB_CHARSET_CONFIDENT) {
		c->enc_source = ENCODING_SOURCE_DETECTED;
		c->encoding = (char *) charset;
		return HUBBUB_OK;
	}
	c->encoding = charset;
	c->enc_source = ENCODING_SOURCE_META;
	return (charset == name) ? HUBBUB_OK : HUBBUB_ENCODINGCHANGE;
}
hubbub_error change_encoding ( void * ctx , const char * charset ) { context * c = ( context * ) ctx ; uint32_t source ; const char * name ; if ( c -> encoding != NULL ) { return HUBBUB_OK ; } name = hubbub_parser_read_charset ( c -> parser , & source ) ; if ( source == HUBBUB_CHARSET_CONFIDENT ) { c -> enc_source = ENCODING_SOURCE_DETECTED ; c -> encoding = ( char * ) charset ; return HUBBUB_OK ; } c -> encoding = charset ; c -> enc_source = ENCODING_SOURCE_META ; return ( charset == name ) ? HUBBUB_OK : HUBBUB_ENCODINGCHANGE ; }
Notification that a potential encoding change is required
 \param ctx      Our context
 \param charset  The new charset for the source data
 \return HUBBUB_OK to continue using the current input handler,
         HUBBUB_ENCODINGCHANGE to stop processing immediately and
                               return control to the client,
         appropriate error otherwise.
Notification that a potential encoding change is required \ param ctx Our context \ param charset The new charset for the source data \ return HUBBUB_OK to continue using the current input handler HUBBUB_ENCODINGCHANGE to stop processing immediately and return control to the client appropriate error otherwise .
/* If we have an encoding here, it means we are *certain* */ /* Find the confidence otherwise (can only be from a BOM) */ /* So here we have something of confidence tentative... */ /* http://www.whatwg.org/specs/web-apps/current-work/#change */ /* 2. "If the new encoding is identical or equivalent to the encoding
	 * that is already being used to interpret the input stream, then set
	 * the confidence to confident and abort these steps." */ /* Whatever happens, the encoding should be set here; either for
	 * reprocessing with a different charset, or for confirming that the
	 * charset is in fact correct */ /* Equal encodings will have the same string pointers */