xref: /PHP-5.3/ext/mbstring/libmbfl/tests/sample.c (revision ea539c8b)
1 /**
2  * this is a small sample script to use libmbfl.
3  * Rui Hirokawa <hirokawa@php.net>
4  *
5  * this file is encoded in EUC-JP.
6  */
7 
8 #include <stdio.h>
9 #include "../mbfl/mbfilter.h"
10 
main()11 int main()
12 {
13 	enum mbfl_no_encoding from_encoding, to_encoding;
14 	enum mbfl_no_language no_language;
15 	mbfl_buffer_converter *convd = NULL;
16 	mbfl_string string, result, *ret;
17 	mbfl_language lang;
18 	unsigned char input[] = "���ܸ�ʸ����"; /* EUC-JP kanji string */
19 
20 	no_language = mbfl_name2no_language("Japanese");
21 	from_encoding = mbfl_name2no_encoding("EUC-JP");
22 	to_encoding = mbfl_name2no_encoding("SJIS");
23 
24 	mbfl_string_init(&string);
25 	mbfl_string_init(&result);
26 
27 	string.no_encoding = from_encoding;
28 	string.no_language = no_language;
29 	string.val = (unsigned char *)input;
30 	string.len = strlen(input);
31 
32 	convd = mbfl_buffer_converter_new(from_encoding, to_encoding, 0);
33 	ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
34 	mbfl_buffer_converter_delete(convd);
35 
36 	puts(ret->val);
37 	return 1;
38 }
39