Example #1
0
double LevenshteinDistance(const wxString& _s, const wxString& _t)
{
	const wxString s = _s.Lower(); // case insensitive edit distance
	const wxString t = _t.Lower();

	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
}
wxTreeItemId ProjectConfigurationPanel::CategoryId(const wxString& Category)
{
    if ( m_CategoryMap.find(Category.Lower()) != m_CategoryMap.end() )
    {
        return m_CategoryMap[Category.Lower()];
    }

    wxStringTokenizer Tokens(Category,_T("."),wxTOKEN_STRTOK);
    wxString PathSoFar = _T("");
    wxTreeItemId IdSoFar = m_KnownLibrariesTree->GetRootItem();
    bool FirstElem = true;
    while ( Tokens.HasMoreTokens() )
    {
        // Iterate through items already added to map
        wxString Part = Tokens.GetNextToken();
        PathSoFar += Part.Lower();
        if ( m_CategoryMap.find(PathSoFar) == m_CategoryMap.end() )
        {
            // Ok, found first node which is not yet added, this mean
            // that all subnodes are also not yet added
            int SkipLast = FirstElem ? (m_IsOtherCategory?1:0) + (m_IsPkgConfig?1:0) : 0;

            // First elem of the path must take into consideration
            // that some categoies must remain at the end
            if ( SkipLast )
            {
                IdSoFar = m_CategoryMap[PathSoFar] =
                    m_KnownLibrariesTree->InsertItem(
                        IdSoFar,
                        m_KnownLibrariesTree->GetChildrenCount(IdSoFar,false)-SkipLast,
                        Part);
                FirstElem = false;
            }
            else
            {
                IdSoFar = m_CategoryMap[PathSoFar] =
                    m_KnownLibrariesTree->AppendItem(IdSoFar,Part);
            }

            // Next items are always added at the end
            while ( Tokens.HasMoreTokens() )
            {
                Part = Tokens.GetNextToken();
                PathSoFar += _T(".");
                PathSoFar = Part.Lower();
                IdSoFar = m_CategoryMap[PathSoFar] =
                    m_KnownLibrariesTree->AppendItem(IdSoFar,Part);
            }

            // If we're here, all remaining path has been added, so we
            // finished here
            break;
        }
        FirstElem = false;
        PathSoFar += _T(".");
    }
    // Just for sure if there are multiple dots
    m_CategoryMap[Category.Lower()] = IdSoFar;
    return IdSoFar;
}
Example #3
0
void VirtualDirectoryTree::StoreChild(const wxString& displayname, const wxString& vdPath)
{
    VirtualDirectoryTree* child = new VirtualDirectoryTree(this, displayname, vdPath);
    if (IsSourceVD(displayname.Lower()) || IsHeaderVD(displayname.Lower()) || IsResourceVD(displayname.Lower())) {
        m_children.push_back(child); // We want these processed last, so push_back
    } else {
        m_children.push_front(child);
    }
}
void MSVCWorkspaceBase::addDependency(const wxString& projectID, const wxString& dependencyID) {
    // add the dependency to the last project
    HashProjects::iterator it = _projects.find(projectID.Lower());
    if (it != _projects.end()) {
        if (it->second._dependencyList.Index(dependencyID.Lower()) == wxNOT_FOUND) // not already in
            it->second._dependencyList.Add(dependencyID.Lower());
    }
    else {
        Manager::Get()->GetLogManager()->DebugLog(_T("ERROR: project id not found: ") + projectID);
    }
}
 TREE_NODE(NODE_TYPE aType, TREE_NODE* aParent, LIB_ALIAS* aAlias,
           const wxString& aName, const wxString& aDisplayInfo,
           const wxString& aSearchText )
     : Type( aType ),
       Parent( aParent ), Alias( aAlias ), Unit( 0 ),
       DisplayName( aName ),
       DisplayInfo( aDisplayInfo ),
       MatchName( aName.Lower() ),
       SearchText( aSearchText.Lower() ),
       MatchScore( 0 ), PreviousScore( 0 )
 {
 }
