int CDBCommandBuilderBase::GenerateSqlInsert(const IDBRecord& rec, tstring& buffer) { buffer.append(TEXT("INSERT INTO ")); WrapperIdentifier(TableSchema_->DBName.c_str(), buffer); buffer.append(TEXT(" (")); for (int i = 0; i < TableSchema_->Columns.size(); ++i) { WrapperIdentifier(TableSchema_->Columns[i].DBName.c_str(), buffer); buffer.append(TEXT(", ")); } *(buffer.end() - 2) = ')'; buffer.append(TEXT("VALUES (")); for (int i = 0; i < TableSchema_->Columns.size(); ++i) { WrapperValue(rec.GetField(i).c_str(), TableSchema_->Columns[i].DBType, buffer); buffer.append(TEXT(", ")); } *(buffer.end() - 2) = ')'; return 1; }
tstring format_rate(const IQuotesProvider *pProvider, MCONTACT hContact, const tstring &rsFrmt) { tstring sResult; for (tstring::const_iterator i = rsFrmt.begin(); i != rsFrmt.end();) { TCHAR chr = *i; switch (chr) { default: sResult += chr; ++i; break; case _T('\\'): ++i; if (i != rsFrmt.end()) { TCHAR t = *i; switch (t) { case _T('%'): sResult += _T("%"); break; case _T('t'): sResult += _T("\t"); break; case _T('n'): sResult += _T("\n"); break; case _T('\\'): sResult += _T("\\"); break; default: sResult += chr; sResult += t; break; } ++i; } else sResult += chr; break; case _T('%'): ++i; if (i != rsFrmt.end()) { chr = *i; byte nWidth = 0; if (::isdigit(chr)) { nWidth = chr - 0x30; ++i; if (i == rsFrmt.end()) { sResult += chr; break; } else chr = *i; } CQuotesProviderVisitorFormater visitor(hContact, chr, nWidth); pProvider->Accept(visitor); const tstring& s = visitor.GetResult(); sResult += s; ++i; } else sResult += chr; break; } } return sResult; }
tstring nf::Parser::ExtractPrefix(tstring const &CommandString) { //можем обойтись без регулярного выражения if (CommandString.empty()) return _T(""); tstring::const_iterator p = std::find(++CommandString.begin(), CommandString.end(), _T(':')); if (p == CommandString.end()) return _T(""); return tstring(CommandString.begin(), p + 1); }
std::wstring SystemWindowsClass::ToWString(const tstring &s) #endif { #ifdef _UNICODE string #else wstring #endif result(s.begin(), s.end()); // copy from one to another result.assign(s.begin(), s.end()); return result; }
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); }
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 EditorLoader::SaveLevel(const tstring& fileName) { if (fileName != _T("")) { string s(fileName.begin(), fileName.end()); m_pLevel->Serialize(s); } }
// HKEY_CLASSES_ROOT // FileMarker.AVI - AVI - Windows 기본 비디오 파일 // shell // Mark - Daum 팟플레이어의 재생목록(&I)에 추가하기 // command - "C:\Program Files (x86)\DAUM\PotPlayer\PotPlayer.exe" "%1" /ADD bool CRegisterMenu::Register(const tstring& strAppName, tstring strExt, tstring strMenu, tstring strMenuDisplay, tstring strCommand, tstring strDesc) { if (strAppName.empty() || strExt.empty() || strDesc.empty() || strMenu.empty() || strMenuDisplay.empty() || strCommand.empty()) return false; if (!RegisterExtKey(strExt, strMenu, strMenuDisplay, strCommand)) return false; // remove '.' strExt.erase(std::remove(strExt.begin(), strExt.end(), _T('.')), strExt.end()); // Uppercase extension CStringUtil::MakeUpper(strExt); tstring strAppExt = strAppName + _T(".") + strExt; LPCTSTR strSubKeys[] = { strAppExt.c_str(), _T("shell"), strMenu.c_str(), _T("command") }; LPCTSTR strValues[] = { strDesc.c_str(), _T(""), strMenuDisplay.c_str(), strCommand.c_str() }; tstring strSubKey; tstring strValue; for (int i = 0; i < _countof(strSubKeys); ++i) { strSubKey += strSubKeys[i]; strSubKey += _T("\\"); strValue = strValues[i]; if (!RegisterMenu(strSubKey, strValue)) return false; } // SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, NULL, NULL); return true; }
void TLvColumn::SetText(const tstring& text) { if (!IsRepresentable<int>(text.size() + 1)) throw TXOwl(_T("TLvColumn::SetText: The text argument is too large (>INT_MAX)")); Buffer.assign(text.begin(), text.end()); Buffer.push_back(_T('\0')); SetTextBuffer(&Buffer[0], static_cast<int>(Buffer.size())); }
std::string GetDefaultLanguage() { static std::string language; if (language.empty()) { const tstring tLanguage = GetString(IDS_LANGUAGE); language.assign(tLanguage.begin(), tLanguage.end()); } return language; }
bool CRegisterMenu::UnRegister(tstring strAppName, tstring strExt, tstring strMenu) { if ( strAppName.empty() || strExt.empty() || strMenu.empty()) return false; if (!UnRegisterExtKey(strExt, strMenu)) { return false; } // remove '.' strExt.erase(std::remove(strExt.begin(), strExt.end(), _T('.')), strExt.end()); // Uppercase extension CStringUtil::MakeUpper(strExt); tstring strAppExt = strAppName + _T(".") + strExt; return UnRegisterMenu(strAppExt); }
void litehtml::css_length::fromString( const tstring& str, const tstring& predefs, int defValue ) { // TODO: Make support for calc if(str.substr(0, 4) == _t("calc")) { m_is_predefined = true; m_predef = 0; return; } int predef = value_index(str.c_str(), predefs.c_str(), -1); if(predef >= 0) { m_is_predefined = true; m_predef = predef; } else { m_is_predefined = false; tstring num; tstring un; bool is_unit = false; for(tstring::const_iterator chr = str.begin(); chr != str.end(); chr++) { if(!is_unit) { if(t_isdigit(*chr) || *chr == _t('.') || *chr == _t('+') || *chr == _t('-')) { num += *chr; } else { is_unit = true; } } if(is_unit) { un += *chr; } } if(!num.empty()) { m_value = (float) t_strtod(num.c_str(), 0); m_units = (css_units) value_index(un.c_str(), css_units_strings, css_units_none); } else { // not a number so it is predefined m_is_predefined = true; m_predef = defValue; } } }
void SystemFrame::Colorize(const tstring& line, LONG Begin){ tstring::const_iterator start = line.begin(); tstring::const_iterator end = line.end(); boost::match_results<tstring::const_iterator> result; int pos=0; while(boost::regex_search(start, end, result, reg, boost::match_default)) { ctrlPad.SetSel(pos + Begin + result.position(), pos + Begin + result.position() + result.length()); ctrlPad.SetSelectionCharFormat(WinUtil::m_ChatTextServer); start = result[0].second; pos=pos+result.position() + result.length(); } }
string ChatCtrl::escapeUnicode(tstring str) { TCHAR buf[8]; memzero(buf, sizeof(buf)); int dist = 0; tstring::iterator i; while((i = std::find_if(str.begin() + dist, str.end(), std::bind2nd(std::greater<TCHAR>(), 0x7f))) != str.end()) { dist = (i+1) - str.begin(); // Random Acess iterators FTW snwprintf(buf, sizeof(buf), _T("%hd"), int(*i)); str.replace(i, i+1, _T("\\ud\\u") + tstring(buf) + _T("?")); memzero(buf, sizeof(buf)); } return Text::fromT(str); }
void CDBCommandBuilderBase::GenerateConditionStr(const IDBRecord& rec, const CDBRecordComparison& cmp, tstring& buffer) { if(cmp.KeyFields().size() > 0) { buffer.append(TEXT(" WHERE ")); for (int i = 0; i < cmp.KeyFields().size(); ++i) { int field = cmp.KeyFields()[i]; GenerateFieldConditionStr((*TableSchema_)[field], rec.GetField(field), buffer); buffer.append(TEXT(" AND ")); } *(buffer.end() - 4) = '\0'; } }
int CDBCommandBuilderBase::GenerateSqlUpdate(const IDBRecord& ori, const IDBRecord& cur, const CDBRecordComparison& cmp, tstring& buffer) { buffer.append(TEXT("UPDATE ")); WrapperIdentifier(TableSchema_->DBName.c_str(), buffer); buffer.append(TEXT(" SET ")); for (int i = 0; i < TableSchema_->Columns.size(); ++i) { GenerateFieldAssignmentStr(TableSchema_->Columns[i], cur.GetField(i), buffer); buffer.append(TEXT(", ")); } *(buffer.end() - 2) = ' '; GenerateConditionStr(ori, cmp, buffer); return 1; }
void texture_from_file(ID3D11Device* device, tstring filename, ID3D11ShaderResourceView** srv) { std::replace(filename.begin(), filename.end(), L'\\', L'/'); bool is_dds = filename.find(L".dds") != std::string::npos; try { if (!is_dds) stb_to_srv(device, to_string(filename).c_str(), srv); else dds_to_srv(device, filename, srv); tclog << L"Loading: " << filename << print_log_info(*srv) << std::endl; } catch (std::exception& e) { tcout << L"Failed to load: " << filename << std::endl; tcout << e.what() << std::endl; } }
/////////////////////////////////////////////////////////////////////////////// // The query->m_Search is filled out when provided. // bool TokenizeQuery( const tstring& queryString, std::vector< tstring >& tokens ) { const tregex parseTokens( s_TokenizeQueryString, std::tr1::regex::icase ); // parse once to tokenize then match again tsregex_iterator parseItr( queryString.begin(), queryString.end(), parseTokens ); tsregex_iterator parseEnd; tstring curToken; for ( ; parseItr != parseEnd; ++parseItr ) { const std::tr1::match_results<tstring::const_iterator>& tokenizeResults = *parseItr; curToken = tokenizeResults[1].matched ? Helium::MatchResultAsString( tokenizeResults, 1 ) : TXT( "" ); if ( !curToken.empty() ) { tokens.push_back( curToken ); } } return !tokens.empty(); }
BOOL CRegistryTool::StringToRootKey(tstring strKey,HKEY *hKey) { BOOL bSucceed = FALSE; transform(strKey.begin(),strKey.end(),strKey.begin(),_totupper); if(strKey.compare(_T("HKEY_CLASSES_ROOT"))==0) { *hKey = HKEY_CLASSES_ROOT; bSucceed = TRUE; } else if(strKey.compare(_T("HKEY_CURRENT_CONFIG"))==0) { *hKey = HKEY_CURRENT_CONFIG; bSucceed = TRUE; } else if(strKey.compare(_T("HKEY_CURRENT_USER"))==0) { *hKey = HKEY_CURRENT_USER; bSucceed = TRUE; } else if(strKey.compare(_T("HKEY_LOCAL_MACHINE"))==0) { *hKey = HKEY_LOCAL_MACHINE; bSucceed = TRUE; } else if(strKey.compare(_T("HKEY_PERFORMANCE_DATA")) ==0) { *hKey = HKEY_PERFORMANCE_DATA; bSucceed = TRUE; } else if(strKey.compare(_T("HKEY_USERS")) == 0) { *hKey = HKEY_USERS; bSucceed = TRUE; } return bSucceed; }
bool is_fixed_width(const tstring & font_name) { if (font_name.length() > 31) return false; HDC dc = GetDC(NULL); if (!dc) WIN_EXCEPT("Failed call to GetDC(NULL)."); LOGFONT lf = {}; lf.lfCharSet = DEFAULT_CHARSET; lf.lfPitchAndFamily = 0; // already checked length TCHAR * ptr = std::copy(font_name.begin(), font_name.end(), lf.lfFaceName); ASSERT(ptr <= (lf.lfFaceName + 32)); (void)ptr; bool is = false; EnumFontFamiliesEx(dc, &lf, reinterpret_cast<FONTENUMPROC>(EnumFontFamExProc), reinterpret_cast<LPARAM>(&is), 0); ReleaseDC(NULL, dc); return is; }
tstring::size_type tstring::find(char_type const* s, size_type pos, size_type n) const { if( size() == 0 ) { if( n == 0 ) return 0; else return npos; } TINFRA_ASSERT(pos == npos || pos <= this->size() ); tstring const other = tstring(s, n, false); const_iterator result = std::search( begin()+pos, end(), other.begin(), other.end()); if( result == end() ) return npos; else return result - begin(); }
tstring::size_type tstring_find_last(tstring const& subject, Predicate p, size_t pos) { const size_t npos = tstring::npos; if( subject.size() == 0 ) return npos; if( pos != npos && pos > subject.size() ) pos = subject.size()-1; TINFRA_ASSERT(pos == npos || pos < subject.size() ); const tstring::const_iterator begin = subject.begin(); tstring::const_iterator i = (pos == npos) ? subject.end()-1 : subject.begin() + pos; do { if( p(*i) ) // predicate true, then found return i - begin; } while( i-- != begin ); return npos; }
bool CPicture::Load(tstring sFilePathName) { bool bResult = false; bIsIcon = false; lpIcons = NULL; //CFile PictureFile; //CFileException e; FreePictureData(); // Important - Avoid Leaks... // No-op if no file specified if (sFilePathName.empty()) return true; // Load & initialize the GDI+ library if available HMODULE hGdiPlusLib = AtlLoadSystemLibraryUsingFullPath(_T("gdiplus.dll")); if (hGdiPlusLib && GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL) == Ok) { bHaveGDIPlus = true; } // Since we loaded the gdiplus.dll only to check if it's available, we // can safely free the library here again - GdiplusStartup() loaded it too // and reference counting will make sure that it stays loaded until GdiplusShutdown() // is called. FreeLibrary(hGdiPlusLib); // Attempt to load using GDI+ if available if (bHaveGDIPlus) { pBitmap = new Bitmap(sFilePathName.c_str(), FALSE); GUID guid; pBitmap->GetRawFormat(&guid); if (pBitmap->GetLastStatus() != Ok) { delete pBitmap; pBitmap = NULL; } // gdiplus only loads the first icon found in an icon file // so we have to handle icon files ourselves :( // Even though gdiplus can load icons, it can't load the new // icons from Vista - in Vista, the icon format changed slightly. // But the LoadIcon/LoadImage API still can load those icons, // at least those dimensions which are also used on pre-Vista // systems. // For that reason, we don't rely on gdiplus telling us if // the image format is "icon" or not, we also check the // file extension for ".ico". std::transform(sFilePathName.begin(), sFilePathName.end(), sFilePathName.begin(), ::tolower); bIsIcon = (guid == ImageFormatIcon) || (wcsstr(sFilePathName.c_str(), L".ico") != NULL) || (wcsstr(sFilePathName.c_str(), L".cur") != NULL); bIsTiff = (guid == ImageFormatTIFF) || (_tcsstr(sFilePathName.c_str(), _T(".tiff")) != NULL); m_Name = sFilePathName; if (bIsIcon) { // Icon file, get special treatment... if (pBitmap) { // Cleanup first... delete (pBitmap); pBitmap = NULL; bIsIcon = true; } CAutoFile hFile = CreateFile(sFilePathName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile) { BY_HANDLE_FILE_INFORMATION fileinfo; if (GetFileInformationByHandle(hFile, &fileinfo)) { lpIcons = new BYTE[fileinfo.nFileSizeLow]; DWORD readbytes; if (ReadFile(hFile, lpIcons, fileinfo.nFileSizeLow, &readbytes, NULL)) { // we have the icon. Now gather the information we need later if (readbytes >= sizeof(ICONDIR)) { // we are going to open same file second time so we have to close the file now hFile.CloseHandle(); LPICONDIR lpIconDir = (LPICONDIR)lpIcons; if ((lpIconDir->idCount) && ((lpIconDir->idCount * sizeof(ICONDIR)) <= fileinfo.nFileSizeLow)) { try { bResult = false; nCurrentIcon = 0; hIcons = new HICON[lpIconDir->idCount]; // check that the pointers point to data that we just loaded if (((BYTE*)lpIconDir->idEntries > (BYTE*)lpIconDir) && (((BYTE*)lpIconDir->idEntries) + (lpIconDir->idCount * sizeof(ICONDIRENTRY)) < ((BYTE*)lpIconDir) + fileinfo.nFileSizeLow)) { m_Width = lpIconDir->idEntries[0].bWidth; m_Height = lpIconDir->idEntries[0].bHeight; bResult = true; for (int i=0; i<lpIconDir->idCount; ++i) { hIcons[i] = (HICON)LoadImage(NULL, sFilePathName.c_str(), IMAGE_ICON, lpIconDir->idEntries[i].bWidth, lpIconDir->idEntries[i].bHeight, LR_LOADFROMFILE); if (hIcons[i] == NULL) { // if the icon couldn't be loaded, the data is most likely corrupt delete [] lpIcons; lpIcons = NULL; bResult = false; break; } } } } catch (...) { delete [] lpIcons; lpIcons = NULL; bResult = false; } } else { delete [] lpIcons; lpIcons = NULL; bResult = false; } } else { delete [] lpIcons; lpIcons = NULL; bResult = false; } } else { delete [] lpIcons; lpIcons = NULL; } } } } else if (pBitmap) // Image loaded successfully with GDI+ { m_Height = pBitmap->GetHeight(); m_Width = pBitmap->GetWidth(); bResult = true; } // If still failed to load the file... if (!bResult) { // Attempt to load the FreeImage library as an optional DLL to support additional formats // NOTE: Currently just loading via FreeImage & using GDI+ for drawing. // It might be nice to remove this dependency in the future. HMODULE hFreeImageLib = LoadLibrary(_T("FreeImage.dll")); // FreeImage DLL functions typedef const char* (__stdcall *FreeImage_GetVersion_t)(void); typedef int (__stdcall *FreeImage_GetFileType_t)(const TCHAR *filename, int size); typedef int (__stdcall *FreeImage_GetFIFFromFilename_t)(const TCHAR *filename); typedef void* (__stdcall *FreeImage_Load_t)(int format, const TCHAR *filename, int flags); typedef void (__stdcall *FreeImage_Unload_t)(void* dib); typedef int (__stdcall *FreeImage_GetColorType_t)(void* dib); typedef unsigned (__stdcall *FreeImage_GetWidth_t)(void* dib); typedef unsigned (__stdcall *FreeImage_GetHeight_t)(void* dib); typedef void (__stdcall *FreeImage_ConvertToRawBits_t)(BYTE *bits, void *dib, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown); //FreeImage_GetVersion_t FreeImage_GetVersion = NULL; FreeImage_GetFileType_t FreeImage_GetFileType = NULL; FreeImage_GetFIFFromFilename_t FreeImage_GetFIFFromFilename = NULL; FreeImage_Load_t FreeImage_Load = NULL; FreeImage_Unload_t FreeImage_Unload = NULL; //FreeImage_GetColorType_t FreeImage_GetColorType = NULL; FreeImage_GetWidth_t FreeImage_GetWidth = NULL; FreeImage_GetHeight_t FreeImage_GetHeight = NULL; FreeImage_ConvertToRawBits_t FreeImage_ConvertToRawBits = NULL; if (hFreeImageLib) { bool exportsValid = true; //FreeImage_GetVersion = (FreeImage_GetVersion_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_GetVersion@0", valid); FreeImage_GetWidth = (FreeImage_GetWidth_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_GetWidth@4", exportsValid); FreeImage_GetHeight = (FreeImage_GetHeight_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_GetHeight@4", exportsValid); FreeImage_Unload = (FreeImage_Unload_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_Unload@4", exportsValid); FreeImage_ConvertToRawBits = (FreeImage_ConvertToRawBits_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_ConvertToRawBits@32", exportsValid); #ifdef UNICODE FreeImage_GetFileType = (FreeImage_GetFileType_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_GetFileTypeU@8", exportsValid); FreeImage_GetFIFFromFilename = (FreeImage_GetFIFFromFilename_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_GetFIFFromFilenameU@4", exportsValid); FreeImage_Load = (FreeImage_Load_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_LoadU@12", exportsValid); #else FreeImage_GetFileType = (FreeImage_GetFileType_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_GetFileType@8", exportsValid); FreeImage_GetFIFFromFilename = (FreeImage_GetFIFFromFilename_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_GetFIFFromFilename@4", exportsValid); FreeImage_Load = (FreeImage_Load_t)s_GetProcAddressEx(hFreeImageLib, "_FreeImage_Load@12", exportsValid); #endif //const char* version = FreeImage_GetVersion(); // Check the DLL is using compatible exports if (exportsValid) { // Derive file type from file header. int fileType = FreeImage_GetFileType(sFilePathName.c_str(), 0); if (fileType < 0) { // No file header available, attempt to parse file name for extension. fileType = FreeImage_GetFIFFromFilename(sFilePathName.c_str()); } // If we have a valid file type if (fileType >= 0) { void* dib = FreeImage_Load(fileType, sFilePathName.c_str(), 0); if (dib) { unsigned width = FreeImage_GetWidth(dib); unsigned height = FreeImage_GetHeight(dib); // Create a GDI+ bitmap to load into... pBitmap = new Bitmap(width, height, PixelFormat32bppARGB); if (pBitmap && pBitmap->GetLastStatus() == Ok) { // Write & convert the loaded data into the GDI+ Bitmap Rect rect(0, 0, width, height); BitmapData bitmapData; if (pBitmap->LockBits(&rect, ImageLockModeWrite, PixelFormat32bppARGB, &bitmapData) == Ok) { FreeImage_ConvertToRawBits((BYTE*)bitmapData.Scan0, dib, bitmapData.Stride, 32, 0xff << RED_SHIFT, 0xff << GREEN_SHIFT, 0xff << BLUE_SHIFT, FALSE); pBitmap->UnlockBits(&bitmapData); m_Width = width; m_Height = height; bResult = true; } else // Failed to lock the destination Bitmap { delete pBitmap; pBitmap = NULL; } } else // Bitmap allocation failed { delete pBitmap; pBitmap = NULL; } FreeImage_Unload(dib); dib = NULL; } } } FreeLibrary(hFreeImageLib); hFreeImageLib = NULL; } } }
bool Parse(const IQuotesProvider* pProvider, const tstring& rsFrmt, MCONTACT hContact) { m_abValueFlags[0] = false; m_abValueFlags[1] = false; m_nComparison = NonValid; bool bValid = true; int nCurValue = 0; for (tstring::const_iterator i = rsFrmt.begin(); i != rsFrmt.end() && bValid && nCurValue < NumValues;) { TCHAR chr = *i; switch (chr) { default: if (false == std::isspace(chr)) bValid = false; else ++i; break; case _T('%'): ++i; if (i != rsFrmt.end()) { TCHAR t = *i; ++i; CQuotesProviderVisitorTendency visitor(hContact, t); pProvider->Accept(visitor); if (false == visitor.IsValid()) { bValid = false; } else { double d = visitor.GetResult(); m_adValues[nCurValue] = d; m_abValueFlags[nCurValue] = true; ++nCurValue; } } else bValid = false; break; case _T('>'): m_nComparison = Greater; ++i; break; case _T('<'): m_nComparison = Less; ++i; break; case _T('='): switch (m_nComparison) { default: bValid = false; break; case NonValid: m_nComparison = Equal; break; case Greater: m_nComparison = GreaterOrEqual; break; case Less: m_nComparison = LessOrEqual; break; } ++i; break; } } return (bValid && IsValid()); }
void ChatCtrl::FormatEmoticonsAndLinks(tstring& sMsg, tstring& sMsgLower, LONG lSelBegin, bool bUseEmo) { if(!sMsg.size()) return; LONG lSelEnd = lSelBegin + sMsg.size(); // hightlight all URLs and make them clickable for(size_t i = 0; i < (sizeof(protocols) / sizeof(protocols[0])); ++i) { size_t linkStart = sMsgLower.find(protocols[i]); bool isMagnet = (protocols[i] == _T("magnet:?")); while(linkStart != tstring::npos) { size_t linkEnd = linkStart + protocols[i].size(); try { // TODO: complete regexp for URLs std::tr1::wregex reg; //[+]PPA Исправил регулярное выражение для коррктного поиска урлов в VC++ 2010 (пример урла - magnet:?xt=urn:tree:tiger:V3LVT4CSASPLNHRG6DOORAD2SDSBBANIKEI7XHI&xl=260524251&dn=cstrike_full_v.35_(4156).exe ) if(isMagnet) // magnet links have totally indifferent structure than classic URL // -/?%&=~#'\\w\\.\\+\\*\\(\\) reg.assign(_T("^(\\w)+=[:\\w]+(&(\\w)+=[\\S]*)*[^\\s<>{}\"']+"), std::tr1::regex_constants::icase); else reg.assign(_T("^([@\\w-]+(\\.)*)+(:[\\d]+)?(/[\\S]*)*[^\\s<>{}\"']+"), std::tr1::regex_constants::icase); tstring::const_iterator start = sMsg.begin(); tstring::const_iterator end = sMsg.end(); std::tr1::match_results<tstring::const_iterator> result; if(std::tr1::regex_search(start + linkEnd, end, result, reg, std::tr1::regex_constants::match_default)) { dcassert(!result.empty()); linkEnd += result.length(0); SetSel(lSelBegin + linkStart, lSelBegin + linkEnd); if(isMagnet) { tstring cURL = ((tstring)(result[0])); tstring::size_type dn = cURL.find(_T("dn=")); if(dn != tstring::npos) { string sFileName = Util::encodeURI(Text::fromT(cURL).substr(dn + 3), true); int64_t filesize = Util::toInt64(Text::fromT(cURL.substr(cURL.find(_T("xl=")) + 3, cURL.find(_T("&")) - cURL.find(_T("xl="))))); tstring shortLink = Text::toT(sFileName) + _T(" (") + Util::formatBytesW(filesize) + _T(")"); sMsg.replace(linkStart, linkEnd - linkStart, shortLink.c_str()); std::transform(&sMsgLower.replace(linkStart, linkEnd - linkStart, shortLink.c_str())[linkStart], &sMsgLower[linkEnd], &sMsgLower[linkStart], _totlower); setText(shortLink); linkEnd = linkStart + shortLink.size(); SetSel(lSelBegin + linkStart, lSelBegin + linkEnd); magnets[shortLink] = _T("magnet:?") + cURL; } } SetSelectionCharFormat(WinUtil::m_TextStyleURL); } } catch(...) { } linkStart = sMsgLower.find(protocols[i], linkEnd); } } // insert emoticons if(bUseEmo && emoticonsManager->getUseEmoticons()) { const Emoticon::List& emoticonsList = emoticonsManager->getEmoticonsList(); tstring::size_type lastReplace = 0; uint8_t smiles = 0; while(true) { tstring::size_type curReplace = tstring::npos; Emoticon* foundEmoticon = NULL; for(Emoticon::Iter emoticon = emoticonsList.begin(); emoticon != emoticonsList.end(); ++emoticon) { tstring::size_type idxFound = sMsg.find((*emoticon)->getEmoticonText(), lastReplace); if(idxFound < curReplace || curReplace == tstring::npos) { curReplace = idxFound; foundEmoticon = (*emoticon); } } if(curReplace != tstring::npos && smiles < MAX_EMOTICONS) { CHARFORMAT2 cfSel; cfSel.cbSize = sizeof(cfSel); lSelBegin += (curReplace - lastReplace); lSelEnd = lSelBegin + foundEmoticon->getEmoticonText().size(); SetSel(lSelBegin, lSelEnd); GetSelectionCharFormat(cfSel); if(!(cfSel.dwEffects & CFE_LINK)) { CImageDataObject::InsertBitmap(GetOleInterface(), foundEmoticon->getEmoticonBmp(cfSel.crBackColor)); ++smiles; ++lSelBegin; } else lSelBegin = lSelEnd; lastReplace = curReplace + foundEmoticon->getEmoticonText().size(); } else break; } } }
std::string ConvertTString(const tstring & value) { return string(value.begin(), value.end()); }
tstring lowercase(const tstring &str) { tstring result = str; transform(str.begin(), str.end(), result.begin(), ToLower()); return result; }
bool dir_reader::matches(const tstring& name, const tstring& spec) { tstring::const_iterator name_itr = name.begin(); tstring::const_iterator name_end = name.end(); tstring::const_iterator spec_itr = spec.begin(); tstring::const_iterator spec_end = spec.end(); tstring::const_iterator last_good_spec = spec_end; tstring::const_iterator last_good_name = name_end; while (name_itr != name_end && spec_itr != spec_end) { switch (*spec_itr) { case _T('?'): // question mark mathes one char name_itr++; spec_itr++; break; case _T('*'): // double asterisk is the same as a single asterisk while (*spec_itr == _T('*')) { spec_itr++; // asterisk at the end of the spec matches the end of the name if (spec_itr == spec_end) return true; } // remember last good name and spec for prematurely stopped asterisk last_good_spec = spec_itr; last_good_name = name_itr; break; default: // Jim Park: This should work since tolower is templated with Chartype. if (::tolower(*name_itr) != ::tolower(*spec_itr)) { if (last_good_spec != spec_end) { // matched wrong part of the name, try again spec_itr = last_good_spec; name_itr = ++last_good_name; } else { // no match and no asterisk to use return false; } } else { // remember last good name for prematurely stopped asterisk last_good_name = name_itr; spec_itr++; name_itr++; if (spec_itr == spec_end && name_itr != name_end && last_good_spec != spec_end) { // asterisk hasn't matched enough, keep matching spec_itr = last_good_spec; } } break; } } // skip any redundant asterisks and periods at the end of the name while (spec_itr != spec_end) { if (*spec_itr != _T('.') && *spec_itr != _T('*')) { break; } spec_itr++; } // return true only if managed to match everything return name_itr == name_end && spec_itr == spec_end; }
string ConvertToString(const tstring& str) { return string(str.begin(), str.end()); }
void Path::MakeNative( tstring& path ) { std::replace( path.begin(), path.end(), s_InternalPathSeparator, Helium::PathSeparator ); }