source/AccessorySDK/Support/utfconv.c
int
utf8_decodestr_copy(
	const void *inUTF8Ptr, size_t inUTF8Bytes, 
	void *outUTF16, size_t *outUTF16Bytes, 
	uint16_t inAltslash, int inFlags )
{
	OSStatus			err;
	const uint8_t *		utf8;
	uint16_t *			utf16Ptr;
	size_t				utf16Len;
	
	utf16Len = inUTF8Bytes * sizeof( uint16_t );
	utf16Ptr = (uint16_t *) utfmalloc( utf16Len + sizeof( uint16_t ) );
	if( !utf16Ptr ) { err = ENOMEM; goto exit; }
	
	utf8 = (const uint8_t *) inUTF8Ptr;
	err = utf8_decodestr( utf8, inUTF8Bytes, utf16Ptr, &utf16Len, utf16Len, inAltslash, inFlags );
	if( err ) goto exit;
	utf16Ptr[ utf16Len / sizeof( uint16_t ) ] = 0;
	
	*( (uint16_t **) outUTF16 )			= utf16Ptr;
	if( outUTF16Bytes ) *outUTF16Bytes	= utf16Len;
	utf16Ptr = NULL;
	
exit:
	if( utf16Ptr ) utffree( utf16Ptr );
	return( err );
}
/*
 * utf8_decodestr_copy - Decodes a UTF-8 string into UTF-16 into a malloc'd buffer.
 *
 * NOTES:
 *    On success, the caller must use utffree to free the UTF-16 buffer when no longer needed.
 *    Otherwise, the same notes as utf8_decodestr.
 *
 * FLAGS:
 *    Same flags as utf8_decodestr.
 *
 * ERRORS:
 *    Same errors as utf8_decodestr.
 */
Decodes a UTF-8 string into UTF-16 into a malloc'd buffer.
NOTES:
On success, the caller must use utffree to free the UTF-16 buffer when no longer needed.
Otherwise, the same notes as utf8_decodestr.

Same flags as utf8_decodestr.

Same errors as utf8_decodestr.
Decodes a UTF - 8 string into UTF - 16 into a malloc ' d buffer . NOTES : On success the caller must use utffree to free the UTF - 16 buffer when no longer needed . Otherwise the same notes as utf8_decodestr . Same flags as utf8_decodestr . Same errors as utf8_decodestr .
int
utf8_decodestr_copy(
	const void *inUTF8Ptr, size_t inUTF8Bytes, 
	void *outUTF16, size_t *outUTF16Bytes, 
	uint16_t inAltslash, int inFlags )
{
	OSStatus			err;
	const uint8_t *		utf8;
	uint16_t *			utf16Ptr;
	size_t				utf16Len;
	utf16Len = inUTF8Bytes * sizeof( uint16_t );
	utf16Ptr = (uint16_t *) utfmalloc( utf16Len + sizeof( uint16_t ) );
	if( !utf16Ptr ) { err = ENOMEM; goto exit; }
	utf8 = (const uint8_t *) inUTF8Ptr;
	err = utf8_decodestr( utf8, inUTF8Bytes, utf16Ptr, &utf16Len, utf16Len, inAltslash, inFlags );
	if( err ) goto exit;
	utf16Ptr[ utf16Len / sizeof( uint16_t ) ] = 0;
	*( (uint16_t **) outUTF16 )			= utf16Ptr;
	if( outUTF16Bytes ) *outUTF16Bytes	= utf16Len;
	utf16Ptr = NULL;
exit:
	if( utf16Ptr ) utffree( utf16Ptr );
	return( err );
}
int utf8_decodestr_copy ( const void * inUTF8Ptr , size_t inUTF8Bytes , void * outUTF16 , size_t * outUTF16Bytes , uint16_t inAltslash , int inFlags ) { OSStatus err ; const uint8_t * utf8 ; uint16_t * utf16Ptr ; size_t utf16Len ; utf16Len = inUTF8Bytes * sizeof ( uint16_t ) ; utf16Ptr = ( uint16_t * ) utfmalloc ( utf16Len + sizeof ( uint16_t ) ) ; if ( ! utf16Ptr ) { err = ENOMEM ; goto exit ; } utf8 = ( const uint8_t * ) inUTF8Ptr ; err = utf8_decodestr ( utf8 , inUTF8Bytes , utf16Ptr , & utf16Len , utf16Len , inAltslash , inFlags ) ; if ( err ) goto exit ; utf16Ptr [ utf16Len / sizeof ( uint16_t ) ] = 0 ; * ( ( uint16_t * * ) outUTF16 ) = utf16Ptr ; if ( outUTF16Bytes ) * outUTF16Bytes = utf16Len ; utf16Ptr = NULL ; exit : if ( utf16Ptr ) utffree ( utf16Ptr ) ; return ( err ) ; }
utf8_decodestr_copy - Decodes a UTF-8 string into UTF-16 into a malloc'd buffer.
utf8_decodestr_copy - Decodes a UTF - 8 string into UTF - 16 into a malloc ' d buffer .