1 /***************************************************************************
2  *   copyright           : (C) 2002 by Hendrik Sattler                     *
3  *   mail                : post@hendrik-sattler.de                         *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  ***************************************************************************/
11 
12 #include <charsets.h>
13 #include <helper.h>
14 #include "ucs2.h"
15 
16 #include <stdio.h>
17 #include <string.h>
18 
convert_to_ucs2(ucs4char_t * input)19 ucs2char_t* convert_to_ucs2 (ucs4char_t* input) {
20   return (ucs2char_t*)convert_from_internal(ucs2_get_iconv_charset(),
21 					    input,
22 					    REPMODE_IGNORE);
23 }
24 
convert_to_ucs2_hexstring(ucs4char_t * input,uint16_t (* fromhe)(uint16_t i))25 char* convert_to_ucs2_hexstring (ucs4char_t* input,
26 				 uint16_t (*fromhe)(uint16_t i)) {
27   char* retval;
28   ucs2char_t* temp;
29   unsigned int i;
30 
31   temp = convert_to_ucs2(input);
32   retval = mem_alloc((ucs2len(temp)*2*sizeof(ucs2char_t))+1,1);
33   for (i = 0; i < ucs2len(temp); ++i) {
34     sprintf(retval+(4*i),"%04X",fromhe(temp[i]));
35   }
36   mem_realloc(temp,0);
37   return retval;
38 }
39