// Get the character width of the word that comes next UINT GetNextWordWidth(wchar_t *str) { UINT i; UINT ret; // Validate arguments if (str == NULL) { return 0; } ret = 0; for (i = 0;;i++) { wchar_t c = str[i]; if (c == 0) { break; } if (IsWordChar(c) == false) { break; } ret++; } return ret; }
// Helper string find metho wxString ReplaceWord(const wxString &str, const wxString &word, const wxString &replaceWith) { wxString currChar; wxString nextChar; wxString currentWord; wxString output; for(size_t i=0; i<str.Length(); i++) { // Look ahead if( str.Length() > i + 1 ) { nextChar = str[i+1]; } else { // we are at the end of buffer nextChar = wxT('\0'); } currChar = str[i]; if(!IsWordChar( currChar, currentWord.Length() )) { output << str[i]; currentWord.Clear(); } else { currentWord << currChar; if(IsWordChar(nextChar, currentWord.Length())) { // do nothing } else if( !IsWordChar(nextChar, currentWord.Length()) && currentWord == word ) { output << replaceWith; currentWord.Clear(); } else { output << currentWord; currentWord.Clear(); } } } return output; }
wxArrayString TokenizeWords(const wxString &str) { wxString currChar; wxString nextChar; wxString currentWord; wxArrayString outputArr; wxString::const_iterator iter = str.begin(); for(; iter != str.end(); iter++) { // Look ahead if( (iter + 1) != str.end() ) { nextChar = *(iter+1); } else { // we are at the end of buffer nextChar = wxT('\0'); } currChar = *iter; if(!IsWordChar( currChar, currentWord.Length() )) { currentWord.Clear(); } else { currentWord << currChar; if(IsWordChar(nextChar, currentWord.Length())) { // do nothing } else { outputArr.Add(currentWord); currentWord.Clear(); } } } return outputArr; }
bool wxSimpleHtmlParser::ReadWord(wxString& str, bool eatIt) { int pos = m_pos; if (!IsAlpha(GetChar(pos))) return FALSE; str += (wxChar) GetChar(pos) ; pos ++; while (!Eof(pos) && IsWordChar(GetChar(pos))) { str += (wxChar) GetChar(pos); pos ++; } if (eatIt) m_pos = pos; return TRUE; }
ecConfigItem *ecConfigToolView::DoFind(const wxString& what, wxWindow* parent) { ecConfigToolDoc *pDoc = wxGetApp().GetConfigToolDoc(); if (!pDoc) return NULL; #if wxCHECK_VERSION(2, 6, 0) int nCount = pDoc->GetItems().GetCount(); #else int nCount = pDoc->GetItems().Number(); #endif // static LPCTSTR arWhereImage[]={_T("name"),_T("macro"),_T("description string"),_T("current value"),_T("default value")}; wxString strFind(what); if(! wxGetApp().GetSettings().m_findMatchCase) { strFind.MakeLower(); } wxTreeItemId h = wxGetApp().GetTreeCtrl()->GetSelection(); int nItem; if(!h){ nItem=0; } else { for (nItem=nCount-1;nItem>=0;--nItem) { if(h==pDoc->GetItem(nItem)->GetTreeItem()) { break; } } wxASSERT(nItem>=0); } ecConfigItem *pItem = NULL; int i; for (i=0 ; i < nCount ; i++) { if(wxGetApp().GetSettings().m_findDirection) { nItem=(nItem+1)%nCount; } else { nItem=(nCount+nItem-1)%nCount; } pItem = pDoc->GetItem(nItem); ecWhereType where = ecConfigItem::WhereStringToType(wxGetApp().GetSettings().m_findSearchWhat); wxString strName (pItem->StringValue(where)); if (!wxGetApp().GetSettings().m_findMatchCase) { strName.MakeLower(); } int nIndex = strName.Find(strFind); if(-1!=nIndex) { if (wxGetApp().GetSettings().m_findMatchWholeWord) { // Enforce whole-word semantics: to left and right if(nIndex>0 && IsWordChar(strName[(unsigned) (nIndex-1)])){ continue; } nIndex += strFind.Length(); if (nIndex < strName.Length() && IsWordChar(strName[(unsigned) nIndex])){ continue; } } break; } } if (i < nCount) { if(m_expandedForFind) { wxGetApp().GetTreeCtrl()->Collapse(m_expandedForFind); } wxTreeItemId h=pItem->GetTreeItem(); // Is h visible? wxTreeItemId hv; for(hv=wxGetApp().GetTreeCtrl()->GetFirstVisibleItem();hv;hv=wxGetApp().GetTreeCtrl()->GetNextVisible(hv)) { if(hv==h) { break; } } #if wxCHECK_VERSION(2, 6, 0) if (!hv.IsOk()) #else if (0==hv) #endif { // we want to record the highest unexpanded item for(hv=wxGetApp().GetTreeCtrl()->GetItemParent(h);hv;hv=wxGetApp().GetTreeCtrl()->GetItemParent(hv)) { if (!wxGetApp().GetTreeCtrl()->IsExpanded( hv)) { m_expandedForFind = hv; } } } wxGetApp().GetTreeCtrl()->EnsureVisible(h); wxGetApp().GetTreeCtrl()->SelectItem(h); } else { wxString msg; msg.Printf(_("Cannot find '%s' in %s"), (const wxChar*) what, (const wxChar*) wxGetApp().GetSettings().m_findSearchWhat ); wxMessageBox(msg, _("Find"), wxOK|wxICON_INFORMATION, parent); } return pItem; }