Example #6
0
wxString XMLCodeCompletion::GetCompletePattern(const wxString& tag) const
{
    if(m_completePattern.find(tag.Lower()) == m_completePattern.end()) {
        // The default:
        // <tag>|</tag>
        wxString t = tag;
        if(t.StartsWith("<")) { t.Remove(0, 1); }
        return wxString() << "<" << t << ">|</" << t << ">";
    } else {
        return m_completePattern.find(tag.Lower())->second;
    }
}
Example #7
0
CmpPatternPtr NewBuildTab::GetMatchingRegex(const wxString& lineText, LINE_SEVERITY& severity)
{
    if(lineText.Lower().Contains("entering directory") || lineText.Lower().Contains("leaving directory")) {
        severity = SV_DIR_CHANGE;
        return NULL;

    } else if(lineText.StartsWith("====")) {
        severity = SV_NONE;
        return NULL;

    } else {

        // Find *warnings* first
        bool isWarning = false;

        if(!m_cmp) {
            severity = SV_NONE;
            return NULL;
        }

        CmpPatterns cmpPatterns;
        if(!DoGetCompilerPatterns(m_cmp->GetName(), cmpPatterns)) {
            severity = SV_NONE;
            return NULL;
        }

        // If it is not an error, maybe it's a warning
        for(size_t i = 0; i < cmpPatterns.warningPatterns.size(); i++) {
            CmpPatternPtr cmpPatterPtr = cmpPatterns.warningPatterns.at(i);
            BuildLineInfo bli;
            if(cmpPatterPtr->Matches(lineText, bli)) {
                severity = SV_WARNING;
                return cmpPatterPtr;
            }
        }
        if(!isWarning) {
            for(size_t i = 0; i < cmpPatterns.errorsPatterns.size(); i++) {
                BuildLineInfo bli;
                CmpPatternPtr cmpPatterPtr = cmpPatterns.errorsPatterns.at(i);
                if(cmpPatterPtr->Matches(lineText, bli)) {
                    severity = SV_ERROR;
                    return cmpPatterPtr;
                }
            }
        }
    }

    // Default
    severity = SV_NONE;
    return NULL;
}
Example #8
0
// Attempt to reselect the node with the given path
bool frmMain::SetCurrentNode(wxTreeItemId node, const wxString &origPath)
{
	wxString path = origPath.Lower();
	wxTreeItemIdValue cookie;
	wxTreeItemId child = browser->GetFirstChild(node, cookie);


	while (child.IsOk())
	{
		wxString actNodePath = GetNodePath(child).Lower();

		if(path.StartsWith(actNodePath))
		{
			if(!browser->IsExpanded(child))
			{
				browser->SelectItem(child, true);
				browser->Expand(child);
			}

			if (actNodePath == path)
			{
				browser->SelectItem(child, true);
				return true;
			}
			else if (SetCurrentNode(child, path))
				return true;
		}
		child = browser->GetNextChild(node, cookie);

	}

	return false;
}
/////////////////////////////////////
// Associates a type with Aegisub
void DialogAssociations::AssociateType(wxString type) {
	type.Lower();
	wxRegKey *key = new wxRegKey(_T("HKEY_CLASSES_ROOT\\.") + type);
	if (!key->Exists()) key->Create();
	key->SetValue(_T(""),_T("Aegisub"));
	delete key;
}
Example #10
0
bool Postgres::DatabaseExists(const wxString& sDatabaseName)
  {
  if(!IsConnected())
    throw wx::Exception(wxT("Postgres::DatabaseExists() Database not connected."));

  // The query uses field 'datdba' as it's lightweight (int4)
  wxString sqryDatabaseExists = wxT("         \
SELECT datdba                                 \
FROM pg_database                              \
WHERE datname = $1;                           \
");

  // Unfortunately, SQL has a stupid rule about case folding.
  // PG holds table names internally as lower case.
  wxString sDbLower = sDatabaseName.Lower();

  ArrayRecord arParams;
  arParams.push_back(wxVariant(sDbLower));
  ArrayRecordArray ara;
  stc.CacheExecute
    (
    wxT("Postgres::DatabaseExists"),
    sqryDatabaseExists,
    arParams,
    ara
    );

  return (ara.size() > 0)? true : false;
  }
