cp_encrec.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "codepage.h"
  2. #include <util/stream/output.h>
  3. void Encoder::Tr(const wchar32* in, char* out, size_t len) const {
  4. while (len--)
  5. *out++ = Tr(*in++);
  6. }
  7. void Encoder::Tr(const wchar32* in, char* out) const {
  8. do {
  9. *out++ = Tr(*in);
  10. } while (*in++);
  11. }
  12. void Recoder::Create(const CodePage& source, const Encoder* wideTarget) {
  13. for (size_t i = 0; i != 256; ++i) {
  14. Table[i] = wideTarget->Tr(source.unicode[i]);
  15. Y_ASSERT(Table[i] != 0 || i == 0);
  16. }
  17. }
  18. void Recoder::Create(const CodePage& page, const Encoder* widePage, wchar32 (*mapfunc)(wchar32)) {
  19. for (size_t i = 0; i != 256; ++i) {
  20. char c = widePage->Code((*mapfunc)(page.unicode[i]));
  21. Table[i] = (c == 0 && i != 0) ? (unsigned char)i : (unsigned char)c;
  22. }
  23. }
  24. void Recoder::Tr(const char* in, char* out, size_t len) const {
  25. while (len--)
  26. *out++ = Table[(unsigned char)*in++];
  27. }
  28. void Recoder::Tr(const char* in, char* out) const {
  29. do {
  30. *out++ = Table[(unsigned char)*in];
  31. } while (*in++);
  32. }
  33. void Recoder::Tr(char* in_out, size_t len) const {
  34. while (len--) {
  35. *in_out = Table[(unsigned char)*in_out];
  36. in_out++;
  37. }
  38. }
  39. void Recoder::Tr(char* in_out) const {
  40. // assuming that '\0' <--> '\0'
  41. do {
  42. *in_out = Table[(unsigned char)*in_out];
  43. } while (*in_out++);
  44. }