[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / platform / win32 / CharsetConverter.cpp
blob58f207da35e9af2488a59acb6e3725b190aa915f
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "CharsetConverter.h"
11 #include <memory>
12 namespace KODI
14 namespace PLATFORM
16 namespace WINDOWS
18 std::string FromW(const wchar_t* str, size_t length)
20 int result = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, str, length, nullptr, 0, nullptr, nullptr);
21 if (result == 0)
22 return std::string();
24 auto newStr = std::make_unique<char[]>(result);
25 result = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, str, length, newStr.get(), result, nullptr, nullptr);
26 if (result == 0)
27 return std::string();
29 return std::string(newStr.get(), result);
32 std::string FromW(const std::wstring& str)
34 return FromW(str.c_str(), str.length());
37 std::wstring ToW(const char* str, size_t length)
39 int result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, length, nullptr, 0);
40 if (result == 0)
41 return std::wstring();
43 auto newStr = std::make_unique<wchar_t[]>(result);
44 result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, length, newStr.get(), result);
46 if (result == 0)
47 return std::wstring();
49 return std::wstring(newStr.get(), result);
52 std::wstring ToW(const std::string& str)
54 return ToW(str.c_str(), str.length());