[vlc-commits] commit: MMS: use ToCharset() ( Rémi Denis-Courmont )
git at videolan.org
git at videolan.org
Tue Oct 26 20:11:38 CEST 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Oct 26 20:59:59 2010 +0300| [20faccf7c4642cb878aae12a14a4d6c5018bf219] | committer: Rémi Denis-Courmont
MMS: use ToCharset()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=20faccf7c4642cb878aae12a14a4d6c5018bf219
---
modules/access/mms/buffer.c | 46 +++++++++++++++++-------------------------
1 files changed, 19 insertions(+), 27 deletions(-)
diff --git a/modules/access/mms/buffer.c b/modules/access/mms/buffer.c
index f80787a..13eff95 100644
--- a/modules/access/mms/buffer.c
+++ b/modules/access/mms/buffer.c
@@ -108,34 +108,26 @@ void var_buffer_addmemory( var_buffer_t *p_buf, void *p_mem, int i_mem )
void var_buffer_addUTF16( var_buffer_t *p_buf, const char *p_str )
{
- unsigned int i;
- if( !p_str )
- {
- var_buffer_add16( p_buf, 0 );
- }
+ uint16_t *p_out;
+ size_t i_out;
+
+ if( p_str != NULL )
+#ifdef WORDS_BIGENDIAN
+ p_out = ToCharset( "UTF-16BE", p_str, &i_out );
+#else
+ p_out = ToCharset( "UTF-16LE", p_str, &i_out );
+#endif
else
- {
- vlc_iconv_t iconv_handle;
- size_t i_in = strlen( p_str );
- size_t i_out = i_in * 4;
- char *psz_out, *psz_tmp;
-
- psz_out = psz_tmp = xmalloc( i_out + 1 );
- iconv_handle = vlc_iconv_open( "UTF-16LE", "UTF-8" );
- vlc_iconv( iconv_handle, &p_str, &i_in, &psz_tmp, &i_out );
- vlc_iconv_close( iconv_handle );
- psz_tmp[0] = '\0';
- psz_tmp[1] = '\0';
-
- for( i = 0; ; i += 2 )
- {
- uint16_t v = GetWLE( &psz_out[i] );
- var_buffer_add16( p_buf, v );
- if( !v )
- break;
- }
- free( psz_out );
- }
+ p_out = NULL;
+ if( p_out == NULL )
+ i_out = 0;
+
+ i_out /= 2;
+ for( size_t i = 0; i < i_out; i ++ )
+ var_buffer_add16( p_buf, p_out[i] );
+ free( p_out );
+
+ var_buffer_add16( p_buf, 0 );
}
void var_buffer_free( var_buffer_t *p_buf )
More information about the vlc-commits
mailing list