CUtils.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
  3. #define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
  4. #define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
  5. #define FNM_NOMATCH 1
  6. #define fnmatch fnmatch_win
  7. class CUtils
  8. {
  9. public:
  10. CUtils();
  11. ~CUtils(void);
  12. int MultiByToUtf8(const char* multi, char*& utf8);
  13. int Utf8ToMultiBy(const char* utf8, char*& multi);
  14. int Utf8ToUnicode(const char* utf8, wchar_t*& unicode);
  15. int UnicodeToUtf8(const wchar_t* unicode, char*& utf8);
  16. int MultiByToUnicode(const char* multi, wchar_t*& unicode);
  17. int UnicodeToMultiBy(const wchar_t* unicode, char*& multi);
  18. int fnmatch_win(const char* pattern, const char* name, int flags = 0);
  19. bool SafeFNMatch(const char* pattern, size_t patt_len, const char* str, size_t str_len);
  20. static std::string CvtA2A(const std::string& str, unsigned int cpFrom = CP_UTF8, unsigned int cpTo = CP_ACP);
  21. static std::wstring CvtW2W(const std::wstring& str, unsigned int cp = CP_ACP);
  22. static std::wstring CvtA2W(const std::string& str, unsigned int cp = CP_ACP, unsigned int cp2 = 0);
  23. static std::string CvtW2A(const std::wstring& str, unsigned int cp);
  24. };
  25. #define S_CA2W CUtils::CvtA2W
  26. #define S_CW2A CUtils::CvtW2A
  27. #define S_CA2A CUtils::CvtA2A
  28. #define S_CW2W CUtils::CvtW2W
  29. #ifdef UNICODE
  30. #define S_CA2T S_CA2W
  31. #define S_CT2A S_CW2A
  32. #define S_CW2T S_CW2W
  33. #define S_CT2W S_CW2W
  34. #else
  35. #define S_CA2T S_CA2A
  36. #define S_CT2A S_CA2A
  37. #define S_CW2T S_CW2A
  38. #define S_CT2W S_CA2W
  39. #endif // UNICODE