static tstring formatIntegerValue(uint64 value) { typedef tstring::reverse_iterator rev_iter; typedef tstring::const_reverse_iterator c_rev_iter; const tstring rawResult = Core::format<uint64>(value); const size_t numDigits = (rawResult[0] != TXT('-')) ? rawResult.length() : (rawResult.length()-1); const tstring separator = getGroupSeparator(); const size_t numSeps = (numDigits-1) / 3; const size_t total = rawResult.length() + (numSeps * separator.length()); tstring result = tstring(total, TXT(' ')); c_rev_iter it = rawResult.rbegin(); c_rev_iter end = rawResult.rend(); size_t digits = 0; size_t seps = 0; rev_iter output = result.rbegin(); while (it != end) { *output++ = *it++; if ( ((++digits % 3) == 0) && (seps++ != numSeps) ) output = std::copy(separator.rbegin(), separator.rend(), output); } return result; }
bool CDDELink::ParseLink(const tstring& link, tstring& service, tstring& topic, tstring& item) { size_t serviceBegin = 0; size_t serviceEnd = link.find_first_of('|', serviceBegin); if ( (serviceEnd == tstring::npos) || (serviceEnd == serviceBegin) ) return false; size_t topicBegin = serviceEnd + 1; size_t topicEnd = link.find_first_of('!', topicBegin); if ( (topicEnd == tstring::npos) || (topicEnd == topicBegin) ) return false; size_t itemBegin = topicEnd + 1; size_t itemEnd = link.length(); if (itemEnd == itemBegin) return false; service = link.substr(serviceBegin, serviceEnd - serviceBegin); topic = link.substr(topicBegin, topicEnd - topicBegin); item = link.substr(itemBegin, itemEnd - itemBegin); ASSERT(service.length() != 0); ASSERT(topic.length() != 0); ASSERT(item.length() != 0); return true; }
void CGrottoHUD::PaintHintText(const tstring& sHint) { float flTextWidth = glgui::CLabel::GetTextWidth(sHint, sHint.length(), "sans-serif", 18); float flFontHeight = glgui::CLabel::GetFontHeight("sans-serif", 18); glgui::CBaseControl::PaintRect(GetWidth()/2+200 - 5, GetHeight()/2 - 5, flTextWidth + 10, flFontHeight + 10, Color(50, 50, 50, 150), 2); glgui::CLabel::PaintText(sHint, sHint.length(), "sans-serif", 18, GetWidth()/2+200, GetHeight()/2); }
void tstring2string(const tstring& src, std::string& dst) { #ifdef UNICODE { char* newStr = ""; int _len = 0; if (!src.empty()) { _len = WideCharToMultiByte(CP_UTF8, 0, src.c_str(), src.length(), NULL, 0, NULL, NULL); newStr = new char[_len + 1]; WideCharToMultiByte(CP_UTF8, 0, src.c_str(), src.length(), newStr, _len, NULL, NULL); newStr[_len] = 0; //Null terminator } dst = newStr; delete newStr; } #else dst = src; #endif }
// /// Sets the values for the DEVNAMES structure. // void TPrintDialog::TData::SetDevNames(const tstring& driver, const tstring& device, const tstring& output) { ClearDevNames(); // Calculate the required buffer size, as the number of characters incl. null-terminators, // and the resulting total size, in bytes, of the DEVNAMES structure including trailing strings. // Then allocate and lock the required amount of global memory. // const int n = driver.length() + 1 + device.length() + 1 + output.length() + 1; const int size = sizeof(DEVNAMES) + (n * sizeof(tchar)); HDevNames = ::GlobalAlloc(GHND, size); DevNames = static_cast<DEVNAMES*>(::GlobalLock(HDevNames)); DevNames->wDefault = false; // Calculate the offsets to the strings within DEVNAMES. // Then copy the given names into DEVNAMES (actually, behind the fixed part of DEVNAMES). // // NB! Offsets are in character counts. Here we assume the size of the fixed part of DEVNAMES is divisible // by the character size. Otherwise the driver name will overwrite the last byte of the fixed part. // But DEVNAMES is divisible and forever set in stone, so we don't need to consider an odd struct size. // CHECK(sizeof(DEVNAMES) % sizeof(tchar) == 0); const LPTSTR base = reinterpret_cast<LPTSTR>(DevNames); const LPTSTR pDriver = reinterpret_cast<LPTSTR>(DevNames + 1); // Jump past the the fixed part, assuming even struct size. const LPTSTR pDevice = pDriver + driver.length() + 1; // Jump past the preceding string, including null-terminator. const LPTSTR pOutput = pDevice + device.length() + 1; DevNames->wDriverOffset = static_cast<WORD>(pDriver - base); DevNames->wDeviceOffset = static_cast<WORD>(pDevice - base); DevNames->wOutputOffset = static_cast<WORD>(pOutput - base); _tcscpy(pDriver, driver.c_str()); _tcscpy(pDevice, device.c_str()); _tcscpy(pOutput, output.c_str()); }
void XmlTreeView::PostProcessSummary(tstring& str) { // Replace empty strings. if (str.empty()) { str = TXT("(empty)"); return; } bool bWhitespaceOnly = true; // Find if only whitespace characters. for (tstring::const_iterator it = str.begin(); ((it != str.end()) && bWhitespaceOnly); ++it) { if (!tisspace(static_cast<utchar>(*it))) bWhitespaceOnly = false; } // Replace "invisible" strings. if (bWhitespaceOnly) { str = TXT("(whitespace)"); return; } // Trim string. if (str.length() > App.m_nDefMaxItemLen) { str.erase(App.m_nDefMaxItemLen, str.length()-App.m_nDefMaxItemLen); str += TXT("..."); } }
void CFTPProtocolOutput::OnSendCommand(const tstring& strCommand) { if( strCommand.length()==0 ) return; if( strCommand.length()>4 && strCommand.substr(5)==_T("PASS ") ) WriteLine(_T("< PASS **********\n"), RGB(0, 0, 255)); else WriteLine(_T("> ") + CString(strCommand.c_str()) + _T("\n"), RGB(0, 0, 255)); }
// /// Sets the maximum horizontal extent for the list view window. // void TListBoxView::SetExtent(const tstring& str) { if (str.length() == 0) return; TClientDC clientDC(*this); TSize extent = clientDC.GetTextExtent(str, str.length()); extent.cx += 2; // room for focus rectangle if (extent.cx > MaxWidth) SetHorizontalExtent(MaxWidth = extent.cx); }
void ChatCtrl::FormatChatLine(const tstring& sMyNick, tstring& sText, CHARFORMAT2& cf, bool isMyMessage, const tstring& sAuthor, LONG lSelBegin, bool bUseEmo) { // Set text format tstring sMsgLower(sText.length(), NULL); std::transform(sText.begin(), sText.end(), sMsgLower.begin(), _totlower); LONG lSelEnd = lSelBegin + sText.size(); SetSel(lSelBegin, lSelEnd); SetSelectionCharFormat(isMyMessage ? WinUtil::m_ChatTextMyOwn : cf); // highlight all occurences of my nick long lMyNickStart = -1, lMyNickEnd = -1; size_t lSearchFrom = 0; tstring sNick(sMyNick.length(), NULL); std::transform(sMyNick.begin(), sMyNick.end(), sNick.begin(), _totlower); bool found = false; while((lMyNickStart = sMsgLower.find(sNick, lSearchFrom)) != tstring::npos) { lMyNickEnd = lMyNickStart + (long)sNick.size(); SetSel(lSelBegin + lMyNickStart, lSelBegin + lMyNickEnd); SetSelectionCharFormat(WinUtil::m_TextStyleMyNick); lSearchFrom = lMyNickEnd; found = true; } if(found) { if( !SETTING(CHATNAMEFILE).empty() && !BOOLSETTING(SOUNDS_DISABLED) && !sAuthor.empty() && (stricmp(sAuthor.c_str(), sNick) != 0)) { ::PlaySound(Text::toT(SETTING(CHATNAMEFILE)).c_str(), NULL, SND_FILENAME | SND_ASYNC); } } // highlight all occurences of favourite users' nicks FavoriteManager::FavoriteMap ul = FavoriteManager::getInstance()->getFavoriteUsers(); for(FavoriteManager::FavoriteMap::const_iterator i = ul.begin(); i != ul.end(); ++i) { const FavoriteUser& pUser = i->second; lSearchFrom = 0; sNick = Text::toT(pUser.getNick()); std::transform(sNick.begin(), sNick.end(), sNick.begin(), _totlower); while((lMyNickStart = sMsgLower.find(sNick, lSearchFrom)) != tstring::npos) { lMyNickEnd = lMyNickStart + (long)sNick.size(); SetSel(lSelBegin + lMyNickStart, lSelBegin + lMyNickEnd); SetSelectionCharFormat(WinUtil::m_TextStyleFavUsers); lSearchFrom = lMyNickEnd; } } // Links and smilies FormatEmoticonsAndLinks(sText, sMsgLower, lSelBegin, bUseEmo); }
bool OdbcCommand::Execute(const tstring & szSQL) { if (!Open()) return false; #ifdef USE_SQL_TRACE TRACE((szSQL + _T("\n")).c_str()); #endif if (!BindParameters()) return false; SQLRETURN result = SQLExecDirect(m_hStmt, (SQLTCHAR *)szSQL.c_str(), szSQL.length()); if (!(result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO || result == SQL_NO_DATA)) { if (m_odbcConnection != nullptr) m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, (TCHAR *)szSQL.c_str(), _T("Failed to execute statement.")); else m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt); Close(); return false; } if (!MoveNext()) MoveNextSet(); return true; }
bool OdbcCommand::Execute(const tstring & szSQL) { if (!Open()) return false; #ifdef _DEBUG OutputDebugString((szSQL + _T("\n")).c_str()); #endif if (!BindParameters()) return false; if (!SQL_SUCCEEDED(SQLExecDirect(m_hStmt, (SQLTCHAR *)szSQL.c_str(), szSQL.length()))) { if (m_odbcConnection != NULL) m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, (TCHAR *)szSQL.c_str(), _T("Failed to execute statement.")); else m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt); Close(); return false; } if (!MoveNext()) MoveNextSet(); return true; }
bool CRegisterMenu::RegisterMenu(const tstring& strSubKey, const tstring& strValue) { HKEY hKey; DWORD strValueSize = strValue.empty() ? 0 : (strValue.length() + 1) * sizeof(TCHAR); if (RegOpenKeyEx(HKEY_CLASSES_ROOT, strSubKey.c_str(), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS ) { if (!strValue.empty()) RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)strValue.c_str(), strValueSize); RegCloseKey(hKey); } else { DWORD disp = REG_CREATED_NEW_KEY; if (RegCreateKeyEx(HKEY_CLASSES_ROOT, strSubKey.c_str(), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp) == ERROR_SUCCESS ) { if (!strValue.empty()) RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)strValue.c_str(), strValueSize); RegCloseKey(hKey); } } return true; }
CTokenizer::CTokenizer(const tstring& p_Str, const tstring& p_Delimiters) { const tstring::size_type len = p_Str.length(); tstring::size_type i = 0; while(i < len) { // eat leading whitespace i = p_Str.find_first_not_of(p_Delimiters, i); if(i == tstring::npos) return; // nothing left but white space // find the end of the token tstring::size_type j = p_Str.find_first_of(p_Delimiters, i); // push token if(j == tstring::npos) { m_Tokens.push_back(p_Str.substr(i)); return; } else m_Tokens.push_back(p_Str.substr(i, j - i)); // set up for next loop i = j + 1; } }
HRESULT WINAPI GameEnv::OpenEnv(const tstring whichPath) { if (NULL != pInstance) //检查是否已经初始化 { mainEnv = pInstance; return E_HANDLE; } if (_T('\\') == whichPath[whichPath.length() - 1]) //检查结尾反斜杠符 { ErrorHandler(ERROR_RES_Unknown, _T(__FUNCTION__)); return E_FAIL; } if (!IsFolderExist(whichPath)) //检查路径是否存在 { ErrorHandler(ERROR_RES_MissingPath, _T(__FUNCTION__)); return E_FAIL; } PGameRes pRes = OpenResFiles(whichPath); if (NULL != pRes) //检查资源文件完整性 { pInstance = new GameEnv(pRes); mainEnv = pInstance; return S_OK; } return E_FAIL; }
uint64_t UserInfoSimple::inputSlotTime() { static tstring deftext = _T("00:30"); LineDlg dlg; dlg.description = TSTRING(EXTRA_SLOT_TIME_FORMAT); dlg.title = TSTRING(EXTRA_SLOT_TIMEOUT); dlg.line = deftext; if (dlg.DoModal() == IDOK) { deftext = dlg.line; unsigned int n = 0; for (size_t i = 0; i < deftext.length(); i++) // TODO: cleanup. { if (deftext[i] == L':') n++; } unsigned int d, h, m; switch (n) { case 1: if (swscanf(deftext.c_str(), L"%u:%u", &h, &m) == 2) return (h * 3600 + m * 60); break; case 2: if (swscanf(deftext.c_str(), L"%u:%u:%u", &d, &h, &m) == 3) return (d * 3600 * 24 + h * 3600 + m * 60); break; } ::MessageBox(GetForegroundWindow(), CTSTRING(INVALID_TIME_FORMAT), CTSTRING(ERRORS), MB_OK | MB_ICONERROR); } return 0; }
void get_text(TCHAR *text, size_t max_length) { #ifndef USE_GDI value.copy(text, std::min(max_length - 1, value.length())); #else ::GetWindowText(hWnd, text, max_length); #endif }
Filepath::Filepath(const tstring & full_path) : m_Path(EMPTY_STRING) , m_File(EMPTY_STRING) { int32 dotCounter(0); for(uint32 i = 0; i < full_path.size(); ++i) { if(full_path[i] == _T('.')) { ++dotCounter; } } if(dotCounter > 1) { Logger::GetInstance()->Log(LogLevel::Error, _T("Please don't use . in your filename (except for the file extension)")); } auto index = full_path.find_last_of('/'); if(index == tstring::npos) { index = full_path.find_last_of('\\'); } if(index != tstring::npos) { index += 1; m_Path = full_path.substr(0,index); m_File = full_path.substr(index, full_path.length() - index); } else { m_File = full_path; } }
void CRenderingContext::RenderText(const tstring& sText, unsigned iLength, FTFont* pFont) { TAssert(m_pShader); if (!m_pShader) return; CRenderContext& oContext = GetContext(); if (iLength == -1) iLength = sText.length(); TAssert(m_pShader->m_iPositionAttribute >= 0); TAssert(m_pShader->m_aiTexCoordAttributes[0] >= 0); if (!oContext.m_bProjectionUpdated) SetUniform("mProjection", oContext.m_mProjection); if (!oContext.m_bViewUpdated) SetUniform("mView", oContext.m_mView); // Take the position out and let FTGL do it. It looks sharper that way. Matrix4x4 mTransformations = oContext.m_mTransformations; Vector vecPosition = mTransformations.GetTranslation(); mTransformations.SetTranslation(Vector()); SetUniform("mGlobal", mTransformations); oContext.m_bProjectionUpdated = oContext.m_bViewUpdated = oContext.m_bTransformUpdated = true; ftglSetAttributeLocations(m_pShader->m_iPositionAttribute, m_pShader->m_aiTexCoordAttributes[0]); pFont->Render(sText.c_str(), iLength, FTPoint(vecPosition.x, vecPosition.y, vecPosition.z)); }
void CmdDlg::prettify(tstring &text) { try { const tstring search(_T("\n")), replace(_T("\r\n")); // http://stackoverflow.com/a/14678800/98528 tstring::size_type pos = 0; while ((pos = text.find(search, pos)) != tstring::npos) { text.replace(pos, search.length(), replace); pos += replace.length(); } text += replace; } catch (...) { text.clear(); } }
bool Enumeration::GetBitfieldValue(const tstring& str, uint32_t& value) const { if ( str.length() >= 1024 ) { HELIUM_BREAK(); return false; } tchar_t tmp[1024]; _tcscpy( tmp, str.c_str() ); std::vector< tstring > strs; tchar_t seps[] = TXT("|"); tchar_t *token = _tcstok( tmp, seps ); while( token != NULL ) { strs.push_back(token); /* Get next token: */ token = _tcstok( NULL, seps ); } return GetBitfieldValue(strs, value); }
//레지스트리에 문자열을 기록 BOOL CUtil::RegSetString( HKEY hKeyRoot, tstring strSubKey, tstring strItem, tstring strValue) { HKEY hKey; DWORD dwType=REG_SZ, dwSize=16000; // 98 때문 if (RegOpenKeyEx(hKeyRoot, strSubKey.c_str(), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) { // 2000에서 오류로 dwSize 대신 문자열 길이로 변경 RegSetValueEx(hKey, strItem.c_str(), 0, dwType, (unsigned char *)strValue.c_str(), (strValue.length() + 1) * sizeof(TCHAR)); RegCloseKey(hKey); return TRUE; } else { DWORD disp = REG_CREATED_NEW_KEY; if (RegCreateKeyEx(hKeyRoot, strSubKey.c_str(), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp) == ERROR_SUCCESS ) { // 2000에서 오류로 dwSize 대신 문자열 길이로 변경 RegSetValueEx(hKey, strItem.c_str(), 0, dwType, (unsigned char *)strValue.c_str(), (strValue.length() + 1) * sizeof(TCHAR)); RegCloseKey(hKey); return TRUE; } } return FALSE; }
static bool ReadTextFile(Path path, tstring &buffer) try { /* auto-detect the character encoding, to be able to parse XCSoar 6.0 task files */ FileLineReader reader(path, Charset::AUTO); long size = reader.GetSize(); if (size > 65536) return false; else if (size < 0) size = 4096; buffer.reserve(size); const TCHAR *line; while ((line = reader.ReadLine()) != nullptr) { if (buffer.length() > 65536) /* too long */ return false; buffer.append(line); buffer.append(_T("\n")); } return true; } catch (const std::runtime_error &) { return false; }
static bool ReadTextFile(const TCHAR *path, tstring &buffer) { /* auto-detect the character encoding, to be able to parse XCSoar 6.0 task files */ FileLineReader reader(path, ConvertLineReader::AUTO); if (reader.error()) return false; long size = reader.size(); if (size > 65536) return false; else if (size < 0) size = 4096; buffer.reserve(size); const TCHAR *line; while ((line = reader.read()) != NULL) { if (buffer.length() > 65536) /* too long */ return false; buffer.append(line); buffer.append(_T("\n")); } return true; }
// construct \ref data content void ShellCache::CPathFilter::AddEntry(const tstring& s, bool include) { static wchar_t pathbuf[MAX_PATH * 4] = { 0 }; if (s.empty()) return; TCHAR lastChar = *s.rbegin(); SEntry entry; entry.hasSubFolderEntries = false; entry.recursive = lastChar != L'?'; entry.included = include ? tristate_true : tristate_false; entry.subPathIncluded = include == entry.recursive ? tristate_true : tristate_false; entry.path = s; if ((lastChar == L'?') || (lastChar == L'*')) entry.path.erase(s.length() - 1); if (!entry.path.empty() && (*entry.path.rbegin() == L'\\')) entry.path.erase(entry.path.length() - 1); auto ret = ExpandEnvironmentStrings(entry.path.c_str(), pathbuf, _countof(pathbuf)); if ((ret > 0) && (ret < _countof(pathbuf))) entry.path = pathbuf; data.push_back(entry); }
void ProxyStub::Package(const tstring& data, void*& pDataPool) { TCHAR* pData = static_cast<TCHAR*>(pDataPool); _tcscpy(pData, data.c_str()); pDataPool = static_cast<void*>(pData + data.length() + 1); }
void ProxyStub::UnPackage(void*& pDataPool, tstring& data) { TCHAR* pData = static_cast<TCHAR*>(pDataPool); data = pData; pDataPool = static_cast<void*>(pData + data.length() + 1); }
void GetHashInfo(tstring id, std::vector<std::wstring> & info) { while(id.size() > 0) { size_t pos = id.find(L'-'); tstring substr = id.substr(0, pos == tstring::npos ? id.length() : pos); info.push_back(substr); if(pos == tstring::npos) id = L""; else { ++pos; id = id.substr(pos, id.length() - pos); } } }
// /// Returns the extent of a given string using this particular font in a /// particular DC. // TSize TFont::GetTextExtent(TDC& dc, const tstring& text) const { dc.SelectObject(*this); TSize size = dc.GetTextExtent(text, static_cast<int>(text.length())); // TODO: Widen parameter type to avoid this narrowing cast. dc.RestoreFont(); return size; }
void PathX::GetExtension(const tstring& path, tstring& outExtension) { tstring::size_type pos = path.find_last_of(extension); if (pos == tstring::size_type(-1)) { outExtension.clear(); return; } else if(pos == tstring::size_type(path.length()-1)) { outExtension.clear(); return; } else { outExtension = path.substr(pos+1, path.length()); return; } }
void PathX::GetFileName(const tstring& path, tstring& outFileName) { tstring::size_type pos = path.find_last_of(separator); if (pos == tstring::size_type(-1)) { outFileName = path; return; } else if(pos == tstring::size_type(path.length()-1)) { outFileName.clear(); return; } else { outFileName = path.substr(pos+1, path.length()); return; } }