BOOL CFCacheImpl::GetFileSize( LPCWSTR lpFilePath, ULONGLONG& qwSize ) { BOOL retval = FALSE; int nRetCode; char* szError = NULL; CStringA strSql; CStringW strFilePath; sqlite3_stmt* pStmt = NULL; if (!m_pDbConnect) goto clean0; if (!lpFilePath) goto clean0; strFilePath = lpFilePath; strFilePath.MakeLower(); strSql.Format("select size from files where path = '%s'", KUTF16_To_UTF8(strFilePath)); nRetCode = sqlite3_prepare(m_pDbConnect, strSql, -1, &pStmt, 0); if (nRetCode) goto clean0; nRetCode = sqlite3_step(pStmt); if (SQLITE_ROW != nRetCode) goto clean0; qwSize = sqlite3_column_int64(pStmt, 0); retval = TRUE; clean0: if (pStmt) { sqlite3_finalize(pStmt); pStmt = NULL; } return retval; }
bool IsDefaultBrowser() { IApplicationAssociationRegistration* pAAR; HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, nullptr, CLSCTX_INPROC, IID_IApplicationAssociationRegistration, (void**)&pAAR); if (FAILED(hr)) return false; BOOL res = FALSE; hr = pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE, APP_REG_NAME, &res); Log(L"QueryAppIsDefaultAll: %d", res); if (!res) { pAAR->Release(); return false; } // Make sure the Prog ID matches what we have LPWSTR registeredApp; hr = pAAR->QueryCurrentDefault(L"http", AT_URLPROTOCOL, AL_EFFECTIVE, ®isteredApp); pAAR->Release(); Log(L"QueryCurrentDefault: %X", hr); if (FAILED(hr)) return false; Log(L"registeredApp=%s", registeredApp); bool result = !wcsicmp(registeredApp, kDefaultMetroBrowserIDPathKey); CoTaskMemFree(registeredApp); if (!result) return false; // If the registry points another browser's path, // activating the Metro browser will fail. So fallback to the desktop. CStringW selfPath; GetDesktopBrowserPath(selfPath); CStringW browserPath; GetDefaultBrowserPath(browserPath); return !selfPath.CompareNoCase(browserPath); }
/* * Retrieve the target path if it is the default browser * or if not default, retreives the target path if it is a firefox browser * or if the target is not firefox, relies on a hack to get the * 'module dir path\firefox.exe' * The reason why it's not good to rely on the CEH path is because there is * no guarantee win8 will use the CEH at our expected path. It has an in * memory cache even if the registry is updated for the CEH path. * * @aPathBuffer Buffer to fill */ bool GetDesktopBrowserPath(CStringW& aPathBuffer) { // If the target was the default browser itself then return early. Otherwise // rely on a hack to check CEH path and calculate it relative to it. if (mTargetIsDefaultBrowser || mTargetIsBrowser) { aPathBuffer = mTarget; return true; } if (!GetModulePath(aPathBuffer)) return false; // ceh.exe sits in dist/bin root with the desktop browser. Since this // is a firefox only component, this hardcoded filename is ok. aPathBuffer.Append(L"\\"); aPathBuffer.Append(kFirefoxExe); return true; }
BOOL ShellFunctions::RunRegistryCommand(HKEY hKey,LPCWSTR szFile) { if (!IsUnicodeSystem()) return RunRegistryCommand(hKey,W2A(szFile)); PROCESS_INFORMATION pi; STARTUPINFOW si; CRegKey CommandKey; CStringW ExecuteStr; CStringW CommandLine; int i; if (CommandKey.OpenKey(hKey,"command",CRegKey::openExist|CRegKey::samAll)!=ERROR_SUCCESS) return FALSE; if (CommandKey.QueryValue(L"",ExecuteStr)<2) return FALSE; i=ExecuteStr.FindFirst(L'%'); while (i!=-1) { if (ExecuteStr[i+1]==L'1') { CommandLine.Copy(ExecuteStr,i); CommandLine<<szFile; CommandLine<<((LPCWSTR)ExecuteStr+i+2); break; } i=ExecuteStr.FindNext(L'%',i); } if (i==-1) CommandLine=ExecuteStr; if (!ExpandEnvironmentStringsW(CommandLine,ExecuteStr.GetBuffer(1000),1000)) ExecuteStr.Swap(CommandLine); si.cb=sizeof(STARTUPINFOW); si.lpReserved=NULL; si.cbReserved2=0; si.lpReserved2=NULL; si.lpDesktop=NULL; si.lpTitle=NULL; si.dwFlags=STARTF_USESHOWWINDOW; si.wShowWindow=SW_SHOWDEFAULT; if (!CreateProcessW(NULL,ExecuteStr.GetBuffer(),NULL, NULL,FALSE,CREATE_DEFAULT_ERROR_MODE|NORMAL_PRIORITY_CLASS, NULL,NULL,&si,&pi)) { CommandKey.CloseKey(); return FALSE; } CloseHandle(pi.hThread); CloseHandle(pi.hProcess); CommandKey.CloseKey(); return TRUE; }
//Read UTF-8 format file to an unicode text buffer. BOOL Utility::ReadU8FileToUText(LPCTSTR pszFile, CStringW& strOutText) { CStringA strUTF8; CFile fNib; //Read an UTF-8 text file to pU8Buffer fNib.Open(pszFile, CFile::modeRead); int nSize = (int)fNib.GetLength(); char *pU8Buffer = strUTF8.GetBuffer(nSize + 1); //UTF-8 buffer fNib.Read(pU8Buffer, nSize); strUTF8.ReleaseBuffer(); fNib.Close(); //Convert pU8Buffer from UTF-8 to Unicode int count = MultiByteToWideChar(CP_UTF8, 0, strUTF8, -1 ,NULL,0); LPWSTR pszUnicode = strOutText.GetBuffer(count); MultiByteToWideChar(CP_UTF8, 0, pU8Buffer, -1, pszUnicode, count); strOutText.ReleaseBuffer(); return TRUE; }
void SubtitleFile::Append(InputStream& s, float start, float stop, bool fSetTime) { Reference* pRootRef = GetRootRef(); ParseDefs(s, pRootRef); CAtlList<Definition*> defs; GetNewDefs(defs); POSITION pos = defs.GetHeadPosition(); while(pos) { Definition* pDef = defs.GetNext(pos); if(pDef->m_parent == pRootRef && pDef->m_type == L"subtitle" && (*pDef)[L"@"].IsValue()) { m_segments.Insert(start, stop, pDef); if(fSetTime) { try { Definition::Time time; StringMapW<float> offset; pDef->GetAsTime(time, offset); if(time.start.value == start && time.stop.value == stop) continue; } catch(Exception&) { } CStringW str; str.Format(L"%.3f", start); pDef->SetChildAsNumber(L"time.start", str, L"s"); str.Format(L"%.3f", stop); pDef->SetChildAsNumber(L"time.stop", str, L"s"); } } } Commit(); }
int CStatusBarCtrl::GetText(CStringW& str,int nPane,int* pType) const { int ret; int len=(int)::SendMessage(m_hWnd,SB_GETTEXTLENGTH,(WPARAM)nPane,0); if (IsUnicodeSystem()) ret=(int)::SendMessageW(m_hWnd,SB_GETTEXTW,(WPARAM)nPane,(LPARAM)str.GetBuffer(len)); else { char* pText=new char[len+2]; ret=(int)::SendMessageA(m_hWnd,SB_GETTEXTA,(WPARAM)nPane,(LPARAM)pText); str.Copy(pText,len); delete[] pText; } if (pType!=NULL) *pType=HIWORD(ret); return ret; }
//转换源目录 void CDlgFileConv::OnSelectSrcDir() { UpdateData(TRUE); CStringW strDir = SelectDirectory(_T("请选择一个要转换的目录:")); if (!strDir.IsEmpty()) m_strSrcDir = strDir; else return; std::string charset; foreach_file(CStringToUTF8string(strDir).c_str(), find_file_charset_of_src_dir, m_bRecurDir, 1, &charset); if (!charset.empty()) m_strSrcCharset = UTF8stringToCString(charset); else m_strSrcCharset = _T(""); UpdateData(FALSE); }
void Skein::Node::OverwriteBanner(CStringW& inStr) { // Does this text contain an Inform 7 banner? int i = inStr.Find(L"\nRelease "); if (i >= 0) { int release, serial, build; if (swscanf((LPCWSTR)inStr+i,L"\nRelease %d / Serial number %d / Inform 7 build %d",&release,&serial,&build) == 3) { // Replace the banner line with asterisks for (int j = i+1; j < inStr.GetLength(); j++) { if (inStr.GetAt(j) == '\n') break; inStr.SetAt(j,'*'); } } } }
void CShortcut::FormatKeyLabel(VirtualKeyName* pVirtualKeyNames,BYTE bKey,BYTE bModifiers,BOOL bScancode,CStringW& str) { if (bKey==0) { str.LoadString(IDS_SHORTCUTNONE); return; } // Formatting modifiers if (bModifiers&MOD_WIN) str.LoadString(IDS_SHORTCUTMODEXT); else str.Empty(); if (bModifiers&MOD_CONTROL) str.AddString(IDS_SHORTCUTMODCTRL); if (bModifiers&MOD_ALT) str.AddString(IDS_SHORTCUTMODALT); if (bModifiers&MOD_SHIFT) str.AddString(IDS_SHORTCUTMODSHIFT); if (bScancode) { CStringW str2; str2.Format(IDS_SHORTCUTSCANCODE,(int)bKey); str << str2; return; } int i; for (i=0;pVirtualKeyNames[i].bKey!=0 && pVirtualKeyNames[i].bKey!=bKey;i++); if (pVirtualKeyNames[i].iFriendlyNameId!=0) { str.AddString(pVirtualKeyNames[i].iFriendlyNameId); return; } BYTE pKeyState[256]; ZeroMemory(pKeyState,256); WORD wChar; int nRet=ToAscii(bKey,0,pKeyState,&wChar,0); if (nRet==1) { MakeUpper((LPSTR)&wChar,1); str << char(wChar); } else if (nRet==2) { MakeUpper((LPSTR)&wChar,2); str << (LPSTR(&wChar))[0] << (LPSTR(&wChar))[0]; } else if (pVirtualKeyNames[i].pName!=NULL) str << pVirtualKeyNames[i].pName; else str << (int) bKey; }
BOOL CDdnPayCardApp::InitInstance() { CWinApp::InitInstance(); WCHAR chPath[512] = {0}; GetModuleFileNameW(this->m_hInstance,chPath,512); CStringW strFilew = chPath; strFilew = strFilew.Left(strFilew.ReverseFind(_T('\\'))); strFilew += _T("\\CardLog\\"); _wmkdir(strFilew); GXX_LOG_CREATE(strFilew); GXX_LOG_HIT(_T("init instance")); G2XStartup(); return TRUE; }
BOOL CRegKey::QueryValue(LPCWSTR lpszValueName,CStringW& strData) const { if (!IsUnicodeSystem()) { CString strA; if (QueryValue(W2A(lpszValueName),strA)) { strData=strA; return TRUE; } return FALSE; } DWORD dwLength=0; DWORD dwType=REG_SZ; if (::RegQueryValueExW(m_hKey,lpszValueName,NULL,&dwType,NULL,&dwLength)!=ERROR_SUCCESS) { strData.Empty(); return FALSE; } if (dwType!=REG_SZ && dwType!=REG_EXPAND_SZ) { strData.Empty(); return FALSE; } if (dwLength<=1) { strData.Empty(); return TRUE; } if (::RegQueryValueExW(m_hKey,lpszValueName,NULL,NULL,(LPBYTE)strData.GetBuffer(dwLength/2-1),&dwLength)!=ERROR_SUCCESS) { strData.Empty(); return FALSE; } return TRUE; }
// **************************************************************** // ReadShapefileIndex() // **************************************************************** // Fast reading for drawing procedure without bounds, file code, etc bool CShapefileReader::ReadShapefileIndex(CStringW filename, FILE* shpFile, CCriticalSection* readLock) { if (filename.GetLength() < 4) { return false; } // reading shape index (SHX) CStringW sFilename = filename; sFilename.SetAt(sFilename.GetLength() - 1, L'x'); FILE* shxfile = _wfopen(sFilename, L"rb"); if (!shxfile ) { _shpfile = NULL; _indexData = NULL; USES_CONVERSION; CallbackHelper::ErrorMsg(Debug::Format("Failed to open SHX file: %s", OLE2A(sFilename))); return false; } fseek (shxfile, 0, SEEK_END); int indexFileSize = ftell(shxfile); rewind(shxfile); // 100 is for header fseek(shxfile, 100, SEEK_SET); _indexData = new char[indexFileSize - 100]; long result = fread(_indexData, sizeof(char), indexFileSize - 100, shxfile); fclose(shxfile); //_shpHeader.numShapes = (indexFileSize - 100)/8; // 2 int on record _readLock = readLock; _shpfile = shpFile; rewind(shpFile); return true; }
// detect the version of CLR BOOL DetermineDotNetVersion(void) { WCHAR wszPath[MAX_PATH] = {0}; ::GetModuleFileNameW( g_hClrModule, wszPath, MAX_PATH); CStringW strPath(wszPath); int nIndex = strPath.ReverseFind('\\'); if( nIndex <= 0 ) return FALSE; nIndex++; CStringW strFilename = strPath.Mid( nIndex, strPath.GetLength() - nIndex); if( strFilename.CompareNoCase(L"mscorwks.dll") == 0 ) { g_tDotNetVersion = DotNetVersion_20; return TRUE; } if( strFilename.CompareNoCase(L"clr.dll") == 0 ) { VS_FIXEDFILEINFO tVerInfo = {0}; if ( CUtility::GetFileVersion( wszPath, &tVerInfo) && tVerInfo.dwSignature == 0xfeef04bd) { int nMajor = HIWORD(tVerInfo.dwFileVersionMS); int nMinor = LOWORD(tVerInfo.dwFileVersionMS); int nBuildMajor = HIWORD(tVerInfo.dwFileVersionLS); int nBuildMinor = LOWORD(tVerInfo.dwFileVersionLS); if( nMajor == 4 && nMinor == 0 && nBuildMajor == 30319 ) { if( nBuildMinor < 10000 ) g_tDotNetVersion = DotNetVersion_40; else g_tDotNetVersion = DotNetVersion_45; return TRUE; } } return FALSE; } return FALSE; }
STDMETHODIMP XyOptionsImpl::XyGetString(unsigned field, LPWSTR *value, int *chars) { if (!TestOption(field, OPTION_TYPE_STRING, OPTION_MODE_READ)) return E_INVALIDARG; if (!value && !chars) return S_FALSE; CStringW tmp; HRESULT hr = DoGetField(field, &tmp); if (SUCCEEDED(hr)) { if (value) { *value = static_cast<LPWSTR>(LocalAlloc(LPTR, sizeof(WCHAR)*(tmp.GetLength()+1))); ASSERT(*value); memcpy(*value, tmp.GetString(), (tmp.GetLength()+1)*sizeof(WCHAR)); } if (chars) { *chars = tmp.GetLength(); } } return hr; }
VOID CALLBACK CMainDlg::TimerProc( _In_ HWND hwnd, _In_ UINT uMsg, _In_ UINT_PTR idEvent, _In_ DWORD dwTime ) { CStringW strMessage; strMessage.Format(L"Carer: TimerProc id:%d\n", idEvent); OutputDebugString(strMessage); static UINT_PTR m_TimerID = 0; if (TN_Remind == idEvent) { ::SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, m_rectScreen.right, m_rectScreen.bottom, SWP_SHOWWINDOW); ::SetActiveWindow(hwnd); } else if(TN_WindowHide == idEvent) { ::ShowWindow(hwnd, SW_HIDE); } }
CStringA CUnicodeUtils::GetMulti(const CStringW& string,int acp) { char * buf; CStringA retVal; int len = string.GetLength(); if (len==0) return retVal; buf = retVal.GetBuffer(len*4 + 1); int lengthIncTerminator = WideCharToMultiByte(acp, 0, string, -1, buf, len * 4, nullptr, nullptr); retVal.ReleaseBuffer(lengthIncTerminator-1); return retVal; }
void CBatchTextDlg::SaveTextFile(CString &strFile, CStringW &strContent) { CFile file; file.Open(strFile, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate); file.SeekToEnd(); int nLen; std::vector<BYTE> Buf; switch (m_ctrlEnc.GetCurSel()) { case 0: nLen = WideCharToMultiByte(CODEPAGE_GB2312, 0, strContent, -1, NULL, 0, NULL, NULL) - 1; Buf.resize(nLen); if (nLen != 0) { WideCharToMultiByte(CODEPAGE_GB2312, 0, strContent, -1, (LPSTR)&Buf[0], nLen, NULL, NULL); } break; case 1: Buf.resize(strContent.GetLength() * 2 + 2); Buf[0] = 0xFE; Buf[1] = 0xFF; CopyMemory(&Buf[2], strContent.GetBuffer(), Buf.size()); break; case 2: nLen = WideCharToMultiByte(CP_UTF8, 0, strContent, -1, NULL, 0, NULL, NULL) - 1; Buf.resize(nLen + 3); Buf[0] = 0xEF; Buf[1] = 0xBB; Buf[2] = 0xBF; WideCharToMultiByte(CP_UTF8, 0, strContent, -1, (LPSTR)&Buf[3], nLen, NULL, NULL); break; } file.Write(&Buf[0], Buf.size()); }
void File::ParseTypes(InputStream& s, CAtlList<CStringW>& types) { types.RemoveAll(); CStringW str; for(int c = s.SkipWhiteSpace(); iswcsym(c) || c == '.' || c == '@'; c = s.PeekChar()) { c = s.GetChar(); if(c == '.') { if(str.IsEmpty()) s.ThrowError(_T("'type' cannot be an empty string")); if(!iswcsym(s.PeekChar())) s.ThrowError(_T("unexpected dot after type '%s'"), CString(str)); types.AddTail(str); str.Empty(); } else { if(str.IsEmpty() && iswdigit(c)) s.ThrowError(_T("'type' cannot start with a number")); if((!str.IsEmpty() || !types.IsEmpty()) && c == '@') s.ThrowError(_T("unexpected @ in 'type'")); str += (WCHAR)c; } } if(!str.IsEmpty()) { types.AddTail(str); } }
void CPlayerPlaylistBar::Append(CStringW vdn, CStringW adn, int vinput, int vchannel, int ainput) { CPlaylistItem pli; pli.m_type = CPlaylistItem::device; pli.m_fns.AddTail(CString(vdn)); pli.m_fns.AddTail(CString(adn)); pli.m_vinput = vinput; pli.m_vchannel = vchannel; pli.m_ainput = ainput; CAtlList<CStringW> sl; CStringW vfn = GetFriendlyName(vdn); CStringW afn = GetFriendlyName(adn); if (!vfn.IsEmpty()) { sl.AddTail(vfn); } if (!afn.IsEmpty()) { sl.AddTail(afn); } CStringW label = Implode(sl, '|'); label.Replace(L"|", L" - "); pli.m_label = CString(label); m_pl.AddTail(pli); Refresh(); SavePlaylist(); }
void SourceEdit::TokenizeLine(const CStringW& line, CArray<CStringW>& tokens) { int i = 0; while (true) { // We are either at the start of the line, or the end of the previous token, // so scan forward to find the start of the next token. while (true) { if (i == line.GetLength()) return; WCHAR c = line.GetAt(i); if ((c != L' ') && (c != L'\t')) break; i++; } // Find the end of this token int j = line.Find(L" ",i); if (j == -1) { // No final delimiter, so this must be the last token if (i < line.GetLength()) tokens.Add(line.Mid(i)); return; } else { // Store this token and move to the end of it tokens.Add(line.Mid(i,j-i)); i = j; } } }
CStringW DebugBasicSerialize( LuaObject& obj ) { if ( obj.Type() == LUA_TNUMBER ) { CStringW str; str.Format( L"%.16g", obj.GetNumber() ); return str; } else if ( obj.Type() == LUA_TBOOLEAN ) { return obj.GetBoolean() ? L"true" : L"false"; } else if (obj.Type() == LUA_TSTRING) { CString str = obj.GetString(); if ( str == "!!!NIL!!!" ) return L"nil"; else if ( str == "!!!FUNCTION!!!" ) return L"{function}"; else if ( str == "!!!CFUNCTION!!!" ) return L"{cfunction}"; else if ( str == "!!!USERDATA!!!" ) return L"{userdata}"; else if ( str == "!!!TABLE!!!" ) return L"{table}"; return CStringW(str); } #if LUA_WIDESTRING else if (obj.Type() == LUA_TWSTRING) { return CStringW((wchar_t*)obj.GetWString()); } #endif // LUA_WIDESTRING else return _T("Unknown"); }
CString TextFormat::UnicodeToLatin1(const CStringW& in) { CString text; int len = in.GetLength(); LPSTR textPtr = text.GetBufferSetLength(len); for (int i = 0; i < len; i++) { wchar_t c = in[i]; textPtr[i] = (c < 256) ? (char)c : '?'; } text.ReleaseBuffer(len); return text; }
CStringW CFormData::GetMime(LPCTSTR __szExt) { HKEY hkey; DWORD dwType, dwSize; wchar_t buffer[255]; ZeroMemory(&buffer, sizeof(buffer)); CStringW s; s.Format(L"\\.%s", __szExt); if(RegOpenKeyEx(HKEY_CLASSES_ROOT, s, 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { dwType = REG_SZ; dwSize = sizeof(buffer); RegQueryValueEx(hkey, TEXT("Content Type"), 0, &dwType, (LPBYTE)&buffer, &dwSize); RegCloseKey(hkey); } return CStringW(buffer); }
void CStubbornFiles::AddFile(const CStringW& strFilePath) { CStringW strTempPath = strFilePath; CAtlMap<CStringW, BOOL>::CPair* pPair = NULL; KAutoLock lock(klock); if (strFilePath.IsEmpty()) goto clean0; strTempPath.MakeLower(); pPair = m_fileMap.Lookup(strTempPath); if (pPair) goto clean0; m_fileMap[strTempPath] = TRUE; m_fileList.AddTail(strTempPath); clean0: return; }
CStringA CUnicodeUtils::GetUTF8(const CStringW& string) { char * buf; CStringA retVal; int len = string.GetLength(); if (len==0) return retVal; buf = retVal.GetBuffer(len*4 + 1); // SecureZeroMemory(buf, (string.GetLength()*4 + 1)*sizeof(char)); int lengthIncTerminator = WideCharToMultiByte(CP_UTF8, 0, string, -1, buf, len*4, NULL, NULL); retVal.ReleaseBuffer(lengthIncTerminator-1); return retVal; }
void CSearchManager::GetWords(LPCTSTR sz, WordList *plistWords) { LPCTSTR szS = sz; size_t uChars = 0; size_t uBytes = 0; CStringW sWord; //CStringA sWord; while (_tcslen(szS) > 0) { uChars = _tcscspn(szS, _aszInvKadKeywordChars); sWord = szS; // xt+20101214 size_t nLen = (size_t)sWord.GetLength(); if (uChars <= nLen) // xt+20101214 sWord.Truncate((int)uChars); // TODO: We'd need a safe way to determine if a sequence which contains only 3 chars is a real word. // Currently we do this by evaluating the UTF-8 byte count. This will work well for Western locales, // AS LONG AS the min. byte count is 3(!). If the byte count is once changed to 2, this will not // work properly any longer because there are a lot of Western characters which need 2 bytes in UTF-8. // Maybe we need to evaluate the Unicode character values itself whether the characters are located // in code ranges where single characters are known to represent words. uBytes = KadGetKeywordBytes(sWord).GetLength(); if (uBytes >= 3) { KadTagStrMakeLower(sWord); plistWords->remove (sWord); plistWords->push_back(sWord); } szS += uChars; if (uChars < _tcslen(szS)) szS++; } // if the last word we have added, contains 3 chars (and 3 bytes), it's in almost all cases a file's extension. if (plistWords->size() > 1 && (uChars == 3 && uBytes == 3)) plistWords->pop_back(); }
bool UtilReadFileSplitted(LPCTSTR lpFile,FILELINECONTAINER &container) { //行バッファをクリア container.data.clear(); container.lines.clear(); //---読み込み std::vector<BYTE> cReadBuffer; if(!UtilReadFile(lpFile,cReadBuffer))return false; //終端の0追加 cReadBuffer.resize(cReadBuffer.size()+2); cReadBuffer[cReadBuffer.size()-1]; cReadBuffer[cReadBuffer.size()-2]; { CStringW strData; UtilGuessToUNICODE(strData,&cReadBuffer[0],cReadBuffer.size()); container.data.assign((LPCWSTR)strData,(LPCWSTR)strData+strData.GetLength()); container.data.push_back(L'\0'); } LPWSTR p=&container.data[0]; const LPCWSTR end=p+container.data.size(); LPCWSTR lastHead=p; //解釈 for(;p!=end && *p!=L'\0';p++){ if(*p==_T('\n')||*p==_T('\r')){ if(lastHead<p){ //空行は飛ばす container.lines.push_back(lastHead); } lastHead=p+1; *p=L'\0'; } } return true; }
CString OptUtf8ToStr(const CStringW& rwstr) { CStringA astr; for (int i = 0; i < rwstr.GetLength(); i++) { if (rwstr[i] >= 0x100) { // this is no UTF8 string (it's already an Unicode string)... return rwstr; // just return the string } astr += (BYTE)rwstr[i]; } return OptUtf8ToStr(astr); }
bool EditFind::Replace(void) { ASSERT(m_findOnly == false); // Get the text in the current selection CHARRANGE sel = m_edit->GetSelect(); CStringW selText = m_edit->GetTextRange(sel.cpMin,sel.cpMax); // If the current selection matches the text in the dialog, replace it if (m_dialog->MatchCase()) { if (selText.Compare(m_dialog->GetFindString()) == 0) m_edit->ReplaceSelect(m_dialog->GetReplaceString()); } else { if (selText.CompareNoCase(m_dialog->GetFindString()) == 0) m_edit->ReplaceSelect(m_dialog->GetReplaceString()); } // Find the next occurence return FindNext(true); }