bool wxExVCS::Execute() { const wxExFileName filename(GetFile()); if (!filename.IsOk()) { return m_Entry.Execute( m_Entry.GetCommand().IsAdd() ? wxExConfigFirstOf(_("Path")): std::string(), wxExLexer(), true, wxExConfigFirstOf(_("Base folder"))); } else { std::string args; std::string wd; if (m_Files.size() > 1) { for (const auto& it : m_Files) { args += "\"" + it + "\" "; } } else if (m_Entry.GetName() == "git") { const std::string admin_dir(FindEntry(filename).GetAdminDir()); wd = GetTopLevelDir(admin_dir, filename); if (!filename.GetFullName().empty()) { args = GetRelativeFile( admin_dir, filename); } } else if (m_Entry.GetName() == "sccs") { args = "\"" + // sccs for windows does not handle windows paths, // so convert them to UNIX, and add volume as well. #ifdef __WXMSW__ filename.GetVolume() + wxFileName::GetVolumeSeparator() + #endif filename.GetFullPath(wxPATH_UNIX) + "\""; } else { args = "\"" + filename.GetFullPath() + "\""; } return m_Entry.Execute(args, filename.GetLexer(), true, wd); } }
const wxExLexer wxExLexers::FindByFileName( const wxFileName& filename) const { for ( auto it = m_Lexers.begin(); it != m_Lexers.end(); ++it) { if (wxExMatchesOneOf(filename, it->second.GetExtensions())) { return it->second; } } return wxExLexer(); }
const wxExLexer wxExLexers::FindByText(const wxString& text) const { // Add automatic lexers if text starts with some special tokens. const wxString text_lowercase = text.Lower(); if (text_lowercase.StartsWith("<html>")) { return FindByName("hypertext"); } else if (text_lowercase.StartsWith("<?xml")) { return FindByName("xml"); } // cpp files like #include <map> really do not have a .h extension // (e.g. /usr/include/c++/3.3.5/map) so add here. else if (text_lowercase.StartsWith("//")) { return FindByName("cpp"); } else if (text_lowercase.StartsWith("<?php")) { return FindByName("phpscript"); } else { // If there is a Shell Language Indicator, // match with bash. const wxRegEx re("#!.*/bin/.*"); if (re.Matches(text_lowercase)) { return FindByName("bash"); } } return wxExLexer(); }
const wxExLexer wxExLexers::FindByName(const wxString& name) const { const auto it = m_Lexers.find(name); return (it != m_Lexers.end() ? it->second: wxExLexer()); }
long wxExVCS::Execute() { const wxExFileName filename(GetFile()); if (!filename.IsOk()) { wxString args; if (m_Entry.GetCommand().IsAdd()) { args = wxExConfigFirstOf(_("Path")); } return m_Entry.Execute( args, wxExLexer(), wxExConfigFirstOf(_("Base folder"))); } else { wxString args; wxString wd; if (m_Files.size() > 1) { // File should not be surrounded by double quotes. for ( #ifdef wxExUSE_CPP0X auto it = m_Files.begin(); #else wxArrayString::iterator it = m_Files.begin(); #endif it != m_Files.end(); ++it) { args += *it + " "; } } else if (m_Entry.GetName().Lower() == "git") { const wxString admin_dir(FindEntry(filename).GetAdminDir()); wd = GetTopLevelDir(admin_dir, filename); if (!filename.GetFullName().empty()) { args = GetRelativeFile( admin_dir, filename); } } else if (m_Entry.GetName().Lower() == "sccs") { args = "\"" + // sccs for windows does not handle windows paths, // so convert them to UNIX, and add volume as well. #ifdef __WXMSW__ filename.GetVolume() + filename.GetVolumeSeparator() + #endif filename.GetFullPath(wxPATH_UNIX) + "\""; } else { args = "\"" + filename.GetFullPath() + "\""; } return m_Entry.Execute(args, filename.GetLexer(), wd); }
void fixture::testLexer() { wxExSTC* stc = new wxExSTC(m_Frame, "hello stc"); wxExLexer lexer; CPPUNIT_ASSERT(!lexer.IsOk()); CPPUNIT_ASSERT( wxExLexer("cpp").IsOk()); CPPUNIT_ASSERT( wxExLexer("pascal").IsOk()); CPPUNIT_ASSERT(!wxExLexer("xxx").IsOk()); lexer = wxExLexers::Get()->FindByText("XXXX"); CPPUNIT_ASSERT(!lexer.IsOk()); lexer = wxExLexers::Get()->FindByText("<html>"); CPPUNIT_ASSERT( lexer.IsOk()); CPPUNIT_ASSERT( lexer.GetDisplayLexer() == "hypertext"); lexer = wxExLexers::Get()->FindByText("// this is a cpp comment text"); CPPUNIT_ASSERT( lexer.IsOk()); CPPUNIT_ASSERT( wxExLexer(lexer).IsOk()); CPPUNIT_ASSERT( lexer.GetDisplayLexer() == "cpp"); CPPUNIT_ASSERT( lexer.GetScintillaLexer() == "cpp"); CPPUNIT_ASSERT(!lexer.GetExtensions().empty()); CPPUNIT_ASSERT(!lexer.GetCommentBegin().empty()); CPPUNIT_ASSERT(!lexer.GetCommentBegin2().empty()); CPPUNIT_ASSERT( lexer.GetCommentEnd().empty()); CPPUNIT_ASSERT(!lexer.GetCommentEnd2().empty()); CPPUNIT_ASSERT( lexer.GetLanguage().empty()); CPPUNIT_ASSERT(!lexer.GetKeywords().empty()); CPPUNIT_ASSERT(!lexer.GetKeywordsString().empty()); CPPUNIT_ASSERT(!lexer.GetKeywordsString(-1, 0).empty()); CPPUNIT_ASSERT(!lexer.GetKeywordsString(-1, 6).empty()); CPPUNIT_ASSERT( lexer.GetKeywordsString(-1, 8).Contains("for_each")); CPPUNIT_ASSERT(!lexer.GetKeywordsString(-1, 9).Contains("for_each")); CPPUNIT_ASSERT( lexer.GetKeywordsString(-1, 50).empty()); CPPUNIT_ASSERT( lexer.CommentComplete("// test").empty()); CPPUNIT_ASSERT( lexer.IsKeyword("class")); CPPUNIT_ASSERT( lexer.IsKeyword("const")); CPPUNIT_ASSERT( lexer.KeywordStartsWith("cla")); CPPUNIT_ASSERT(!lexer.KeywordStartsWith("xxx")); CPPUNIT_ASSERT(!lexer.MakeComment("test", true).empty()); CPPUNIT_ASSERT(!lexer.MakeComment("test", "test").empty()); CPPUNIT_ASSERT(!lexer.MakeSingleLineComment("test").empty()); CPPUNIT_ASSERT( lexer.GetKeywordsString(6).empty()); CPPUNIT_ASSERT( lexer.AddKeywords("hello:1")); CPPUNIT_ASSERT( lexer.AddKeywords("more:1")); CPPUNIT_ASSERT( lexer.AddKeywords( "test11 test21:1 test31:1 test12:2 test22:2")); CPPUNIT_ASSERT( lexer.AddKeywords("final", 6)); CPPUNIT_ASSERT(!lexer.AddKeywords("")); CPPUNIT_ASSERT(!lexer.AddKeywords("xxx:1", -1)); CPPUNIT_ASSERT(!lexer.AddKeywords("xxx:1", 100)); CPPUNIT_ASSERT(!lexer.GetKeywordsString(6).empty()); CPPUNIT_ASSERT( lexer.IsKeyword("hello")); CPPUNIT_ASSERT( lexer.IsKeyword("more")); CPPUNIT_ASSERT( lexer.IsKeyword("class")); CPPUNIT_ASSERT( lexer.IsKeyword("test11")); CPPUNIT_ASSERT( lexer.IsKeyword("test21")); CPPUNIT_ASSERT( lexer.IsKeyword("test12")); CPPUNIT_ASSERT( lexer.IsKeyword("test22")); CPPUNIT_ASSERT( lexer.IsKeyword("test31")); CPPUNIT_ASSERT( lexer.IsKeyword("final")); CPPUNIT_ASSERT(!lexer.IsKeyword("xxx")); CPPUNIT_ASSERT( lexer.KeywordStartsWith("te")); CPPUNIT_ASSERT(!lexer.KeywordStartsWith("xx")); CPPUNIT_ASSERT(!lexer.GetKeywords().empty()); lexer.SetProperty("test", "value"); wxString val; for (auto p : lexer.GetProperties()) { if (p.GetName() == "test") { val = p.GetValue(); break; } } CPPUNIT_ASSERT(val == "value"); CPPUNIT_ASSERT( lexer.Set("pascal", stc)); CPPUNIT_ASSERT( lexer.GetDisplayLexer() == "pascal"); CPPUNIT_ASSERT( lexer.GetScintillaLexer() == "pascal"); CPPUNIT_ASSERT(!lexer.CommentComplete("(*test").empty()); CPPUNIT_ASSERT( lexer.CommentComplete("(*test").EndsWith(" *)")); wxExLexer lexer2(wxExLexers::Get()->FindByText("// this is a cpp comment text")); CPPUNIT_ASSERT( lexer2.IsOk()); CPPUNIT_ASSERT( lexer2.GetDisplayLexer() == "cpp"); CPPUNIT_ASSERT( lexer2.GetScintillaLexer() == "cpp"); CPPUNIT_ASSERT( lexer2.Set(lexer, stc)); CPPUNIT_ASSERT( lexer2.GetDisplayLexer() == "pascal"); CPPUNIT_ASSERT( lexer2.GetScintillaLexer() == "pascal"); CPPUNIT_ASSERT(!lexer2.CommentComplete("(*test").empty()); CPPUNIT_ASSERT( lexer2.CommentComplete("(*test").EndsWith(" *)")); lexer.Reset(stc); CPPUNIT_ASSERT( lexer.GetDisplayLexer().empty()); CPPUNIT_ASSERT( lexer.GetScintillaLexer().empty()); CPPUNIT_ASSERT( lexer.Set("xsl", stc)); CPPUNIT_ASSERT( lexer.GetLanguage() == "xml"); }