void PreviewDlg::InsertBase(vector<char>& html, const wxString& path) { // static if (path.empty()) return; const char* basestart = "<base href=\""; const char* baseend = "\" />\n"; vector<char> base; // Build base string base.insert(base.end(), basestart, basestart + strlen(basestart)); const wxCharBuffer buf = path.mb_str(wxConvUTF8); const unsigned int len = strlen(buf.data()); base.insert(base.end(), buf.data(), buf.data()+len); base.insert(base.end(), baseend, baseend + strlen(baseend)); // Check if we have a head tag in the first 200 bytes vector<char>::iterator insertpos = html.begin(); unsigned int end = wxMin(300, html.size()); if (end > 6) { end -= 6; for (vector<char>::iterator c = html.begin(); c != html.begin() + end; ++c) { if (*c == '<' && *(c+1) == 'h' && *(c+2) == 'e' && *(c+3) == 'a' && *(c+4) == 'd' && *(c+5) == '>') { insertpos = c + 6; break; } } } html.insert(insertpos, base.begin(), base.end()); }
AdbConReply* AdbConnection::send_layer0(wxString s, bool send_only){ if(old){ time_t td = m_sw.Time(); if(td<m_opt->delay){ ADEBUG(SP1("| Sleep: %d", m_opt->delay-td)); wxThread::Sleep(m_opt->delay-td); } /*if(!send_only && m_cb->abort()){ logout(true); return NULL; }*/ } else old = true; m_sw.Start(); wxString cen = s; int i = cen.Find(wxT("pass="******"&"), i); if(j>0&&j<=cen.Length()) cen = cen.substr(0, i+5)+wxT("xxxxx")+cen.substr(j); } ADEBUG(wxT("> ") + cen); //const char * outb = s.mb_str(wxConvUTF8); const wxCharBuffer outb = s.mb_str(wxConvUTF8); m_udp->SendTo((*m_remoteaddr), /*s.ToAscii().data()*/outb, strlen(outb.data()));//(wxUint32)s.Length()); if(m_udp->Error()) ADEBUG(wxT("! Failed to send datagram!")); if(send_only) return NULL; char buf[UDP_BUF_MAX]; wxDateTime t0 = wxDateTime::UNow(); do{ m_udp->RecvFrom((*m_remoteaddr),buf, UDP_BUF_MAX); if(m_cb->abort()){ logout(true); return NULL; } wxTimeSpan delta = wxDateTime::UNow()-t0; if(delta.GetMilliseconds()>m_opt->timeout){ AERROR(wxT("! Timed out!")); return NULL; } }while(m_udp->Error()); lastTimeUsed = m_sw.Time(); m_sw.Start(); buf[m_udp->LastCount()-1] = '\0'; wxString replymsg(buf,wxConvUTF8); ADEBUG(wxT("< ")+replymsg); AdbConReply* r = new AdbConReply(replymsg); return r; }
bool isoimage::ReadDir(const wxString &path, stat_vector_t& stat_vector) { const wxCharBuffer buffer = path.ToAscii(); const char *spath = buffer.data(); return m_image.readdir(spath, stat_vector); }
bool TagEntry::TypedefFromPattern(const wxString& tagPattern, const wxString& typedefName, wxString& name, wxString& templateInit, bool nameIncludeTemplate) { wxString pattern(tagPattern); pattern.StartsWith(wxT("/^"), &pattern); const wxCharBuffer cdata = pattern.mb_str(wxConvUTF8); clTypedefList li; get_typedefs(cdata.data(), li); if(li.size() == 1) { clTypedef td = *li.begin(); templateInit = _U(td.m_realType.m_templateDecl.c_str()); if(td.m_realType.m_typeScope.empty() == false) { name << _U(td.m_realType.m_typeScope.c_str()); if(nameIncludeTemplate) { name << templateInit; } name << wxT("::"); } name << _U(td.m_realType.m_type.c_str()); return true; } return false; }
bool isoimage::OpenImage(const wxString &filename) { const wxCharBuffer buffer = filename.ToAscii(); const char *path = buffer.data(); return m_image.open(path, ISO_EXTENSION_ALL); }
/*static*/ void wxMemoryFSHandlerBase::AddFileWithMimeType(const wxString& filename, const wxString& textdata, const wxString& mimetype) { const wxCharBuffer buf(textdata.To8BitData()); AddFileWithMimeType(filename, buf.data(), buf.length(), mimetype); }
time_t FileUtils::GetFileModificationTime(const wxFileName& filename) { wxString file = filename.GetFullPath(); struct stat buff; const wxCharBuffer cname = file.mb_str(wxConvUTF8); if(stat(cname.data(), &buff) < 0) { return 0; } return buff.st_mtime; }
tmCommand RunCmdDlg::GetCommand() const { tmCommand cmd; const wxString cmdStr = m_cmdCtrl->GetValue(); cmd.name = cmdStr; const wxCharBuffer buf = cmdStr.mb_str(wxConvUTF8); const size_t len = strlen(buf.data()); vector<char> content(buf.data(), buf.data()+len); cmd.SwapContent(content); switch(m_inputBox->GetSelection()) { case 0: cmd.input = tmCommand::ciNONE; break; case 1: cmd.input = tmCommand::ciSEL; break; case 2: cmd.input = tmCommand::ciDOC; break; } switch(m_outputBox->GetSelection()) { case 0: cmd.output = tmCommand::coNONE; break; case 1: cmd.output = tmCommand::coSEL; break; case 2: cmd.output = tmCommand::coDOC; break; case 3: cmd.output = tmCommand::coINSERT; break; case 4: cmd.output = tmCommand::coSNIPPET; break; case 5: cmd.output = tmCommand::coHTML; break; case 6: cmd.output = tmCommand::coTOOLTIP; break; case 7: cmd.output = tmCommand::coNEWDOC; break; } return cmd; }
void ApiHandler::OnInputLineChanged(unsigned int nid, const wxString& text) { // Look up notifier id map<unsigned int, IConnection*>::const_iterator p = m_notifiers.find(nid); if (p == m_notifiers.end()) return; IConnection& conn = *p->second; // Send notifier hessian_ipc::Writer& writer = conn.get_reply_writer(); const wxCharBuffer str = text.ToUTF8(); writer.write_notifier(nid, str.data()); conn.notifier_done(); }
size_t ConvertFromUTF8(const wxCharBuffer& utf8_buff, const wxMBConv& conv, wxWCharBuffer& wchar_buff, size_t& wchar_buff_len, wxCharBuffer& dest_buff, size_t& dest_buff_len, size_t char_len) { // static // Calculate length of conversion to widechar size_t wchar_len = wxConvUTF8.MB2WC(NULL, utf8_buff, 0); if (wchar_len == (size_t)-1) return (size_t)-1; // invalid conversion // Extend widechar buffer if needed if (wchar_buff_len < wchar_len + sizeof(wxChar)) { wchar_buff_len = wchar_len + sizeof(wxChar); wchar_buff = wxWCharBuffer(wchar_buff_len); } // Convert to widechar wchar_len = wxConvUTF8.MB2WC(wchar_buff.data(), utf8_buff, wchar_buff_len); if (wchar_len == (size_t)-1) return (size_t)-1; // invalid conversion // Calculate length of conversion to dest encoding size_t dest_len = conv.WC2MB(NULL, wchar_buff, 0); if (dest_len == (size_t)-1) return (size_t)-1; // invalid conversion // Extend dest buffer if needed if (dest_buff_len < dest_len + char_len) { dest_buff_len = dest_len + char_len; dest_buff = wxCharBuffer(dest_buff_len); } // Convert to dest encoding dest_len = conv.WC2MB(dest_buff.data(), wchar_buff, dest_buff_len); if (dest_len == (size_t)-1) return (size_t)-1; // invalid conversion return dest_len; }
void ParseThread::GetFileListToParse(const wxString& filename, wxArrayString& arrFiles) { if ( !this->IsCrawlerEnabled() ) { return; } { wxCriticalSectionLocker locker( TagsManagerST::Get()->m_crawlerLocker ); wxArrayString includePaths, excludePaths; GetSearchPaths( includePaths, excludePaths ); fcFileOpener::Instance()->ClearResults(); fcFileOpener::Instance()->ClearSearchPath(); for(size_t i=0; i<includePaths.GetCount(); i++) { fcFileOpener::Instance()->AddSearchPath( includePaths.Item(i).mb_str(wxConvUTF8).data() ); } for(size_t i=0; i<excludePaths.GetCount(); i++) { fcFileOpener::Instance()->AddExcludePath(excludePaths.Item(i).mb_str(wxConvUTF8).data()); } // Invoke the crawler const wxCharBuffer cfile = filename.mb_str(wxConvUTF8); // Skip binary files if(TagsManagerST::Get()->IsBinaryFile(filename)) { DEBUG_MESSAGE( wxString::Format(wxT("Skipping binary file %s"), filename.c_str()) ); return; } // Before using the 'crawlerScan' we lock it, since it is not mt-safe crawlerScan( cfile.data() ); } std::set<std::string> fileSet = fcFileOpener::Instance()->GetResults(); std::set<std::string>::iterator iter = fileSet.begin(); for (; iter != fileSet.end(); iter++ ) { wxFileName fn(wxString((*iter).c_str(), wxConvUTF8)); fn.MakeAbsolute(); if ( arrFiles.Index(fn.GetFullPath()) == wxNOT_FOUND ) { arrFiles.Add(fn.GetFullPath()); } } }
void ApiHandler::IpcEditorPrompt(EditorCtrl& editor, IConnection& conn) { const hessian_ipc::Call& call = *conn.get_call(); // Get the title const hessian_ipc::Value& v2 = call.GetParameter(1); const string& t = v2.GetString(); const wxString title(t.c_str(), wxConvUTF8, t.size()); // Show Prompt WindowEnabler we; // otherwise dlg wont be able to return focus const wxString text = wxGetTextFromUser(title, _("Input text"), wxEmptyString, &editor); const wxCharBuffer str = text.ToUTF8(); hessian_ipc::Writer& writer = conn.get_reply_writer(); writer.write_reply(str.data()); }
void strStream::CheckString(const wxString& text) { wxStringOutputStream sos; const wxCharBuffer buf(text.To8BitData()); sos.Write(buf, buf.length()); CPPUNIT_ASSERT_EQUAL( text, sos.GetString() ); }
void wxArchive::Load(wxCharBuffer &buf) { if(CanLoad()) { wxUint32 size = LoadUint32(); if(size > 0) m_idstr.Read(buf.data(), size); } }
size_t ConvertToUTF8(const char* source, const size_t source_len, const wxMBConv& conv, wxCharBuffer& temp_buff, size_t& temp_buff_len, wxWCharBuffer& wchar_buff, size_t& wchar_buff_len, wxCharBuffer& utf8_buff, size_t& utf8_buff_len, size_t char_len) { // static // We have to copy the source string to a temporary buffer so that we can // make it null terminated. if (temp_buff_len < source_len+char_len) { temp_buff_len = source_len+char_len; temp_buff = wxCharBuffer(temp_buff_len); } memcpy(temp_buff.data(), source, source_len); for (unsigned int i = 0; i < char_len; ++i) temp_buff.data()[source_len+i] = '\0'; // Calculate length of conversion to widechar size_t wchar_len = conv.MB2WC(NULL, temp_buff, 0); if (wchar_len == (size_t)-1) return (size_t)-1; // invalid conversion // Extend widechar buffer if needed if (wchar_buff_len < wchar_len + sizeof(wxChar)) { wchar_buff_len = wchar_len + sizeof(wxChar); wchar_buff = wxWCharBuffer(wchar_buff_len); } // Convert to widechar wchar_len = conv.MB2WC(wchar_buff.data(), temp_buff, wchar_buff_len); if (wchar_len == (size_t)-1) return (size_t)-1; // invalid conversion // Calculate length of conversion to UTF-8 size_t utf8_len = wxConvUTF8.WC2MB(NULL, wchar_buff, 0); if (utf8_len == (size_t)-1) return (size_t)-1; // invalid conversion // Extend UTF-8 buffer if needed if (utf8_buff_len < utf8_len) { utf8_buff_len = utf8_len + 1; utf8_buff = wxCharBuffer(utf8_buff_len); } // Convert to UTF-8 utf8_len = wxConvUTF8.WC2MB(utf8_buff.data(), wchar_buff, utf8_buff_len); if (utf8_len == (size_t)-1) return (size_t)-1; // invalid conversion return utf8_len; }
std::map<std::string,std::string> TagsOptionsData::GetTokensMap() const { std::map<std::string,std::string> tokens; wxArrayString tokensArr = wxStringTokenize(m_tokens, wxT("\r\n"), wxTOKEN_STRTOK); for (size_t i=0; i<tokensArr.GetCount(); i++) { //const wxCharBuffer bufKey = _C( wxString item = tokensArr.Item(i).Trim().Trim(false); wxString k = item.BeforeFirst(wxT('=')); wxString v = item.AfterFirst(wxT('=')); const wxCharBuffer bufKey = _C(k); std::string key = bufKey.data(); std::string value; if (!v.empty()) { const wxCharBuffer bufValue = _C(v); value = bufValue.data(); } tokens[key] = value; } return tokens; }
std::map<std::string, std::string> TagsOptionsData::GetTokensMap() const { std::map<std::string, std::string> tokens; for(size_t i = 0; i < m_tokens.GetCount(); i++) { // const wxCharBuffer bufKey = _C( wxString item = m_tokens.Item(i); item.Trim().Trim(false); wxString k = item.BeforeFirst(wxT('=')); wxString v = item.AfterFirst(wxT('=')); const wxCharBuffer bufKey = _C(k); std::string key = bufKey.data(); std::string value; if(!v.empty()) { const wxCharBuffer bufValue = _C(v); value = bufValue.data(); } tokens[key] = value; } return tokens; }
void Styler_Syntax::GetTextWithScopes(unsigned int start, unsigned int end, vector<char>& text) { wxASSERT(start <= end); wxASSERT(end <= m_doc.GetLength()); // Make sure syntax is valid if (m_syntax_end < end) { DoSearch(m_syntax_end, end, end); } text.reserve((end - start) * 2); // Start tag const wxString& topScope = m_topMatches.subMatcher->GetName(); const wxCharBuffer name = topScope.mb_str(); const size_t len = strlen(name.data()); if (len) { text.push_back('<'); text.insert(text.end(), name.data(), name.data() + len); text.push_back('>'); } XmlText(0, m_topMatches, start, end, text); // End tag if (len) { text.push_back('<'); text.push_back('/'); text.insert(text.end(), name.data(), name.data() + len); text.push_back('>'); } }
void cxEnv::GetEnvBlock(wxString& env) const { for (map<wxString, wxString>::const_iterator p = m_env.begin(); p != m_env.end(); ++p) { wxString line = p->first; line += wxT('='); line += p->second; //wxLogDebug(wxT("%d: %s"), i, line); #ifdef __WXMSW__ // Convert to utf8 const wxCharBuffer buf = line.mb_str(wxConvUTF8); // to avoid unicode chars being mangled by windows automatic // conversion to oem, we first convert the utf8 text to unicode // as if it was oem. Windows will convert it back to oem, which // will then preserve the utf8 encoding. // We use native MultiByteToWideChar to ensure we get the right // codepage no matter the current locale. const size_t len = ::MultiByteToWideChar(CP_OEMCP, 0, buf.data(), -1, NULL, 0); if (len) { wxWCharBuffer wBuf(len); ::MultiByteToWideChar(CP_OEMCP, 0, buf.data(), -1, wBuf.data(), len); env += wBuf; } else wxASSERT(false); //const wxString oemEnv(buf, wxCSConv(wxFONTENCODING_CP437)); #else env += line; #endif env += wxT('\0'); } // Add end marker env += wxT('\0'); }
const char* cxEnv::GetEnvBlock() const { // Add all lines together to a single string m_envStr.clear(); m_envStr.reserve(m_env.size() * 40); for (map<wxString, wxString>::const_iterator p = m_env.begin(); p != m_env.end(); ++p) { wxString line = p->first; line += wxT('='); line += p->second; //wxLogDebug(wxT("%d: %s"), i, line); // Convert const wxCharBuffer buf = line.mb_str(wxConvUTF8); const char* str = buf.data(); m_envStr.insert(m_envStr.end(), str, str+strlen(str)); m_envStr.push_back('\0'); } // Add end marker m_envStr.push_back('\0'); return &*m_envStr.begin(); }
void ParseThread::FindIncludedFiles(ParseRequest* req, std::set<std::string>* newSet) { wxArrayString searchPaths, excludePaths, filteredFileList; GetSearchPaths( searchPaths, excludePaths ); DEBUG_MESSAGE( wxString::Format(wxT("Initial workspace files count is %u"), (unsigned int)req->_workspaceFiles.size()) ) ; for(size_t i=0; i<req->_workspaceFiles.size(); i++) { wxString name(req->_workspaceFiles.at(i).c_str(), wxConvUTF8); wxFileName fn(name); fn.MakeAbsolute(); if(TagsManagerST::Get()->IsBinaryFile(fn.GetFullPath())) continue; filteredFileList.Add( fn.GetFullPath() ); } wxArrayString arrFiles; // Clear the results once { // Before using the 'crawlerScan' we lock it, since it is not mt-safe wxCriticalSectionLocker locker( TagsManagerST::Get()->m_crawlerLocker ); fcFileOpener::Instance()->ClearResults(); fcFileOpener::Instance()->ClearSearchPath(); for(size_t i=0; i<searchPaths.GetCount(); i++) { const wxCharBuffer path = _C(searchPaths.Item(i)); DEBUG_MESSAGE( wxString::Format(wxT("ParseThread: Using Search Path: %s "), searchPaths.Item(i).c_str()) ); fcFileOpener::Instance()->AddSearchPath(path.data()); } for(size_t i=0; i<excludePaths.GetCount(); i++) { const wxCharBuffer path = _C(excludePaths.Item(i)); DEBUG_MESSAGE( wxString::Format(wxT("ParseThread: Using Exclude Path: %s "), excludePaths.Item(i).c_str()) ); fcFileOpener::Instance()->AddExcludePath(path.data()); } for(size_t i=0; i<filteredFileList.GetCount(); i++) { const wxCharBuffer cfile = filteredFileList.Item(i).mb_str(wxConvUTF8); crawlerScan(cfile.data()); if( TestDestroy() ) { return; } } newSet->insert(fcFileOpener::Instance()->GetResults().begin(), fcFileOpener::Instance()->GetResults().end()); } }
void Styler_Syntax::XmlText(unsigned int offset, const submatch& sm, unsigned int start, unsigned int end, vector<char>& text) const { unsigned int textstart = start; for (auto_vector<stxmatch>::const_iterator p = sm.matches.begin(); p != sm.matches.end(); ++p) { const stxmatch& m = *(*p); // Check if there is overlap if (m.end <= start) continue; if (m.start >= m.end) break; const unsigned int matchstart = wxMax(start, m.start); const unsigned int matchend = wxMin(end, m.end); // Print text before submatch if (textstart < matchstart) { const unsigned int len = matchstart - textstart; text.resize(text.size() + len); cxLOCKDOC_READ(m_doc) doc.GetTextPart(offset + textstart, offset + matchstart, (unsigned char*)(&*text.end() - len)); cxENDLOCK } // Start tag const wxCharBuffer name = m.m_name.mb_str(); const size_t len = strlen(name.data()); if (len) { text.push_back('<'); text.insert(text.end(), name.data(), name.data() + len); text.push_back('>'); } // Subscopes if (m.subMatch.get()) { XmlText(offset + m.start, *m.subMatch, matchstart - m.start, matchend - m.start, text); } else { // Print text contained in submatch if (matchstart < matchend) { const unsigned int len = matchend - matchstart; text.resize(text.size() + len); cxLOCKDOC_READ(m_doc) doc.GetTextPart(offset + matchstart, offset + matchend, (unsigned char*)(&*text.end() - len)); cxENDLOCK } } // End tag if (len) { text.push_back('<'); text.push_back('/'); text.insert(text.end(), name.data(), name.data() + len); text.push_back('>'); } textstart = matchend; } // Print text after last submatch if (textstart < end) { const unsigned int len = end - textstart; text.resize(text.size() + len); cxLOCKDOC_READ(m_doc) doc.GetTextPart(offset + textstart, offset + end, (unsigned char*)(&*text.end() - len)); cxENDLOCK } }
void BundlePane::OnMenuNew(wxCommandEvent& event) { const int menuId = event.GetId(); switch (menuId) { case MENU_NEW_BUNDLE: { // Get name from user const wxString name = wxGetTextFromUser(_("Name of new item:"), _("New Item"), _("New Bundle"), this); if (name.empty()) return; // user cancel // Create a new bundle item const unsigned int bundleId = m_plistHandler.NewBundle(name); m_plistHandler.SaveBundle(bundleId); // Add to tree const wxTreeItemId rootItem = m_bundleTree->GetRootItem(); const wxTreeItemId bundleItem = m_bundleTree->AppendItem(rootItem, name, 0, -1, new BundleItemData(bundleId)); const wxTreeItemId menuItem = m_bundleTree->AppendItem(bundleItem, _("Menu"), 6, -1, new BundleItemData(BUNDLE_MENU, bundleId)); m_bundleTree->SortChildren(rootItem); m_bundleTree->SelectItem(bundleItem); } break; case MENU_NEW_COMMAND: NewItem(BUNDLE_COMMAND); break; case MENU_NEW_SNIPPET: NewItem(BUNDLE_SNIPPET); break; case MENU_NEW_DRAGCMD: NewItem(BUNDLE_DRAGCMD); break; case MENU_NEW_PREF: NewItem(BUNDLE_PREF); break; case MENU_NEW_LANGUAGE: NewItem(BUNDLE_LANGUAGE); break; case MENU_NEW_SEPARATOR: { const wxTreeItemId selItem = m_bundleTree->GetSelection(); const BundleItemData* data = (BundleItemData*)m_bundleTree->GetItemData(selItem); PListDict infoDict = GetEditableMenuPlist(data->m_bundleId); InsertMenuItem(selItem, wxT("---- separator ----"), new BundleItemData(BUNDLE_SEPARATOR, data->m_bundleId), infoDict); m_plistHandler.SaveBundle(data->m_bundleId); // Update menu in editorFrame m_syntaxHandler.ReParseBundles(true/*onlyMenu*/); } break; case MENU_NEW_SUBMENU: { // Get name from user const wxString name = wxGetTextFromUser(_("Name of new item:"), _("New Item"), _("New SubMenu"), this); if (name.empty()) return; // user cancel const wxTreeItemId selItem = m_bundleTree->GetSelection(); const BundleItemData* data = (BundleItemData*)m_bundleTree->GetItemData(selItem); // Get a new uuid const wxString newUuid = PListHandler::GetNewUuid(); const wxCharBuffer uuidBuf = newUuid.ToUTF8(); const char* uuid = uuidBuf.data(); // Create the new group PListDict infoDict = GetEditableMenuPlist(data->m_bundleId); PListDict menuDict; if (!infoDict.GetDict("mainMenu", menuDict)) { wxFAIL_MSG(wxT("No mainMenu in info.plist")); return; } PListDict submenuDict = menuDict.NewDict("submenus"); PListDict subDict = submenuDict.NewDict(uuid); subDict.NewArray("items"); subDict.wxSetString("name", name); // Insert in menu InsertMenuItem(selItem, name, new BundleItemData(BUNDLE_SUBDIR, data->m_bundleId, newUuid), infoDict); m_plistHandler.SaveBundle(data->m_bundleId); // Update menu in editorFrame m_syntaxHandler.ReParseBundles(true/*onlyMenu*/); } break; default: wxASSERT(false); } };
bool PreviewDlg::InsertStyle(vector<char>& html) { // Check if we should replace style sheet ref if (!m_pinnedEditor) return false; if (html.empty()) return false; const wxString cssFilePath = m_editorCtrl->GetPath(); if (!cssFilePath.EndsWith(wxT(".css"))) return false; // Compile patterns const char *error; int erroffset; if (!m_re_style) { m_re_style = pcre_compile( "<link[^>]+rel=\"stylesheet\"[^>]*>", // the pattern PCRE_UTF8|PCRE_MULTILINE|PCRE_CASELESS, // options &error, // for error message &erroffset, // for error offset NULL); // use default character tables } if (!m_re_href) { m_re_href = pcre_compile( "href=\"(.*?.css).*?\"", // the pattern PCRE_UTF8|PCRE_MULTILINE|PCRE_CASELESS, // options &error, // for error message &erroffset, // for error offset NULL); // use default character tables } // Do the search for style tag const int OVECCOUNT = 30; int ovector[OVECCOUNT]; const int rc1 = pcre_exec( m_re_style, // the compiled pattern NULL, // extra data - if we study the pattern &*html.begin(), // the subject string wxMin(800, html.size()), // the length of the subject 0, // start at offset in the subject PCRE_NO_UTF8_CHECK, // options ovector, // output vector for substring information OVECCOUNT); // number of elements in the output vector if (rc1 == 0) return false; const unsigned int tag_start_pos = ovector[0]; const char* tag_start = &*html.begin() + tag_start_pos; const unsigned int tag_len = ovector[1] - ovector[0]; // Do the search for href tag with css path const int rc2 = pcre_exec( m_re_href, // the compiled pattern NULL, // extra data - if we study the pattern tag_start, // the subject string tag_len, // the length of the subject 0, // start at offset in the subject PCRE_NO_UTF8_CHECK, // options ovector, // output vector for substring information OVECCOUNT); // number of elements in the output vector if (rc2 == 2) { const unsigned int style_start = tag_start_pos + ovector[2]; const unsigned int style_end = tag_start_pos + ovector[3]; // Get match const wxString stylePath(&*html.begin()+style_start, wxConvUTF8, style_end-style_start); wxString localPath = cssFilePath; localPath.Replace(wxT("\\"), wxT("/")); if (localPath.EndsWith(stylePath)) { // Make sure we have temp file // Since css does not offer a base url, we have to place it in same location const wxString cssPath = wxPathOnly(cssFilePath); if (wxPathOnly(m_tempCssPath) != cssPath) { if (!m_tempCssPath.empty() && wxFileExists(m_tempCssPath)) wxRemoveFile(m_tempCssPath); m_tempCssPath = cssPath + wxFILE_SEP_PATH + wxT(".e_preview_temp.css"); wxFile file(m_tempCssPath, wxFile::write); // create the temp file if (file.IsOpened()) { file.Close(); // allow file to be modified #ifdef __WXMSW__ // Make sure the file is marked as hidden and temporary //::SetFileAttributes(m_tempCssPath, FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_NOT_CONTENT_INDEXED|FILE_ATTRIBUTE_TEMPORARY); // Hiding seems to give problems on Vista ::SetFileAttributes(m_tempCssPath, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED|FILE_ATTRIBUTE_TEMPORARY); #endif } } const wxCharBuffer buff = m_tempCssPath.mb_str(wxConvUTF8); html.erase(html.begin()+style_start, html.begin()+style_end); html.insert(html.begin()+style_start, buff.data(), buff.data()+strlen(buff.data())); return true; } } return false; }