bool ProjectExplorerWindow::MatchesFilter(const wxString& string, const wxString& filter) const
{

    if (m_filterMatchAnywhere)
    {
        return string.Lower().Find(m_filter) != wxNOT_FOUND;
    }
    else
    {

        if (filter.Length() > string.Length())
        {
            return false;
        }

        for (unsigned int i = 0; i < filter.Length(); ++i)
        {
            if ((char)tolower(string[i]) != filter[i])
            {
                return false;
            }
        }

        return true;
    
    }

}
Example #12
0
void wxExViMacros::StartRecording(const wxString& macro)
{
  if (m_IsRecording || macro.empty())
  {
    return;
  }
  
  m_IsRecording = true;
  
  if (macro.size() == 1)
  {
    // We only use lower case macro's, to be able to
    // append to them using qA.
    m_Macro = macro.Lower();
  
    // Clear macro if it is lower case
    // (otherwise append to the macro).
    if (wxIslower(macro[0]))
    {
      m_Macros[m_Macro].clear();
    }
  }
  else
  {
    m_Macro = macro;
    m_Macros[m_Macro].clear();
  }
  
  wxExFrame::StatusText(m_Macro, "PaneMacro");
  
  wxLogStatus(_("Macro recording"));
}
Example #13
0
int FileViewer::GetLexer(const wxString& ext)
{
    struct LexerInfo
    {
        const char *ext;
        int lexer;
    };

    static const LexerInfo s_lexer[] = {
        { "c", wxSTC_LEX_CPP },
        { "cpp", wxSTC_LEX_CPP },
        { "cc", wxSTC_LEX_CPP },
        { "cxx", wxSTC_LEX_CPP },
        { "h", wxSTC_LEX_CPP },
        { "hxx", wxSTC_LEX_CPP },
        { "hpp", wxSTC_LEX_CPP },
        { "py", wxSTC_LEX_PYTHON },
        { "htm", wxSTC_LEX_HTML },
        { "html", wxSTC_LEX_HTML },
        { "php", wxSTC_LEX_PHPSCRIPT },
        { "xml", wxSTC_LEX_XML },
        { "pas", wxSTC_LEX_PASCAL },
        { NULL, -1 }
    };

    wxString e = ext.Lower();

    for ( const LexerInfo *i = s_lexer; i->ext; ++i )
    {
        if ( e == wxString::FromAscii(i->ext) )
            return i->lexer;
    }

    return wxSTC_LEX_NULL;
}
Example #14
0
    virtual wxDirTraverseResult OnFile(const wxString& filename) {
        wxFileName temp = filename;
        wxString shastr = wxT("0");
        unsigned long ovlversion = 0;
        int modtime = temp.GetModificationTime().GetTicks();
        wxFileOffset size = 0;

        if (wxFile::Access(filename.c_str(), wxFile::read)) {
            m_sha.Reset();
            /*
            wxFile f(filename, wxFile::read);
            counted_array_ptr<unsigned char> buf(new unsigned char[f.Length()]);
            size = f.Length();
            f.Read(buf.get(), f.Length());
            m_sha.Input(buf.get(), f.Length());
            */
            size = m_sha.Input(filename);
            shastr = m_sha.Result();

            if (filename.Lower().EndsWith(wxT(".common.ovl"))) {
                cOVLDump dovl;
                dovl.Load(filename.mb_str(wxConvFile));
                ovlversion = dovl.GetVersion();
            }
        }

        temp.MakeRelativeTo(m_root.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME));
        m_buf.Format("insert into vanilla values ('%q', '%q', %d, %lld, %ld);", temp.GetFullPath().mb_str(wxConvUTF8).data(), shastr.mb_str(wxConvUTF8).data(), modtime, size, ovlversion);
        m_db->ExecuteUpdate(m_buf);
        m_pd.Pulse(temp.GetFullPath());
        return wxDIR_CONTINUE;
    }
