MCPcopy Create free account
hub / github.com/dhbloo/rapfi / LegacyFileCPToUTF8

Function LegacyFileCPToUTF8

Rapfi/core/utils.cpp:131–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129// -------------------------------------------------
130
131std::string LegacyFileCPToUTF8(std::string str)
132{
133#if defined(_WIN32)
134 if (str.empty())
135 return {};
136
137 int nCodePage = Config::DatabaseLegacyFileCodePage;
138 // Use system's active code page if not specified
139 if (nCodePage == 0)
140 nCodePage = GetACP();
141 int wideSize = MultiByteToWideChar(nCodePage, 0, str.c_str(), (int)str.length(), nullptr, 0);
142 if (!wideSize)
143 return {}; // error
144
145 std::wstring wstr(wideSize + 1, '\0');
146 if (!MultiByteToWideChar(nCodePage,
147 0,
148 str.c_str(),
149 (int)str.length(),
150 wstr.data(),
151 (int)wstr.size()))
152 return {}; // error
153
154 int utf8Size = WideCharToMultiByte(CP_UTF8,
155 0,
156 wstr.c_str(),
157 (int)wstr.length(),
158 nullptr,
159 0,
160 nullptr,
161 nullptr);
162 if (!utf8Size)
163 return {}; // error
164
165 std::string utf8str(utf8Size, '\0');
166 if (!WideCharToMultiByte(CP_UTF8,
167 0,
168 wstr.c_str(),
169 (int)wstr.length(),
170 utf8str.data(),
171 (int)utf8str.size(),
172 nullptr,
173 nullptr))
174 return {}; // error
175
176 return utf8str;
177#else
178 return str;
179#endif
180}
181
182std::string ConsoleCPToUTF8(std::string str)
183{

Callers 2

loadMethod · 0.85
importLibToDatabaseFunction · 0.85

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected