init.cpp 1017 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "init.h"
  2. #include <libxml/xmlIO.h>
  3. #include <libxml/parser.h>
  4. #include <libxml/parserInternals.h>
  5. #include <libxml/tree.h>
  6. #include <library/cpp/charset/recyr.hh>
  7. #include <util/generic/singleton.h>
  8. namespace {
  9. int CharEncodingInput(unsigned char* out, int* outlen, const unsigned char* in, int* inlen) {
  10. size_t read = 0, written = 0;
  11. RECODE_RESULT r = Recode(CODES_WIN, CODES_UTF8, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, read, written);
  12. if (r == RECODE_EOOUTPUT)
  13. return -1;
  14. if (r != RECODE_OK)
  15. return -2;
  16. *inlen = (int)read;
  17. *outlen = (int)written;
  18. return (int)written;
  19. }
  20. class TLibXml2 {
  21. public:
  22. inline TLibXml2() {
  23. xmlInitParser();
  24. xmlNewCharEncodingHandler("windows-1251", CharEncodingInput, nullptr);
  25. }
  26. inline ~TLibXml2() {
  27. xmlCleanupParser();
  28. }
  29. };
  30. }
  31. void NXml::InitEngine() {
  32. Singleton<TLibXml2>();
  33. }