int CSString::compare(const CSString &s1, const CSString &s2) { if (lexicographical_compare(s1._deqCustString->begin(), s1._deqCustString->end(), s2._deqCustString->begin(), s2._deqCustString->end())) return -1; if (s1.size() != s2.size()) return 1; for (int i = 0; i < s1.size(); i++) { if (s1[i] != s2[i]) return 1; } return 0; }
unsigned CSString::returnFirstPositionSubString(const CSString &str, int from, bool isCaseSensitive) const { unsigned position; int k = 0; for (int i = from; i < _deqCustString->size(); i++) { char curSymbol = str[k]; if (!isCaseSensitive) { curSymbol = tolower(str[k]); (*_deqCustString)[i] = tolower((*_deqCustString)[i]); } if (curSymbol != (*_deqCustString)[i]) continue; else { if (k != str._deqCustString->size() - 1) { k++; continue; } else { position = i - str.size() + 1; return position; } } } return -1; }
void CWords_dicDlg::OnSelchangeResultList() { // Get selection CString resStr; m_Results.GetText( m_Results.GetCurSel(), resStr ); CSString key = Dico.getWordsKey( CSString(resStr) ); // Copy the selection into the clipboard if ( OpenClipboard() ) { HGLOBAL mem = GlobalAlloc (GHND|GMEM_DDESHARE, key.size()+1); if (mem) { char *pmem = (char*)GlobalLock( mem ); strcpy( pmem, key.c_str() ); GlobalUnlock( mem ); EmptyClipboard(); SetClipboardData( CF_TEXT, mem ); } CloseClipboard(); if ( mem ) { CString s; s.Format( "\"%s\" copied into the clipboard", key.c_str() ); GetDlgItem( IDC_Status )->SetWindowText( s ); } } else { GetDlgItem( IDC_Status )->SetWindowText( "Cannot access the clipboard" ); } }
bool CSString::contains(const CSString &str, bool isCaseSensitive) const { bool isContain = false; if (_deqCustString->size() < str.size()) return isContain; if(returnFirstPositionSubString(str, isCaseSensitive) != -1) isContain = true; return isContain; }
/* * Set the result vector with strings corresponding to the input string: * - If inputStr is partially or completely found in the keys, all the matching <key,words> are returned; * - If inputStr is partially or completely in the words, all the matching <key, words> are returned. * The following tags can modify the behaviour of the search algorithm: * - ^mystring returns mystring only if it is at the beginning of a key or word * - mystring$ returns mystring only if it is at the end of a key or word * All returned words are in UTF8. */ void CWordsDictionary::lookup( const CSString& inputStr, CVectorSString& resultVec ) const { // Prepare search string if ( inputStr.empty() ) return; CSString searchStr = inputStr; bool findAtBeginning = false, findAtEnd = false; if ( searchStr[0] == '^' ) { searchStr = searchStr.substr( 1 ); findAtBeginning = true; } if ( searchStr[searchStr.size()-1] == '$' ) { searchStr = searchStr.rightCrop( 1 ); findAtEnd = true; } // Search const vector<string> &vec = reinterpret_cast<const vector<string>&>(_Keys); // for ( CVectorSString::const_iterator ivs=_Keys.begin(); ivs!=_Keys.end(); ++ivs ) for ( vector<string>::const_iterator ivs=vec.begin(); ivs!=vec.end(); ++ivs ) { const CSString& key = *ivs; string::size_type p; if ( (p = key.findNS( searchStr.c_str() )) != string::npos ) { if ( ((!findAtBeginning) || (p==0)) && ((!findAtEnd) || (p==key.size()-searchStr.size())) ) resultVec.push_back( makeResult( key, _Words[ivs-vec.begin()] ) ); } } for ( CVectorSString::const_iterator ivs=_Words.begin(); ivs!=_Words.end(); ++ivs ) { const CSString& word = *ivs; string::size_type p; if ( (p = word.findNS( searchStr.c_str() )) != string::npos ) { if ( ((!findAtBeginning) || (p==0)) && ((!findAtEnd) || (p==word.size()-searchStr.size())) ) resultVec.push_back( makeResult( _Keys[ivs-_Words.begin()], word ) ); } } }
static bool needsQuotes(const CSString& src) { for (uint32 i=0;i<src.size();++i) { char c= src[i]; if (c<=32 || c=='.' || c==':' || c=='#' || c=='\"' || c=='=') { return true; } } return false; }
bool endsWith( const CSString& s, const CSString& substring ) { return (s.right( substring.size() ) == substring); }