MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / ToString

Function ToString

src/shared/util.cpp:54–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54std::string ToString(const std::wstring& source, bool utf8)
55{
56 std::string result;
57 if (source.length() > 0) {
58 UINT codepage = CP_UTF8;
59 if (!utf8) {
60 codepage = AreFileApisANSI() ? GetACP() : GetOEMCP();
61 }
62 int sizeRequired = ::WideCharToMultiByte(codepage, 0, &source[0], -1, nullptr, 0,
63 nullptr, nullptr);
64 if (sizeRequired == 0) {
65 throw windows_error("failed to convert string to multibyte");
66 }
67 // the size returned by WideCharToMultiByte contains zero termination IF -1 is
68 // specified for the length. we don't want that \0 in the string because then the
69 // length field would be wrong. Because madness
70 result.resize(sizeRequired - 1, '\0');
71 ::WideCharToMultiByte(codepage, 0, &source[0], (int)source.size(), &result[0],
72 sizeRequired, nullptr, nullptr);
73 }
74
75 return result;
76}
77
78std::wstring ToWString(const std::string& source, bool utf8)
79{

Callers 4

UsvfsConnectorMethod · 0.85
addFromBSAMethod · 0.85
dumpMethod · 0.85

Calls 2

windows_errorClass · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected