Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

  1. #ifndef _UTF8STR_H_
  2. #define _UTF8STR_H_
  3. class CUTF8String
  4. {
  5. public:
  6. CUTF8String(LPCWSTR pcwszUnicode) :
  7. m_pwszUnicode ((LPWSTR) pcwszUnicode),
  8. m_pszUTF8 (NULL),
  9. m_eAlloc (ALLOC_NONE),
  10. m_hr (S_OK) { };
  11. CUTF8String(LPCSTR pcszUTF8) :
  12. m_pszUTF8 ((LPSTR) pcszUTF8),
  13. m_pwszUnicode (NULL),
  14. m_eAlloc (ALLOC_NONE),
  15. m_hr (S_OK) { };
  16. ~CUTF8String();
  17. VOID AssignString(LPCSTR pcszUTF8) {
  18. delete m_pwszUnicode;
  19. m_pwszUnicode = NULL;
  20. m_eAlloc = ALLOC_NONE;
  21. m_hr = S_OK;
  22. m_pszUTF8 = (LPSTR) pcszUTF8; };
  23. VOID AssignString(LPCWSTR pcwszUnicode) {
  24. delete m_pszUTF8;
  25. m_pszUTF8 = NULL;
  26. m_eAlloc = ALLOC_NONE;
  27. m_hr = S_OK;
  28. m_pwszUnicode = (LPWSTR) pcwszUnicode; };
  29. operator LPWSTR();
  30. operator LPSTR();
  31. HRESULT GetError() { return m_hr; };
  32. protected:
  33. VOID EncodeUTF8();
  34. VOID DecodeUTF8();
  35. HRESULT m_hr;
  36. LPWSTR m_pwszUnicode;
  37. LPSTR m_pszUTF8;
  38. enum
  39. {
  40. ALLOC_NONE,
  41. ALLOC_UNICODE,
  42. ALLOC_UTF8,
  43. } m_eAlloc;
  44. };
  45. #endif // ! _UTF8STR_H_