double LevenshteinDistance(wxString s, wxString t) { s.MakeLower(); // case insensitive edit distance t.MakeLower(); const int m = s.length(), n = t.length(), _w = m + 1; std::vector<unsigned char> _d((m + 1) * (n + 1)); #define D(x, y) _d[(y) * _w + (x)] for (int i = 0; i <= m; ++i) D(i,0) = i; for (int j = 0; j <= n; ++j) D(0,j) = j; for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) { const int cost = (s[i - 1] != t[j - 1]); D(i,j) = LSL::Util::Min(D(i-1,j) + 1, // deletion D(i,j-1) + 1, // insertion D(i-1,j-1) + cost); // substitution } } double d = (double) D(m,n) / std::max(m, n); wxLogMessage( _T("LevenshteinDistance('%s', '%s') = %g"), s.c_str(), t.c_str(), d ); return d; #undef D }
void AttachDbgProcDlg::RefreshProcessesList(wxString filter, int colToSort) { wxWindowUpdateLocker locker(m_dvListCtrl); m_dvListCtrl->DeleteAllItems(); filter.Trim().Trim(false); // Populate the list with list of processes std::vector<ProcessEntry> proclist; ProcUtils::GetProcessList(proclist); // if(colToSort == 0) { // sort by PID // std::sort(proclist.begin(), proclist.end(), PIDSorter()); // // } else if(colToSort == 1) { // sort by name // std::sort(proclist.begin(), proclist.end(), NameSorter()); // } filter.MakeLower(); for(size_t i = 0; i < proclist.size(); ++i) { // Use case in-sensitive match for the filter wxString entryName(proclist.at(i).name); // Append only processes that matches the filter string if(filter.IsEmpty() || FileUtils::FuzzyMatch(filter, entryName)) { const ProcessEntry& entry = proclist.at(i); if(entry.pid == (long)wxGetProcessId()) continue; wxVector<wxVariant> cols; cols.push_back(wxString() << entry.pid); cols.push_back(entry.name); m_dvListCtrl->AppendItem(cols); } } }
inline bool format::isNumeric(wxString kw) { if(kw.Len()==0) return false; if(kw.GetChar(0)=='&') { switch(kw.MakeLower().GetChar(1)) { case 'b': kw=kw.Mid(2); break; case 'o': kw=kw.Mid(2); break; case 'h': kw=kw.Mid(2); break; } } char ch; for(int i=0;i<(int)kw.Len();i++) { ch = kw.GetChar(i); if( ch >= 46 && ch <= 57 ) { if (ch==47) return false; } else { return false; } } return true; }
wxString AssFile::GetScriptInfo(wxString key) const { key.MakeLower(); for (const auto info : Line | agi::of_type<AssInfo>()) { if (key == info->Key().Lower()) return info->Value(); } return ""; }
bool EnvVarsConfigDlg::VerifySetUnique(const wxChoice* choSet, wxString set) { for (int i=0; i<(int)choSet->GetCount(); ++i) { if (set.MakeLower().IsSameAs(choSet->GetString(i).MakeLower())) { cbMessageBox(_("This set already exists."), _("Error"), wxOK | wxCENTRE | wxICON_EXCLAMATION); return false; } } return true; }// VerifySetUnique
int CDirectoryListing::FindFile_CmpNoCase(wxString name) const { if (!m_entryCount) return -1; if (!m_searchmap_nocase) m_searchmap_nocase.Get(); name.MakeLower(); // Search map std::multimap<wxString, unsigned int>::const_iterator iter = m_searchmap_nocase->find(name); if (iter != m_searchmap_nocase->end()) return iter->second; unsigned int i = m_searchmap_nocase->size(); if (i == m_entryCount) return -1; std::multimap<wxString, unsigned int>& searchmap_nocase = m_searchmap_nocase.Get(); // Build map if not yet complete std::vector<CRefcountObject<CDirentry> >::const_iterator entry_iter = m_entries->begin() + i; for (; entry_iter != m_entries->end(); ++entry_iter, ++i) { wxString entry_name = (*entry_iter)->name; entry_name.MakeLower(); searchmap_nocase.insert(std::pair<const wxString, unsigned int>(entry_name, i)); if (entry_name == name) return i; } // Map is complete, item not in it return -1; }
wxString GetIPV6LongForm(wxString short_address) { if (!short_address.empty() && short_address[0] == '[') { if (short_address.Last() != ']') return wxString(); short_address.RemoveLast(); short_address = short_address.Mid(1); } short_address.MakeLower(); wxChar buffer[40] = { '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', 0 }; wxChar* out = buffer; const unsigned int len = short_address.Len(); if (len > 39) return wxString(); // First part, before possible :: unsigned int i = 0; unsigned int grouplength = 0; wxChar const* s = short_address.c_str(); // Get it zero-terminated. for (i = 0; i < len + 1; ++i) { const wxChar& c = s[i]; if (c == ':' || !c) { if (!grouplength) { // Empty group length, not valid if (!c || s[i + 1] != ':') return wxString(); ++i; break; } out += 4 - grouplength; for (unsigned int j = grouplength; j > 0; j--) *out++ = s[i - j]; // End of string... if (!c) { if (!*out) // ...on time return buffer; else // ...premature return wxString(); } else if (!*out) { // Too long return wxString(); } ++out; grouplength = 0; if (s[i + 1] == ':') { ++i; break; } continue; } else if ((c < '0' || c > '9') && (c < 'a' || c > 'f')) { // Invalid character return wxString(); } // Too long group if (++grouplength > 4) return wxString(); } // Second half after :: wxChar* end_first = out; out = &buffer[38]; unsigned int stop = i; for (i = len - 1; i > stop; i--) { if (out < end_first) { // Too long return wxString(); } const wxChar& c = s[i]; if (c == ':') { if (!grouplength) { // Empty group length, not valid return wxString(); } out -= 5 - grouplength; grouplength = 0; continue; } else if ((c < '0' || c > '9') && (c < 'a' || c > 'f')) { // Invalid character return wxString(); } // Too long group if (++grouplength > 4) return wxString(); *out-- = c; } if (!grouplength) { // Empty group length, not valid return wxString(); } out -= 5 - grouplength; out += 2; int diff = out - end_first; if (diff < 0 || diff % 5) return wxString(); return buffer; }
wxInt32 NaturalCompare(wxString String1, wxString String2, bool CaseSensitive = false) { wxInt32 StringCounter1 = 0, StringCounter2 = 0; wxInt32 String1Zeroes = 0, String2Zeroes = 0; wxChar String1Char, String2Char; wxInt32 Result; if (!CaseSensitive) { String1.MakeLower(); String2.MakeLower(); } while (true) { String1Zeroes = 0; String2Zeroes = 0; String1Char = String1[StringCounter1]; String2Char = String2[StringCounter2]; // skip past whitespace or zeroes in first string while (wxIsspace(String1Char) || String1Char == '0' ) { if (String1Char == '0') { String1Zeroes++; } else { String1Zeroes = 0; } String1Char = String1[++StringCounter1]; } // skip past whitespace or zeroes in second string while (wxIsspace(String2Char) || String2Char == '0') { if (String2Char == '0') { String2Zeroes++; } else { String2Zeroes = 0; } String2Char = String2[++StringCounter2]; } // We encountered some digits, compare these. if (wxIsdigit(String1Char) && wxIsdigit(String2Char)) { if ((Result = NaturalCompareWorker( String1.Mid(StringCounter1), String2.Mid(StringCounter2))) != 0) { return Result; } } if ((String1Char == 0) && (String2Char == 0)) { return (String1Zeroes - String2Zeroes); } if (String1Char < String2Char) { return -1; } else if (String1Char > String2Char) { return 1; } ++StringCounter1; ++StringCounter2; } }