XUnZipZilb.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef RVC_MOD_UPLOAD_XUNZIP_ZLIB_H_
  2. #define RVC_MOD_UPLOAD_XUNZIP_ZLIB_H_
  3. #include "SpBase.h"
  4. #ifdef RVC_OS_WIN
  5. #define ZLIB_WINAPI //win32 必须使用的宏
  6. #endif
  7. #include "zip.h"
  8. #include "unzip.h"
  9. #include <iostream>
  10. #include <stdio.h>
  11. #include <string>
  12. #include <locale>
  13. #include <codecvt>
  14. using namespace std;
  15. //GBK转UTF码类
  16. class chs_codecvt : public std::codecvt_byname<wchar_t, char, std::mbstate_t> {
  17. public:
  18. //因不同平台,名称不同,故这里做转换,统一取出不同平台下面的GBK码
  19. #ifdef RVC_OS_WIN
  20. chs_codecvt() : codecvt_byname("chs") { }//zh_CN.GBK or .936
  21. #else
  22. chs_codecvt() : codecvt_byname("zh_CN.GBK") { }//.936
  23. #endif // RVC_OS_WIN
  24. };
  25. //src必须是UTF8否则抛异常
  26. static wstring utf8_to_wstr(const string& src)
  27. {
  28. wstring_convert<codecvt_utf8<wchar_t>> converter;
  29. return converter.from_bytes(src);
  30. }
  31. static string wstr_to_utf8(const wstring& src)
  32. {
  33. wstring_convert<codecvt_utf8<wchar_t>> convert;
  34. return convert.to_bytes(src);
  35. }
  36. static string utf8_to_gbk(const string& str)
  37. {
  38. wstring wStr = utf8_to_wstr(str);//utf8转wstring
  39. wstring_convert<chs_codecvt> converter;
  40. return converter.to_bytes(wStr);//wstring转GBK
  41. }
  42. static string gbk_to_utf8(const string& str)
  43. {
  44. wstring_convert<chs_codecvt> converter;
  45. wstring wStr = converter.from_bytes(str);//GBK转wstring
  46. return wstr_to_utf8(wStr);//wstring 转utf8
  47. }
  48. int UnZipToDir(string zipFileName, string destDirPath);
  49. int unZipCurrentFile(zipFile zf, string destDirPath);
  50. bool is_str_utf8(const char* str);
  51. #ifdef RVC_OS_WIN
  52. #else
  53. unsigned char* utf8_string_create(const char* string);
  54. #endif // RVC_OS_WIN
  55. #endif //RVC_MOD_UPLOAD_XUNZIP_ZLIB_H_