cm_codecvt.hxx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cm_codecvt_hxx
  4. #define cm_codecvt_hxx
  5. #include <cmConfigure.h> // IWYU pragma: keep
  6. #include <locale>
  7. #include <vector>
  8. class codecvt : public std::codecvt<char, char, mbstate_t>
  9. {
  10. public:
  11. enum Encoding
  12. {
  13. None,
  14. UTF8,
  15. ANSI
  16. };
  17. #ifdef CMAKE_BUILD_WITH_CMAKE
  18. codecvt(Encoding e);
  19. protected:
  20. ~codecvt() CM_OVERRIDE;
  21. bool do_always_noconv() const throw() CM_OVERRIDE;
  22. result do_out(mbstate_t& state, const char* from, const char* from_end,
  23. const char*& from_next, char* to, char* to_end,
  24. char*& to_next) const CM_OVERRIDE;
  25. result do_unshift(mbstate_t& state, char* to, char*,
  26. char*& to_next) const CM_OVERRIDE;
  27. int do_max_length() const throw() CM_OVERRIDE;
  28. int do_encoding() const throw() CM_OVERRIDE;
  29. private:
  30. typedef struct
  31. {
  32. bool used;
  33. unsigned char totalBytes;
  34. unsigned char bytesLeft;
  35. char bytes[4];
  36. } State;
  37. unsigned int findStateId() const;
  38. bool m_noconv;
  39. mutable std::vector<State> m_states;
  40. mutable unsigned int m_lastState;
  41. #if defined(_WIN32)
  42. unsigned int m_codepage;
  43. #endif
  44. #endif
  45. };
  46. #endif