sample.c 991 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. #include <stdio.h>
  8. #include "../mbfl/mbfilter.h"
  9. int main()
  10. {
  11. enum mbfl_no_encoding from_encoding, to_encoding;
  12. enum mbfl_no_language no_language;
  13. mbfl_buffer_converter *convd = NULL;
  14. mbfl_string string, result, *ret;
  15. mbfl_language lang;
  16. unsigned char input[] = "ÆüËܸìʸ»úÎó"; /* EUC-JP kanji string */
  17. no_language = mbfl_name2no_language("Japanese");
  18. from_encoding = mbfl_name2no_encoding("EUC-JP");
  19. to_encoding = mbfl_name2no_encoding("SJIS");
  20. mbfl_string_init(&string);
  21. mbfl_string_init(&result);
  22. string.no_encoding = from_encoding;
  23. string.no_language = no_language;
  24. string.val = (unsigned char *)input;
  25. string.len = strlen(input);
  26. convd = mbfl_buffer_converter_new(from_encoding, to_encoding, 0);
  27. ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
  28. mbfl_buffer_converter_delete(convd);
  29. puts(ret->val);
  30. return 1;
  31. }