utfutil.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include <kopano/platform.h>
  18. #include "utfutil.h"
  19. #include <unicode/ustring.h>
  20. #include <kopano/charset/convert.h>
  21. namespace KC {
  22. UnicodeString WCHARToUnicode(const wchar_t *sz)
  23. {
  24. return UTF32ToUnicode((const UChar32 *)sz);
  25. }
  26. UnicodeString StringToUnicode(const char *sz)
  27. {
  28. // *tocode, const _From_Type &_from, size_t cbBytes, const char *fromcode
  29. auto strUTF16 = convert_context().convert_to<std::string>("UTF-16LE", sz, rawsize(sz), "");
  30. return UnicodeString((UChar *)strUTF16.data(), strUTF16.length() / 2);
  31. }
  32. } /* namespace */