MCPcopy Create free account
hub / github.com/dobin/RedEdr / wstring2string

Function wstring2string

RedEdrShared/utils.cpp:148–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146
147
148std::string wstring2string(std::wstring& wide_string) {
149 if (wide_string.empty()) {
150 return "";
151 }
152
153 // Determine the size needed for the UTF-8 buffer
154 int size_needed = WideCharToMultiByte(CP_UTF8, 0, wide_string.c_str(), -1, nullptr, 0, nullptr, nullptr);
155 if (size_needed <= 0) {
156 throw std::runtime_error("Failed to calculate size for UTF-8 string.");
157 }
158
159 // Allocate the buffer and perform the conversion
160 std::string utf8_string(size_needed - 1, '\0'); // Exclude the null terminator
161 WideCharToMultiByte(CP_UTF8, 0, wide_string.c_str(), -1, &utf8_string[0], size_needed, nullptr, nullptr);
162
163 return utf8_string;
164}
165
166
167/*

Callers 8

TEST_CLASSFunction · 0.85
TEST_METHODFunction · 0.85
do_outputMethod · 0.85
getRecordingsAsJsonFunction · 0.85
KrabsEtwEventToJsonStrFunction · 0.85
ProcessEnumerateModulesFunction · 0.85
GetRemoteUnicodeStrFunction · 0.85
GetProcessNameByPidFunction · 0.85

Calls 1

emptyMethod · 0.80

Tested by 2

TEST_CLASSFunction · 0.68
TEST_METHODFunction · 0.68