本文整理汇总了C++中std::wstring::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::assign方法的具体用法?C++ wstring::assign怎么用?C++ wstring::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::wstring
的用法示例。
在下文中一共展示了wstring::assign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trylock
static int trylock() {
if ((lm->uiVersion == 1) || (lm->uiVersion == 2)) {
if (lm->dwcount != last_count) {
last_count = lm->dwcount;
last_tick = GetTickCount();
errno_t err = 0;
wchar_t buff[2048];
if (lm->name[0]) {
err = wcscpy_s(buff, 256, lm->name);
if (! err)
wsPluginName.assign(buff);
}
if (!err && lm->description[0]) {
err = wcscpy_s(buff, 2048, lm->description);
if (! err)
wsDescription.assign(buff);
}
if (err) {
wsPluginName.assign(L"Link");
wsDescription.clear();
return false;
}
return true;
}
}
return false;
}
示例2: trylock
static int trylock() {
if (lm == lm_invalid)
return false;
if ((lm->uiVersion == 1) || (lm->uiVersion == 2)) {
if (lm->ui32count != last_count) {
last_tick = GetTickCount();
last_count = lm->ui32count;
wchar_t buff[2048];
if (lm->name[0]) {
wcsncpy(buff, lm->name, 256);
buff[255] = 0;
wsPluginName.assign(buff);
}
if (lm->description[0]) {
wcsncpy(buff, lm->description, 2048);
buff[2047] = 0;
wsDescription.assign(buff);
}
return true;
}
}
return false;
}
示例3: rq
template<> bool ScriptInterface::FromJSVal<std::wstring>(JSContext* cx, JS::HandleValue v, std::wstring& out)
{
JSAutoRequest rq(cx);
WARN_IF_NOT(v.isString() || v.isNumber(), v); // allow implicit number conversions
JS::RootedString str(cx, JS::ToString(cx, v));
if (!str)
FAIL("Argument must be convertible to a string");
if (JS_StringHasLatin1Chars(str))
{
size_t length;
JS::AutoCheckCannotGC nogc;
const JS::Latin1Char* ch = JS_GetLatin1StringCharsAndLength(cx, nogc, str, &length);
if (!ch)
FAIL("JS_GetLatin1StringCharsAndLength failed");
out.assign(ch, ch + length);
}
else
{
size_t length;
JS::AutoCheckCannotGC nogc;
const char16_t* ch = JS_GetTwoByteStringCharsAndLength(cx, nogc, str, &length);
if (!ch)
FAIL("JS_GetTwoByteStringsCharsAndLength failed"); // out of memory
out.assign(ch, ch + length);
}
return true;
}
示例4: ResourcesDirGetDebugPath
void CSalsitaExtensionHelper::ResourcesDirGetDebugPath(const wchar_t *preprocessorDefinedPath, std::wstring &result)
{
result.assign(preprocessorDefinedPath);
std::replace(result.begin(), result.end(), L'/', L'\\');
std::wstring canonicalized;
canonicalized.resize(MAX_PATH+1);
PathCanonicalizeW((LPWSTR)canonicalized.c_str(), result.c_str());
result.assign(canonicalized.c_str());
ResourcesDirNormalize(result);
}
示例5: naStringFormatV
bool naStringFormatV( std::wstring& rstrOutput, const wchar_t* format, va_list ap)
{
wchar_t wszLocalBuffer[256];
va_list vaClone;
va_copy(vaClone, ap);
int nOutputSize = _vsnwprintf(wszLocalBuffer, sizeof(wszLocalBuffer)/sizeof(wszLocalBuffer[0]), format, vaClone);
va_end(vaClone);
if( nOutputSize < 0 )
return false;
if( nOutputSize < (sizeof(wszLocalBuffer)/sizeof(wszLocalBuffer[0]))) {
rstrOutput.assign( wszLocalBuffer, nOutputSize );
return true;
}
wchar_t* szDynamicBuffer = new wchar_t[nOutputSize+1];
va_copy(vaClone, ap);
nOutputSize = _vsnwprintf(szDynamicBuffer, nOutputSize+1, format, vaClone);
va_end(vaClone);
if( nOutputSize < 0 ) {
delete[] szDynamicBuffer;
return false;
}
rstrOutput.append( szDynamicBuffer, nOutputSize );
delete[] szDynamicBuffer;
return true;
}
示例6: ResourcesDirReadFromRegistry
bool CSalsitaExtensionHelper::ResourcesDirReadFromRegistry(HKEY hKey, const wchar_t *subKey, const wchar_t *valueName, std::wstring &result)
{
bool ret = false;
HKEY hkConfig;
result.erase();
if (RegOpenKeyExW(hKey, subKey, 0, KEY_READ, &hkConfig) == ERROR_SUCCESS)
{
DWORD valueType, valueLen = 0;
if (RegQueryValueExW(hkConfig, valueName, NULL, &valueType, NULL, &valueLen) == ERROR_SUCCESS && valueType == REG_SZ)
{
BYTE *buf = new BYTE[valueLen];
if (RegQueryValueExW(hkConfig, valueName, NULL, &valueType, buf, &valueLen) == ERROR_SUCCESS)
{
result.assign((const wchar_t *)buf);
ResourcesDirNormalize(result);
ret = true;
}
delete buf;
}
RegCloseKey(hkConfig);
}
return ret;
}
示例7:
bool MiscUtils::Val2WStr(const _variant_t& var, std::wstring& str)
{
bool bDone = true;
switch(var.vt)
{
case VT_BSTR:
case VT_LPSTR:
case VT_LPWSTR:
try
{
str.assign((LPCWSTR)(_bstr_t)var);
}
catch (...)
{
bDone = false;
AfxTrace(_T("Val2WStr failed\n"));
}
break;
case VT_EMPTY:
str.erase();
break;
default:
bDone = false;
break;
}
return bDone;
}
示例8: unlock
static void unlock() {
lm->ui32count = last_count = 0;
lm->uiVersion = 0;
lm->name[0] = 0;
wsPluginName.assign(L"Link");
wsDescription.clear();
}
示例9: GetVideoInfoURL
HRESULT URLParser::GetVideoInfoURL(URLParser::VIDEO_URL_PARSER eVideoURLParser, std::wstring& wstrURL, std::wstring& wstrVideoURL)
{
HRESULT hr = E_FAIL;
int iVdoIDStart = -1;
int iVdoIDEnd = -1;
std::wstring wstrVideoID;
if(std::wstring::npos != (iVdoIDStart = wstrURL.find(L"v=")))
{
iVdoIDStart += wcslen(L"v=");
iVdoIDEnd = wstrURL.find(L"&", iVdoIDStart);
if(std::wstring::npos != iVdoIDEnd)
{
// pick start to end
wstrVideoID = wstrURL.substr(iVdoIDStart, (iVdoIDEnd - iVdoIDStart));
}
else
{
// pick the entire string
wstrVideoID = wstrURL.substr(iVdoIDStart, (wstrURL.length() - iVdoIDStart));
}
}
if(0 != wstrVideoID.length())
{
wstrVideoURL.clear();
wstrVideoURL.assign(PRE_VIDEO_ID_URL_STRING);
wstrVideoURL.append(wstrVideoID);
wstrVideoURL.append(POST_VIDEO_ID_URL_STRING);
hr = S_OK;
}
return hr;
}
示例10: GetValue
bool CRegUtil::GetValue(const wchar_t* const name, std::wstring& strValue)
{
const int nSize = 1024;
std::vector<BYTE> buffer;
DWORD dwLength = 0;
DWORD dwType = REG_NONE;
buffer.resize(nSize);
void* pBuffer = &buffer[0];
LONG lResult = ::RegQueryValueEx(m_hKey, name, 0, &dwType, (LPBYTE)pBuffer, &dwLength);
if((lResult != ERROR_MORE_DATA && lResult != ERROR_SUCCESS)
|| (dwType != REG_SZ)
|| dwLength == 0)
{
return false;
}
if(lResult == ERROR_MORE_DATA)
{
buffer.resize(dwLength);
pBuffer = &buffer[0];
lResult = ::RegQueryValueEx(m_hKey, name, 0, &dwType, (LPBYTE)pBuffer, &dwLength);
}
if(lResult != ERROR_SUCCESS)
return false;
strValue.assign((const wchar_t*)pBuffer, dwLength / sizeof(wchar_t));
if(strValue.at(strValue.size() - 1) == 0)
strValue.resize(strValue.size() - 1);
return true;
}
示例11: DllMain
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) {
bool bCreated = false;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
wsPluginName.assign(L"Link");
hMapObject = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink");
if (hMapObject == NULL) {
hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(LinkedMem), L"MumbleLink");
bCreated = true;
if (hMapObject == NULL)
return false;
}
lm = (LinkedMem *) MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, 0);
if (lm == NULL) {
CloseHandle(hMapObject);
hMapObject = NULL;
return false;
}
if (bCreated)
memset(lm, 0, sizeof(LinkedMem));
break;
case DLL_PROCESS_DETACH:
if (lm) {
UnmapViewOfFile(lm);
lm = NULL;
}
if (hMapObject) {
CloseHandle(hMapObject);
hMapObject = NULL;
}
break;
}
return true;
}
示例12: ResourcesDirMakeUrl
void CSalsitaExtensionHelper::ResourcesDirMakeUrl(const wchar_t *resourcesDir, const wchar_t *relativeUrl, std::wstring &pageUrl)
{
pageUrl.assign(L"file:///");
pageUrl.append(resourcesDir);
ResourcesDirNormalize(pageUrl);
pageUrl.append(relativeUrl);
std::replace(pageUrl.begin(), pageUrl.end(), L'\\', L'/');
}
示例13: GetIndexOrName
void GetIndexOrName(PyObject *item, std::wstring& name, Py_ssize_t& i)
{
name.clear();
i = -1;
#ifndef IS_PY3K
if (PyString_Check(item))
{
char* s = PyString_AsString(item);
DWORD len = lstrlenA(s) + 1;
wchar_t* w = new wchar_t[len];
if (::MultiByteToWideChar(CP_ACP, 0, s, len, w, len) != len)
{
delete [] w;
throw MI::Exception(L"MultiByteToWideChar failed");
}
name.assign(w, len);
delete[] w;
}
else
#endif
if (PyUnicode_Check(item))
{
Py_ssize_t len = PyUnicode_GetSize(item) + 1;
wchar_t* w = new wchar_t[len];
if (PyUnicode_AsWideChar((PYUNICODEASVARCHARARG1TYPE*)item, w, len) < 0)
{
delete[] w;
throw MI::Exception(L"PyUnicode_AsWideChar failed");
}
name.assign(w, len);
delete[] w;
}
else if (PyIndex_Check(item))
{
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
if (i == -1 && PyErr_Occurred())
throw MI::Exception(L"Index error");
}
else
throw MI::Exception(L"Invalid name or index");
}
示例14: InitializeSearchPowershell
bool InitializeSearchPowershell(std::wstring &ps)
{
WCHAR pszPath[MAX_PATH]; /// by default , System Dir Length <260
if (SHGetFolderPathW(nullptr, CSIDL_SYSTEM, nullptr, 0, pszPath) != S_OK) {
return false;
}
ps.assign(pszPath);
ps.append(L"\\WindowsPowerShell\\v1.0\\powershell.exe");
return true;
}
示例15: tweetA
void tweetA(std::wstring edit){
char utf8[1000];
if (!edit.empty()) {
int n;
wchar_t ucs2[1000];
n = MultiByteToWideChar(CP_ACP, 0, edit.c_str(), edit.size(), ucs2, 1000);
n = WideCharToMultiByte(CP_UTF8, 0, ucs2, n, utf8, 1000, 0, 0);
edit.assign(utf8, n);
}
tweetTextA(utf8,init_key,init_secret);
}