convstring.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef convstring_INCLUDED
  18. #define convstring_INCLUDED
  19. #include <kopano/zcdefs.h>
  20. #include <kopano/charset/convert.h>
  21. #include <string>
  22. #include <kopano/charset/utf8string.h>
  23. #include <mapidefs.h>
  24. namespace KC {
  25. class _kc_export convstring _kc_final {
  26. public:
  27. static convstring from_SPropValue(const SPropValue *lpsPropVal);
  28. _kc_hidden static convstring from_SPropValue(const SPropValue &);
  29. _kc_hidden convstring(void) = default;
  30. _kc_hidden convstring(const convstring &);
  31. _kc_hidden convstring(const char *);
  32. convstring(const wchar_t *lpsz);
  33. convstring(const TCHAR *lpsz, ULONG ulFlags);
  34. bool null_or_empty() const;
  35. operator utf8string() const;
  36. operator std::string(void) const;
  37. operator std::wstring(void) const;
  38. const char *c_str() const;
  39. const char *u8_str() const;
  40. private:
  41. template<typename T> _kc_hidden T convert_to(void) const;
  42. template<typename T> _kc_hidden T convert_to(const char *tocode) const;
  43. const TCHAR *m_lpsz = nullptr;
  44. ULONG m_ulFlags = 0;
  45. tstring m_str;
  46. mutable convert_context m_converter;
  47. };
  48. } /* namespace */
  49. #endif // ndef convstring_INCLUDED