yencoding.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "yencoding.h"
  2. #include <library/cpp/charset/codepage.h>
  3. #include <library/cpp/charset/recyr.hh>
  4. int
  5. win1251ToUTF8(unsigned char* out, int *outlen,
  6. const unsigned char* in, int *inlen) {
  7. size_t in_readed, out_writed;
  8. RECODE_RESULT res = Recode(CODES_WIN, CODES_UTF8, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, in_readed, out_writed);
  9. *inlen = (int)in_readed;
  10. *outlen = (int)out_writed;
  11. return (res == RECODE_OK)? 0 : -1;
  12. }
  13. int
  14. UTF8Towin1251(unsigned char* out, int *outlen,
  15. const unsigned char* in, int *inlen) {
  16. size_t in_readed, out_writed;
  17. RECODE_RESULT res = Recode(CODES_UTF8, CODES_WIN, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, in_readed, out_writed);
  18. *inlen = (int)in_readed;
  19. *outlen = (int)out_writed;
  20. return (res == RECODE_OK)? 0 : -1;
  21. }
  22. int
  23. koi8ToUTF8(unsigned char* out, int *outlen,
  24. const unsigned char* in, int *inlen) {
  25. size_t in_readed, out_writed;
  26. RECODE_RESULT res = Recode(CODES_KOI8, CODES_UTF8, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, in_readed, out_writed);
  27. *inlen = (int)in_readed;
  28. *outlen = (int)out_writed;
  29. return (res == RECODE_OK)? 0 : -1;
  30. }
  31. int
  32. UTF8Tokoi8(unsigned char* out, int *outlen,
  33. const unsigned char* in, int *inlen) {
  34. size_t in_readed, out_writed;
  35. RECODE_RESULT res = Recode(CODES_UTF8, CODES_KOI8, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, in_readed, out_writed);
  36. *inlen = (int)in_readed;
  37. *outlen = (int)out_writed;
  38. return (res == RECODE_OK)? 0 : -1;
  39. }