Example #15
0
wxString InstIconList::getRealIconKeyForEasterEgg ( wxString key, wxString name )
{
	if (key == "default")
	{
		if (name.Lower().Contains("btw") ||
			name.Lower().Contains("better then wolves") || // Because some people are stupid :D
			name.Lower().Contains("better than wolves"))
		{
			return "herobrine";
		}
		else if (name.Lower().Contains("direwolf"))
		{
			return "enderman";
		}
	}
	return key;
}
Example #16
0
void Compiler::AddCmpFileType(const wxString &extension, CmpFileKind type, const wxString &compile_line)
{
	Compiler::CmpFileTypeInfo ft;
	ft.extension = extension.Lower();
	ft.compilation_line = compile_line;
	ft.kind = type;
	m_fileTypes[extension] = ft;
}
Example #17
0
bool pgConn::HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv)
{
	wxString res = ExecuteScalar(
	                   wxT("SELECT has_") + objTyp.Lower()
	                   + wxT("_privilege(") + qtDbString(objName)
	                   + wxT(", ") + qtDbString(priv) + wxT(")"));

	return StrToBool(res);
}
Example #18
0
bool Compiler::GetCmpFileType(const wxString& extension, Compiler::CmpFileTypeInfo& ft)
{
    std::map<wxString, Compiler::CmpFileTypeInfo>::iterator iter = m_fileTypes.find(extension.Lower());
    if(iter == m_fileTypes.end()) {
        return false;
    }
    ft = iter->second;
    return true;
}
std::vector<wxString> t4p::PhpCodeCompletionProviderClass::CollectNearMatchKeywords(wxString tag) {
    tag = tag.Lower();
    std::vector<wxString> matchedKeywords;
    t4p::KeywordsTokenizeMatch(
        t4p::KeywordsPhpAll(App.PhpModule.Environment.Php.Version),
        tag,
        matchedKeywords);
    return matchedKeywords;
}
Example #20
0
wxString Lower(const wxString & input)
{
#ifdef __WXMSW__
	wxWCharBuffer buf = input.c_str();
	CharLower(buf.data());
	return buf;
#else
	return input.Lower();
#endif
}
Example #21
0
bool FileUtils::FuzzyMatch(const wxString& needle, const wxString& haystack)
{
    wxString word;
    size_t offset = 0;
    wxString lcHaystack = haystack.Lower();
    while(NextWord(needle, offset, word, true)) {
        if(!lcHaystack.Contains(word)) { return false; }
    }
    return true;
}
CMP_TREE_NODE_LIB::CMP_TREE_NODE_LIB( CMP_TREE_NODE* aParent,
                                      wxString const& aName, wxString const& aDesc )
{
    Type = LIB;
    Name = aName;
    MatchName = aName.Lower();
    Desc = aDesc;
    Parent = aParent;
    LibId.SetLibNickname( aName );
}
Example #23
0
const Model_Payee::Data_Set Model_Payee::FilterPayees(const wxString& payee_pattern)
{
    Data_Set payees;
    for (auto &payee : this->all(Model_Payee::COL_PAYEENAME))
    {
        if (payee.PAYEENAME.Lower().Matches(payee_pattern.Lower().Append("*")))
            payees.push_back(payee);
    }
    return payees;
}
Example #24
0
void EditorColourSet::SetFileMasks(HighlightLanguage lang, const wxString& masks, const wxString& separator)
{
    if (lang != HL_NONE)
    {
        m_Sets[lang].m_FileMasks = GetArrayFromString(masks.Lower(), separator);

        // let's add these filemasks in the file filters master list ;)
        FileFilters::Add(wxString::Format(_("%s files"), m_Sets[lang].m_Langs.c_str()), masks);
    }
}
Example #25
0
//----------------------------------------------------------------
bool PenvHelper::ParseBoolean(const wxString& boolstring)
/**
 * \brief Parses a boolean value string into a boolean
 * variable.
 * \param boolstring Boolean string.
 * \return True or false.
 **/
{
    return (boolstring.Lower().Cmp(_T("true")) == 0);
}
Example #26
0
// Tests for a filename extension in both upper and lower case, if the filesystem happens
// to be case-sensitive.
bool pxFileExists_WithExt( const wxFileName& filename, const wxString& ext )
{
	wxFileName part1 = filename;
	part1.SetExt( ext.Lower() );

	if (part1.FileExists()) return true;
	if (!wxFileName::IsCaseSensitive()) return false;

	part1.SetExt( ext.Upper() );
	return part1.FileExists();
}
bool OpenResourceDlg::IsMatchesFilter(const wxString& filter, const wxString& key)
{
    wxString lcKey = key.Lower();
    wxArrayString filters = ::wxStringTokenize(filter, " ", wxTOKEN_STRTOK);
    for(size_t i=0; i<filters.GetCount(); ++i) {
        wxString lcFilter = filters.Item(i).Lower();
        if(lcKey.Contains(lcFilter)) continue;
        else return false;
    }
    return true;
}
Example #28
0
wxEndianness wxPlatformInfo::GetEndianness(const wxString& end)
{
    const wxString endl(end.Lower());
    if ( endl.StartsWith(wxT("little")) )
        return wxENDIAN_LITTLE;

    if ( endl.StartsWith(wxT("big")) )
        return wxENDIAN_BIG;

    return wxENDIAN_INVALID;
}
Example #29
0
std::function<bool (wxString)> get_predicate(int mode, wxRegEx *re, bool match_case, wxString const& match_text) {
	using std::placeholders::_1;

	switch (mode) {
		case MODE_REGEXP:
			return [=](wxString str) { return re->Matches(str); };
		case MODE_EXACT:
			if (match_case)
				return std::bind(std::equal_to<wxString>(), match_text, _1);
			else
				return bind(std::equal_to<wxString>(), match_text.Lower(), std::bind(&wxString::Lower, _1));
		case MODE_CONTAINS:
			if (match_case)
				return std::bind(&wxString::Contains, _1, match_text);
			else
				return bind(&wxString::Contains, std::bind(&wxString::Lower, _1), match_text.Lower());
			break;
		default: throw agi::InternalError("Bad mode", 0);
	}
}
bool Model_Report::PrepareSQL(wxString& sql, std::map <wxString, wxString>& rep_params)
{
    sql.Trim();
    if (sql.empty()) return false;
    if (sql.Last() != ';') sql += ';';

    for (const auto& entry : SqlPlaceHolders())
    {
        wxString value;
        int pos = sql.Lower().Find(entry.label);
        size_t len = wxString(entry.label).size();

        if (pos != wxNOT_FOUND)
        {
            value = entry.def_value;

            const auto w = wxWindow::FindWindowById(entry.ID);
            //const auto name = w->GetClassInfo()->GetClassName();
            if (w && entry.type == "wxDatePickerCtrl")
            {
                    wxDatePickerCtrl* date = static_cast<wxDatePickerCtrl*>(w);
                    value = date->GetValue().FormatISODate();
            }
            else if (w && entry.type == "wxChoice")
            {
                    wxChoice* year = static_cast<wxChoice*>(w);
                    value = year->GetStringSelection();
            }

            rep_params[entry.label.Mid(1)] = value;

            while (pos != wxNOT_FOUND)
            {
                sql.replace(pos, len, value);
                pos = sql.Lower().Find(entry.label);
            }
        }
    }

    return true;
}