/////////////////////////////////////////////////////////////////////////////// // 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 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); }
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(); }
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; }
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; } } }
void Path::MakeNative( tstring& path ) { std::replace( path.begin(), path.end(), s_InternalPathSeparator, Helium::PathSeparator ); }
std::string TCharToOem(const tstring& tText) { std::string result(tText.begin(), tText.end()); ::CharToOem(tText.c_str(), &(result[0])); return result; }
StoreCertificate::StoreCertificate( Win32CertificateLocation certStoreLocation, Win32CertificateStore certStore, const tstring & certName) : mStore(0) { std::wstring wStoreName; switch (certStore) { case Cs_AddressBook: wStoreName = L"AddressBook"; break; case Cs_AuthRoot: wStoreName = L"AuthRoot"; break; case Cs_CertificateAuthority: wStoreName = L"CA"; break; case Cs_Disallowed: wStoreName = L"Disallowed"; break; case Cs_My: wStoreName = L"MY"; break; case Cs_Root: wStoreName = L"Root"; break; case Cs_TrustedPeople: wStoreName = L"TrustedPeople"; break; case Cs_TrustedPublisher: wStoreName = L"TrustedPublisher"; break; default: RCF_ASSERT(0 && "Invalid certificate store value."); } DWORD dwFlags = 0; switch (certStoreLocation) { case Cl_CurrentUser: dwFlags = CERT_SYSTEM_STORE_CURRENT_USER; break; case Cl_LocalMachine: dwFlags = CERT_SYSTEM_STORE_LOCAL_MACHINE; break; default: RCF_ASSERT(0 && "Invalid certificate store location value."); } mStore = CertOpenStore( (LPCSTR) CERT_STORE_PROV_SYSTEM, X509_ASN_ENCODING, 0, dwFlags, &wStoreName[0]); DWORD dwErr = GetLastError(); RCF_VERIFY( mStore, RCF::Exception( _RcfError_CryptoApiError("CertOpenStore()"), dwErr, RCF::RcfSubsystem_Os)); std::wstring wCertName(certName.begin(), certName.end()); DWORD dwFindType = CERT_FIND_SUBJECT_STR; PCCERT_CONTEXT pStoreCert = CertFindCertificateInStore( mStore, X509_ASN_ENCODING, 0, dwFindType, wCertName.c_str(), NULL); dwErr = GetLastError(); RCF_VERIFY( pStoreCert, RCF::Exception( _RcfError_CryptoApiError("CertFindCertificateInStore()"), dwErr, RCF::RcfSubsystem_Os)); mpCert = pStoreCert; }
bool is_number(const tstring &s) { return !s.empty() && std::find_if(s.begin(), s.end(), [](TCHAR c) { return !_istdigit(c); }) == s.end(); }
void makeUpper(tstring& str) { transform(str.begin(), str.end(), str.begin(), toupper); }
int32 CBrainMemory::RetrieveText(int64 MeaningID,tstring& Text,bool Nest){ int64 CurrentRoomValue,RoomType; int64 CurrentID = MeaningID; //首先得到意义空间的信息 if(!GetRoomInfo(MeaningID,CurrentRoomValue,RoomType))return 0; if(!Nest){ //首次外部调用时检查MeaningID代表记忆是否为可读的文字信息,嵌套调用则忽略 if(UnReadable(CurrentRoomValue))return 0; } //向上漫游,找到父空间空间的ID和逻辑明文,得记忆的形ID CppSQLite3Query Result = LBrainQuery("*",CurrentRoomValue,LB_CHILD_ID,CurrentID); if(Result.eof())return 0; CurrentID = Result.getInt64Field(0); if(CurrentID == ROOT_SPACE)return 0; CurrentRoomValue = Result.getInt64Field(1); //总是其他空间的空间识别ID //如果是字符,则可以确定所取文本应该是token int ch = IDToChar(CurrentRoomValue); if(isascii(ch)){ TCHAR buf[100]; //暂存token,一个单词99字符应该足够了 int p = 0; buf[p++] = ch; //继续向上漫游,应该全部都是字符 for(;;){ //根据本空间的ID和逻辑明文,找到父空间空间的ID和逻辑明文, CppSQLite3Query Result = LBrainQuery("*",CurrentRoomValue,LB_CHILD_ID,CurrentID); if(Result.eof())return 0; CurrentID = Result.getInt64Field(0); //如果得到的空间ID为根空间,则表示找到顶了。 if(CurrentID == ROOT_SPACE){ buf[p]='\0'; _tcsrev(buf); Text = buf; //如果是形容词则加上引号 if(RoomType == MEMORY_REFERENCE){ Text.insert(Text.begin(),1,_T('\"')); Text+=_T('\"'); } return 1; //表示得到一个token } CurrentRoomValue = Result.getInt64Field(1); if(p<100) buf[p++] = IDToChar(CurrentRoomValue); } } //不是字符,则需要嵌套处理,然后根据返回值添加标点符号 int32 n = 0; vector<tstring> StrList; for(;;){ tstring s; n = RetrieveText(CurrentRoomValue,s,false); StrList.push_back(s); //继续向上漫游,根据本空间的ID和逻辑明文,找到父空间空间的ID和逻辑明文, CppSQLite3Query Result = LBrainQuery("*",CurrentRoomValue,LB_CHILD_ID,CurrentID); if(Result.eof())return 0; CurrentID = Result.getInt64Field(0); //如果得到的空间ID为根空间,则表示找到顶了。 if(CurrentID == ROOT_SPACE)break; CurrentRoomValue = Result.getInt64Field(1); } TCHAR flag=_T(' '); if(n==1){ //子句,token之间应该有空格 flag = _T(' '); } else if(n==2){ //句子,子句之间有逗号 flag = _T(','); } else if(n ==3){ //段落,句子之间有句号 flag = _T('.'); } else if(n== 4){//文本,段落之间要分行 flag = _T('\n'); } assert(n<5); vector<tstring>::reverse_iterator It = StrList.rbegin(); while(It != StrList.rend()){ Text += *It; if(Text.size()){ TCHAR& ch = Text[Text.size()-1]; if(!ispunct(ch)){ Text += flag; }else if(Text.size()>2) { ch = Text[Text.size()-2]; if (isspace(ch)) { Text.erase(Text.size()-2,1); } } } It++; } if(RoomType == MEMORY_REFERENCE) { Text.insert(Text.begin(),1,_T('\"')); Text+='\"'; assert(n==1 || n==0); //引用被看作是一个token,应该只出现在子句里 return 1; } return ++n; }
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; } } }
bool tryParseDateTime(const tstring& value, CDateTime& datetime, tstring& offset) { if (value.size() != 25) return false; tstring::const_iterator it = value.begin(); tstring::const_iterator end = value.end(); size_t digits = 8 + 6; // Date + Time digits. while ( (digits != 0) && (it != end) ) { if (!isdigit(*it)) return false; --digits; ++it; } if (*it != '.') return false; else ++it; digits = 6; // Time fraction digits. while ( (digits != 0) && (it != end) ) { if (!isdigit(*it)) return false; --digits; ++it; } if ( (*it != '+') && (*it != '-') ) return false; else ++it; digits = 3; // Time-zone offset digits. while ( (digits != 0) && (it != end) ) { if (!isdigit(*it)) return false; --digits; ++it; } const int year = Core::parse<int>(value.substr( 0, 4)); const int month = Core::parse<int>(value.substr( 4, 2)); const int day = Core::parse<int>(value.substr( 6, 2)); const int hours = Core::parse<int>(value.substr( 8, 2)); const int minutes = Core::parse<int>(value.substr(10, 2)); const int seconds = Core::parse<int>(value.substr(12, 2)); if ((year < CDate::MIN_YEAR) || (year > CDate::MAX_YEAR)) return false; if ((month < CDate::MIN_MONTH) || (month > CDate::MAX_MONTH)) return false; if ((day < CDate::MIN_DAY) || (day > CDate::MAX_DAY)) return false; if ((hours < CTime::MIN_HOURS) || (hours > CTime::MAX_HOURS)) return false; if ((minutes < CTime::MIN_MINS) || (minutes > CTime::MAX_MINS)) return false; if ((seconds < CTime::MIN_SECS) || (seconds > CTime::MAX_SECS)) return false; datetime = CDateTime(day, month, year, hours, minutes, seconds); offset = value.substr(21, 4); return true; }
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 Path::Normalize( tstring& path ) { toLower( path ); std::replace( path.begin(), path.end(), Helium::PathSeparator, s_InternalPathSeparator ); }
string ConvertToString(const tstring& str) { return string(str.begin(), str.end()); }
std::string T2C(const tstring& text) { return std::string(text.begin(), text.end()); }