MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / StringWCharToUTF8

Function StringWCharToUTF8

source/StringConv.cpp:41–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41LPCSTR StringWCharToUTF8(LPCWSTR sWChar, CStringA &sUTF8, int iChars/* = -1*/)
42{
43 if (!sWChar)
44 return NULL;
45
46 sUTF8.Empty();
47 int iLen = WideCharToMultiByte(CP_UTF8, 0, sWChar, iChars, NULL, 0, NULL, NULL);
48 if (iLen > 0) {
49 LPSTR sBuf = sUTF8.GetBufferSetLength(iLen);
50 WideCharToMultiByte(CP_UTF8, 0, sWChar, iChars, sBuf, iLen, NULL, NULL);
51 sUTF8.ReleaseBufferSetLength(sBuf[iLen - 1] ? iLen : iLen - 1);
52 return (iLen > 0) ? sUTF8.GetString() : NULL;
53 }
54
55 return (*sWChar != 0) ? sUTF8.GetString() : NULL;
56}
57
58LPCSTR StringCharToUTF8(LPCSTR sChar, CStringA &sUTF8, int iChars/* = -1*/, UINT codepage/* = CP_ACP*/)
59{

Callers 2

CStringUTF8FromWCharMethod · 0.85
StringCharToUTF8Function · 0.85

Calls 2

GetBufferSetLengthMethod · 0.80
GetStringMethod · 0.80

Tested by

no test coverage detected