| 30 | #endif //UNICODE |
| 31 | |
| 32 | TCHAR* SU::Utf8ToTChar(const char * utf8string) { |
| 33 | if (utf8string == NULL) |
| 34 | return NULL; |
| 35 | |
| 36 | if (utf8string[0] == 0) { |
| 37 | TCHAR * empty = new TCHAR[1]; |
| 38 | empty[0] = 0; |
| 39 | return empty; |
| 40 | } |
| 41 | |
| 42 | int size = ::MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0); |
| 43 | if (size == 0) |
| 44 | return NULL; |
| 45 | |
| 46 | wchar_t * wstring = new wchar_t[size]; |
| 47 | int ret = ::MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, wstring, size); |
| 48 | if (ret == 0) { |
| 49 | delete [] wstring; |
| 50 | return NULL; |
| 51 | } |
| 52 | |
| 53 | #ifdef UNICODE |
| 54 | return wstring; |
| 55 | #else |
| 56 | size = ::WideCharToMultiByte(CP_ACP, 0, wstring, -1, NULL, 0, NULL, NULL); |
| 57 | if (size == 0) { |
| 58 | delete [] wstring; |
| 59 | return NULL; |
| 60 | } |
| 61 | char * tstring = new char[size]; |
| 62 | ret = ::WideCharToMultiByte(CP_ACP, 0, wstring, -1, tstring, size, NULL, NULL); |
| 63 | delete [] wstring; |
| 64 | |
| 65 | if (ret == 0) { |
| 66 | delete [] tstring; |
| 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | return tstring; |
| 71 | #endif //UNICODE |
| 72 | } |
| 73 | |
| 74 | char* SU::TCharToUtf8(const TCHAR * string) { |
| 75 | return TCharToCP(string, CP_UTF8); |
nothing calls this directly
no outgoing calls
no test coverage detected