1 /*****************************************************************************
2 * ID3Text.h : ID3v2 Text Helper
3 *****************************************************************************
4 * Copyright (C) 2016 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
23 #include <vlc_charset.h>
25 static const char * ID3TextConv( const uint8_t *p_buf
, size_t i_buf
,
26 uint8_t i_charset
, char **ppsz_allocated
)
29 const char *psz
= p_alloc
;
30 if( i_buf
> 0 && i_charset
< 0x04 )
35 psz
= p_alloc
= FromCharset( "ISO_8859-1", p_buf
, i_buf
);
38 psz
= p_alloc
= FromCharset( "UTF-16LE", p_buf
, i_buf
);
41 psz
= p_alloc
= FromCharset( "UTF-16BE", p_buf
, i_buf
);
45 if( p_buf
[ i_buf
- 1 ] != 0x00 )
47 psz
= p_alloc
= (char *) malloc( i_buf
+ 1 );
50 memcpy( p_alloc
, p_buf
, i_buf
- 1 );
51 p_alloc
[i_buf
] = '\0';
56 psz
= (const char *) p_buf
;
61 *ppsz_allocated
= p_alloc
;
65 static inline const char * ID3TextConvert( const uint8_t *p_buf
, size_t i_buf
,
66 char **ppsz_allocated
)
70 *ppsz_allocated
= NULL
;
73 return ID3TextConv( &p_buf
[1], i_buf
- 1, p_buf
[0], ppsz_allocated
);