string_convert.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Created by huli on 2021/12/20.
  3. //
  4. #ifndef NNXX_TESTS_STRING_CONVERT_H
  5. #define NNXX_TESTS_STRING_CONVERT_H
  6. #include <iostream>
  7. #include <string>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. //#define _WIN32
  11. //using namespace std;
  12. #ifdef _WIN32
  13. #include <windows.h>
  14. #else
  15. #include <iconv.h>
  16. #endif
  17. class String_convert
  18. {
  19. public:
  20. String_convert();
  21. String_convert(const String_convert& other)= default;
  22. String_convert& operator =(const String_convert& other)= default;
  23. ~String_convert();
  24. public://API functions
  25. #ifdef _WIN32
  26. static std::string gbk_to_utf8(const char *src_str);
  27. static std::string utf8_to_gbk(const char *src_str);
  28. #else
  29. static int gbk_to_utf8(char *str_str, size_t src_len, char *dst_str, size_t dst_len);
  30. static int utf8_to_gbk(char *src_str, size_t src_len, char *dst_str, size_t dst_len);
  31. static std::string gbk_to_utf8(std::string src_str);
  32. static std::string utf8_to_gbk(std::string src_str);
  33. #endif
  34. public://get or set member variable
  35. protected://member functions
  36. protected://member variable
  37. private:
  38. };
  39. #endif //NNXX_TESTS_STRING_CONVERT_H