void getPlayerName(std::wstring &identity) { unsigned long mask, base, offset, current, shortGUID, testGUID; mask = getInt32(nameStorePtr + nameMaskOffset); base = getInt32(nameStorePtr + nameBaseOffset); shortGUID = g_playerGUID & 0xffffffff; // Only half the guid is used to check for a hit if (mask == 0xffffffff) { identity.clear(); return; } offset = 12 * (mask & shortGUID); // select the appropriate linked list current=getInt32(base + offset + 8); // ptr to lower half of GUID of first element offset = getInt32(base + offset); // this plus 4 is the offset for the next element if ((current == 0) || (current & 0x1)) { identity.clear(); return; } testGUID=getInt32(current); while (testGUID != shortGUID) { current=getInt32(current + offset + 4); if ((current == 0) || (current & 0x1)) { identity.clear(); return; } testGUID=getInt32(current); } getWString(current + nameStringOffset, identity); }
HRESULT EEDEnumPointer::EvaluateNext( const EvalOptions& options, EvalResult& result, std::wstring& name, std::wstring& fullName ) { if ( mCountDone >= GetCount() ) return E_FAIL; HRESULT hr = S_OK; RefPtr<IEEDParsedExpr> parsedExpr; name.clear(); fullName.clear(); fullName.append( L"*(" ); fullName.append( mParentExprText ); fullName.append( 1, L')' ); hr = ParseText( fullName.c_str(), mTypeEnv, mStrTable, parsedExpr.Ref() ); if ( FAILED( hr ) ) return hr; hr = parsedExpr->Bind( options, mBinder ); if ( FAILED( hr ) ) return hr; hr = parsedExpr->Evaluate( options, mBinder, result ); if ( FAILED( hr ) ) return hr; mCountDone++; return S_OK; }
/* @brief マルチバイト文字列をUNICODEに変換する @param[in] src ソース文字列(char *) @param[in] dst 出力文字列(wstring) @return 変換した文字数 */ size_t strutil::char2wstring(const char* src, std::wstring& dst) { #ifdef WIN32 dst.clear(); size_t len = strlen(src); if(len == 0) return 0; wchar_t* unic = new wchar_t[len + 1]; setlocale(LC_ALL, LOCALE_JP); size_t num; mbstowcs_s(&num, unic, len + 1, src, len + 1); dst = unic; delete[] unic; return num; #else dst.clear(); size_t len = strlen(src); if(len == 0) return 0; wchar_t* unic = new wchar_t[len + 1]; setlocale(LC_ALL, LOCALE_JP); size_t num = mbstowcs(unic, src, len+1); if (num == (size_t)-1) { dst.clear(); } else { dst = unic; } delete[] unic; return num; #endif }
void Reset() { wMenuMask = 0; iInsertPosition = 0; iMenuCmdBegin = -1; strTargetURL.clear(); strSelectedText.clear(); strLinkHrefURL.clear(); strLinkText.clear(); }
bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr) { wstr.clear(); try { utf8::utf8to16(utf8str.c_str(), utf8str.c_str()+utf8str.size(), std::back_inserter(wstr)); } catch(std::exception const&) { wstr.clear(); return false; } return true; }
/*static*/ void WStringCodec::decode(DBusMessageIter& iter, std::wstring& str) { str.clear(); DBusMessageIter _iter; simppl_dbus_message_iter_recurse(&iter, &_iter, DBUS_TYPE_ARRAY); int count = #if DBUS_MAJOR_VERSION == 1 && DBUS_MINOR_VERSION < 9 dbus_message_iter_get_array_len(&_iter) / sizeof(uint32_t); #else dbus_message_iter_get_element_count(&iter); #endif if (count > 0) str.reserve(count); while(dbus_message_iter_get_arg_type(&_iter) != 0) { uint32_t t; Codec<uint32_t>::decode(_iter, t); str.push_back((wchar_t)t); } // advance to next element dbus_message_iter_next(&iter); }
bool COfficeFileFormatChecker::isPdfFormatFile (unsigned char* pBuffer,int dwBytes, std::wstring & documentID) { if (pBuffer == NULL) return false; documentID.clear(); if (dwBytes < 1) return false; pBuffer[dwBytes - 1] = '\0'; char* pFirst = strstr( (char*)pBuffer, "%PDF-" ); if( NULL != pFirst ) { pFirst = strstr( (char*)pBuffer, "%DocumentID " ); if( NULL != pFirst ) { pFirst += 12; char* pLast = strstr( pFirst, " "); if( NULL != pLast ) { std::string s(pFirst, pLast - pFirst); documentID = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)s.c_str(), s.length()); } } return true; } return false; }
bool touchmind::shell::Clipboard::_PasteTEXT(HWND hWnd, std::wstring &text) { if (!OpenClipboard(hWnd)) { text.clear(); return false; } HGLOBAL hg = GetClipboardData(CF_UNICODETEXT); if (hg == nullptr) { text.clear(); return false; } wchar_t *strClip = static_cast<wchar_t *>(GlobalLock(hg)); text.assign(strClip); GlobalUnlock(hg); CloseClipboard(); return true; }
// RegEnumKeyEx // returns ERROR_NO_MORE_ITEMS or ERROR_SUCCESS // if maxNameSize == 0, then we will compute it for you. Use it between calls on the same key for performance inline LONG RegEnumKeyExX(HKEY hKey, DWORD dwIndex, std::wstring& outName, DWORD& maxNameSize) { FILETIME temp; LONG ret; std::vector<wchar_t> buf; DWORD size; outName.clear(); // get maximum subkey name length. if(!maxNameSize) { if(ERROR_SUCCESS != (ret = RegQueryInfoKeyW(hKey, 0, 0, 0, 0, &maxNameSize, 0, 0, 0, 0, 0, 0))) { return ret; } maxNameSize += 2;// for safety } buf.resize(maxNameSize); // make the call size = static_cast<DWORD>(buf.size()); ret = RegEnumKeyExW(hKey, dwIndex, buf.data(), &size, 0, 0, 0, &temp); if(ret == ERROR_SUCCESS) { outName = buf.data(); } return ret; }
HRESULT AccessibleObject::GetRole(std::wstring& role, long child_id, IAccessible* acc) { DWORD role_id = 0; HRESULT hr = GetRole(role_id, child_id, acc); if (hr != S_OK) return hr; UINT role_length = GetRoleText(role_id, nullptr, 0); LPTSTR buffer = (LPTSTR)malloc((role_length + 1) * sizeof(TCHAR)); if (buffer != nullptr) { GetRoleText(role_id, buffer, role_length + 1); if (buffer) { role = buffer; } else { role.clear(); } free(buffer); } else { return E_OUTOFMEMORY; } return S_OK; }
xsize_t xdata_buffer::read(std::wstring& str) { if (current_offset_ >= byte_array_->size()) { return 0; } wchar_t* p = (wchar_t*)(byte_array_->data() + current_offset_); if (*p == L'\0') { current_offset_ += sizeof(wchar_t); str.clear(); return sizeof(wchar_t); } xsize_t rest_of_bytes = byte_array_->size() - current_offset_; xsize_t str_size = 0; wchar_t* e = p; while (*e != L'\0' && str_size < rest_of_bytes) ++ e, str_size += sizeof(wchar_t); str = std::wstring(p, e); xsize_t consumed = str_size + ((str_size < rest_of_bytes) ? (*e == L'\0' ? sizeof(wchar_t) : 0) : 0); current_offset_ += consumed; return consumed; }
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; }
void GetTextFromHtmlFragment(std::wstring& text, LPCTSTR startFragment, LPCTSTR endFragment) { ASSERT(startFragment != NULL); ASSERT(endFragment != NULL); text.clear(); BOOL bInTag = FALSE; for (LPCTSTR pos = startFragment; pos < endFragment; pos++) { if (*pos == 0) break; switch (*pos) { case '<': bInTag = TRUE; break; case '>': bInTag = FALSE; break; default: if (!bInTag) text += *pos; } } if (!text.empty()) { ReplaceHtmlEntities(text); trim(text, _T(" \t\n\r")); } }
void SetSize(int w, int h) { m_image->Resize(w, h); m_col=w/m_fontsize*2; m_row=h/m_fontsize; m_text.clear(); }
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; }
void GNS_to_wstring(int region, const char *word, std::wstring &output) { int len = strlen(word); uchar ch; unsigned short unicode; output.clear(); for (int i = 0; i < len; i++) { ch = (uchar) word[i]; if (ch < 128) unicode = ch; else { if (region == 1) unicode = region1[ch-128]; else if (region == 2) unicode = region2[ch-128]; else if (region == 3) unicode = region3[ch-128]; else // TODO: other 3 regions unicode = region3[ch-128]; if (unicode == 0x0000) unicode = '?'; } output += unicode; } }
bool COfficeFileFormatChecker::isMS_OFFCRYPTOFormatFile (POLE::Storage * storage, std::wstring & documentID) { if (storage == NULL) return false; documentID.clear(); bool result = false; std::list<std::wstring> entries = storage->entries(L"DataSpaces"); if (entries.size() > 0) { result = true; } if ( storage->exists(L"EncryptionInfo") && storage->exists(L"EncryptedPackage")) { result = true; } if (result) { POLE::Stream stream(storage, L"DocumentID"); std::string sData; sData.resize(stream.size()); if (stream.read((BYTE*)sData.c_str(), stream.size()) > 0) { documentID = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sData.c_str(), sData.length()); } } return result; }
//------------------------------------------------------------------------------------------------------ // // FUNCTION: GetChildXmlVal(std::wstring& pszVal, wchar* pszDefault = NULL) // // PURPOSE : overloaded function that sets the current xml node to it's first non-comment child node // and then that node's string value // //------------------------------------------------------------------------------------------------------ bool CvXMLLoadUtility::GetChildXmlVal(std::wstring& pszVal, wchar* pszDefault) { if (pszDefault) { pszVal = pszDefault; } else { pszVal.clear(); } // if we successfully set the current xml node to it's first child node if (gDLL->getXMLIFace()->SetToChild(m_pFXml)) { // skip to the next non-comment node if (SkipToNextVal()) { // get the string value of the current xml node gDLL->getXMLIFace()->GetLastNodeValue(m_pFXml,pszVal); return true; } // otherwise we can't find a non-comment node on this level so we will FAssert and return false else { FAssertMsg(false , "Error in GetChildXmlVal function, unable to find the next non-comment node"); return false; } } // otherwise there are no child nodes but we were expecting them so FAssert and return false else { FAssertMsg(false , "Error in GetChildXmlVal function, unable to find a child node"); return false; } }
bool UTF8Charset::decode(std::wstring &result, const std::string &bytes, int offset, int length) { result.clear(); unsigned char b1, b2, b3, b4; for (int i = 0; i < length; ) { b1 = bytes[i++] & 0xFF; switch (UTF8_BYTES[b1]) { case 1: result.append(1, b1); break; case 2: b2 = bytes[i++]; result.append(1, ((b1 & 0x1f) << 6) | (b2 & 0x3f)); break; case 3: b2 = bytes[i++]; b3 = bytes[i++]; result.append(1, ((b1 & 0x1f) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3f)); break; case 4: b2 = bytes[i++]; b3 = bytes[i++]; b4 = bytes[i++]; result.append(1, (((b1 & 0x1f) << 18) | ((b2 & 0x3f) << 12) | ((b3 & 0x1f) << 6) | (b4 & 0x1f) - 0x10000) / 0x400 + 0xd800); break; } } return true; }
bool ServiceContract::Resolve(const std::wstring &uri, std::wstring &out_uriTemplate, std::vector<std::wstring> &out_args) const { out_uriTemplate.clear(); if (!boost::ends_with(uri, "/")) { for (Impl::Contracts_t::const_iterator it = m_pimpl->Contracts.begin(); it != m_pimpl->Contracts.end(); ++it) { if (boost::starts_with(uri, it->first)) { std::wstring args(uri.substr(it->first.size())); std::size_t argsCount = 0; std::vector<std::wstring> vec; if (args.find(L"/") != std::wstring::npos) { boost::split(vec, args, boost::is_any_of(L"/")); for (std::vector<std::wstring>::const_iterator vecIt = vec.begin(); vecIt != vec.end(); ++vecIt) { if (!(*vecIt).empty()) { out_args.push_back(*vecIt); ++argsCount; } } } if (it->second.second == argsCount) { out_uriTemplate = it->second.first; return true; } } } } return false; }
//------------------------------------------------------------------------------------------------------ // // FUNCTION: GetXmlVal(std::wstring& pszVal, wchar* pszDefault = NULL) // // PURPOSE : Get the string value of the current xml node or the next non-comment xml node if the // current node is a comment node // //------------------------------------------------------------------------------------------------------ bool CvXMLLoadUtility::GetXmlVal(std::wstring& pszVal, wchar* pszDefault) { if (pszDefault) { pszVal = pszDefault; } else { pszVal.clear(); } // skip to the next non-comment node if (SkipToNextVal()) { // get the string value of the current xml node gDLL->getXMLIFace()->GetLastNodeValue(m_pFXml,pszVal); return true; } // otherwise we can't find a non-comment node on this level so we will FAssert and return false else { FAssertMsg(false , "Error in GetXmlVal function, unable to find the next non-comment node"); return false; } }
HRESULT ComReg::ComRegGetModuleFileName(HMODULE h, std::wstring& result) { DWORD n = 256; //number of TCHARS for (;;) { void* const pv = _alloca(n * sizeof(wchar_t)); wchar_t* const buf = (wchar_t*)pv; const DWORD dw = GetModuleFileNameW(h, buf, n); if (dw == 0) //error { result.clear(); const DWORD e = GetLastError(); return HRESULT_FROM_WIN32(e); } if (dw >= n) //truncation { n *= 2; continue; } result = buf; return S_OK; } }
static void unlock() { lm->ui32count = last_count = 0; lm->uiVersion = 0; lm->name[0] = 0; wsPluginName.assign(L"Link"); wsDescription.clear(); }
bool ConvertUTF8toWide(const char *Source, std::wstring &Result) { if (!Source) { Result.clear(); return true; } return ConvertUTF8toWide(llvm::StringRef(Source), Result); }
bool CDownloadThread::TranslanteToBreakDownloadName(const std::wstring& strPath, std::wstring& strDesc) { if (strPath.empty ()) return false; strDesc.clear (); if( wcsrchr(strPath.c_str(), L'\\') ) { wchar_t wcsName[MAX_PATH] = {0}; wcscpy_s(wcsName, _countof(wcsName), strPath.c_str() ); *( wcsrchr(wcsName, L'\\')+1 ) = L'\0'; strDesc = wcsName; // 得到文件名称 std::wstring strTp = strPath; strTp = strTp.substr(strDesc.length (), strPath.length ()); int dwLen =0; wchar_t uBuf[1000] = {0}; base64_encode(( unsigned char *)strTp.c_str(),strTp.size(), ( unsigned char *)uBuf, &dwLen); if (strTp.find (L".") > 0) strTp = strTp.substr (0, strTp.find (L".")); strDesc += uBuf; strDesc += L"."; strDesc += strTp; strDesc += L".mh"; return true; } return false; }
void InstallationManager::mapToArchive(const DirectoryTree::Node *node, std::wstring path, FileData * const *data) { if (path.length() > 0) { // when using a long windows path (starting with \\?\) we apparently can have redundant // . components in the path. This wasn't a problem with "regular" path names. if (path == L".") { path.clear(); } else { path.append(L"\\"); } } for (DirectoryTree::const_leaf_iterator iter = node->leafsBegin(); iter != node->leafsEnd(); ++iter) { std::wstring temp = path + iter->getName().toStdWString(); data[iter->getIndex()]->addOutputFileName(temp.c_str()); } for (DirectoryTree::const_node_iterator iter = node->nodesBegin(); iter != node->nodesEnd(); ++iter) { std::wstring temp = path + (*iter)->getData().name.toStdWString(); if ((*iter)->getData().index != -1) { data[(*iter)->getData().index]->addOutputFileName(temp.c_str()); } mapToArchive(*iter, temp, data); } }
//////////////////////////////////////////////////////////////////////////////// /// ResFont //////////////////////////////////////////////////////////////////////////////// void ResFont::HGEFont::ReadDefine(const std::wstring& data, std::unordered_map<wchar_t, f2dGlyphInfo>& out, std::wstring& tex) { out.clear(); tex.clear(); std::vector<std::wstring> tLines; fcyStringHelper::StringSplit(data, L"\n", true, tLines); for (auto& i : tLines) { i = fcyStringHelper::Trim(i); } // 第一行必须是HGEFONT if (tLines.size() <= 1 || tLines[0] != L"[HGEFONT]") throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); for (size_t i = 1; i < tLines.size(); ++i) { wstring& tLine = tLines[i]; if (tLine.size() == 0) continue; wstring::size_type tPos; if (string::npos == (tPos = tLine.find_first_of(L"="))) throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); wstring tKey = tLine.substr(0, tPos); wstring tValue = tLine.substr(tPos + 1, tLine.size() - tPos - 1); if (tKey == L"Bitmap") tex = tValue; else if (tKey == L"Char") { wchar_t c; int c_hex; float x, y, w, h, left_offset, right_offset; if (7 != swscanf(tValue.c_str(), L"\"%c\",%f,%f,%f,%f,%f,%f", &c, &x, &y, &w, &h, &left_offset, &right_offset)) { if (7 != swscanf(tValue.c_str(), L"%X,%f,%f,%f,%f,%f,%f", &c_hex, &x, &y, &w, &h, &left_offset, &right_offset)) throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); c = static_cast<wchar_t>(c_hex); } // 计算到f2d字体偏移量 f2dGlyphInfo tInfo = { fcyRect(x, y, x + w, y + h), fcyVec2(w, h), fcyVec2(-left_offset, h), fcyVec2(w + left_offset + right_offset, 0) }; if (out.find(c) != out.end()) throw fcyException("ResFont::HGEFont::readDefine", "Duplicated character defination."); out.emplace(c, tInfo); } else throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); } if (tex.empty()) throw fcyException("ResFont::HGEFont::readDefine", "Bad file format."); }
void clear() { csi = false; state = State::Ground; postfix = '\0'; parms.fill(0); inside.clear(); parm_count = 0; }
/* * Trim chTarget from the right of string s. */ void StringUtils::STLTrimRight(std::wstring& s, wchar_t chTarget) { std::wstring::size_type n = s.find_last_not_of( chTarget ); if( n == std::wstring::npos ) s.clear(); else s = s.substr( 0, n+1 ); }
HRESULT EEDEnumStruct::EvaluateNext( const EvalOptions& options, EvalResult& result, std::wstring& name, std::wstring& fullName ) { if ( mCountDone >= GetCount() ) return E_FAIL; HRESULT hr = S_OK; RefPtr<Declaration> decl; RefPtr<IEEDParsedExpr> parsedExpr; if ( !mMembers->Next( decl.Ref() ) ) return E_FAIL; mCountDone++; name.clear(); fullName.clear(); if ( decl->IsBaseClass() ) { if ( !NameBaseClass( decl, name, fullName ) ) return E_FAIL; } else { if ( !NameRegularMember( decl, name, fullName ) ) return E_FAIL; } hr = ParseText( fullName.c_str(), mTypeEnv, mStrTable, parsedExpr.Ref() ); if ( FAILED( hr ) ) return hr; hr = parsedExpr->Bind( options, mBinder ); if ( FAILED( hr ) ) return hr; hr = parsedExpr->Evaluate( options, mBinder, result ); if ( FAILED( hr ) ) return hr; return S_OK; }