+static char *KeyToUTF8( int i_key, char *psz_part )
+{
+ char *psz_utf8, *psz;
+ int len = strlen( psz_part );
+ if( len == 6 )
+ {
+ /* overflow error - should not happen */
+ memset( psz_part, 0, 6 );
+ return NULL;
+ }
+
+ psz_part[len] = (char)i_key;
+
+ psz_utf8 = FromLocaleDup( psz_part );
+
+ /* Ugly check for incomplete bytes sequences
+ * (in case of non-UTF8 multibyte local encoding) */
+ for( psz = psz_utf8; *psz; psz++ )
+ if( ( *psz == '?' ) && ( *psz_utf8 != '?' ) )
+ {
+ /* incomplete bytes sequence detected
+ * (VLC core inserted dummy question marks) */
+ free( psz_utf8 );
+ return NULL;
+ }
+
+ /* Check for incomplete UTF8 bytes sequence */
+ if( EnsureUTF8( psz_utf8 ) == NULL )
+ {
+ free( psz_utf8 );
+ return NULL;
+ }
+
+ memset( psz_part, 0, 6 );
+ return psz_utf8;
+}
+
+static inline int RemoveLastUTF8Entity( char *psz, int len )
+{
+ while( len && ( (psz[--len] & 0xc0) == 0x80 ) );
+ /* UTF8 continuation byte */
+
+ psz[len] = '\0';
+ return len;
+}
+