MCPcopy Create free account
hub / github.com/ashkulz/NppFTP / TCharToCP

Method TCharToCP

src/StringUtils.cpp:78–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78char* SU::TCharToCP(const TCHAR * string, int cp) {
79 int size = 0;
80 int ret = 0;
81
82 if (string == NULL)
83 return NULL;
84
85 if (string[0] == 0) {
86 char * empty = new char[1];
87 empty[0] = 0;
88 return empty;
89 }
90
91#ifndef UNICODE
92 size = ::MultiByteToWideChar(CP_ACP, 0, string, -1, NULL, 0);
93 if (size == 0)
94 return NULL;
95
96 wchar_t * wstring = new wchar_t[size];
97 ret = ::MultiByteToWideChar(CP_ACP, 0, string, -1, wstring, size);
98 if (ret == 0) {
99 delete [] wstring;
100 return NULL;
101 }
102#else
103 const wchar_t * wstring = string;
104#endif //UNICODE
105
106 size = ::WideCharToMultiByte(cp, 0, wstring, -1, NULL, 0, NULL, NULL);
107 if (size == 0) {
108 EXECMBYTE(delete [] wstring;)
109 return NULL;
110 }
111 char * utf8string = new char[size];
112 ret = ::WideCharToMultiByte(cp, 0, wstring, -1, utf8string, size, NULL, NULL);
113 EXECMBYTE(delete [] wstring;)
114
115 if (ret == 0) {
116 delete [] utf8string;
117 return NULL;
118 }
119
120 return utf8string;
121}
122
123TCHAR* SU::DupString(const TCHAR* string) {
124 if (!string)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected