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

Method AssignStringFromCodePage

source/var.cpp:1234–1261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1232
1233
1234ResultType Var::AssignStringFromCodePage(LPCSTR aBuf, int aLength, UINT aCodePage)
1235{
1236#ifndef UNICODE
1237 // Not done since some callers have a more effective optimization in place:
1238 //if (aCodePage == CP_ACP || aCodePage == GetACP())
1239 // Avoid unnecessary conversion (ACP -> UTF16 -> ACP).
1240 //return AssignString(aBuf, aLength, true, false);
1241 // Convert from specified codepage to UTF-16,
1242 CStringWCharFromChar wide_buf(aBuf, aLength, aCodePage);
1243 // then back to the active codepage:
1244 return AssignStringToCodePage(wide_buf, wide_buf.GetLength(), CP_ACP);
1245#else
1246 int iLen = MultiByteToWideChar(aCodePage, 0, aBuf, aLength, NULL, 0);
1247 if (iLen > 0) {
1248 if (!AssignString(NULL, iLen, true))
1249 return FAIL;
1250 LPWSTR aContents = Contents(TRUE);
1251 iLen = MultiByteToWideChar(aCodePage, 0, aBuf, aLength, (LPWSTR) aContents, iLen);
1252 aContents[iLen] = 0;
1253 if (!iLen)
1254 return FAIL;
1255 SetCharLength(iLen);
1256 }
1257 else
1258 Assign(); // Return value is ambiguous in this case: may be zero-length input or an error. For simplicity, return OK.
1259 return OK;
1260#endif
1261}
1262
1263
1264

Callers 1

BIF_DECLFunction · 0.80

Calls 1

GetLengthMethod · 0.80

Tested by

no test coverage detected