diff --git a/src/eepp/system/threadpool.cpp b/src/eepp/system/threadpool.cpp index 87ac0a318..d1cf57b47 100644 --- a/src/eepp/system/threadpool.cpp +++ b/src/eepp/system/threadpool.cpp @@ -21,7 +21,7 @@ ThreadPool::ThreadPool( Uint32 numThreads, bool terminateOnClose ) : mTerminateOnClose( terminateOnClose ) { for ( Uint32 i = 0; i < numThreads; ++i ) { mThreads.emplace_back( std::make_unique( &ThreadPool::threadFunc, this ) ); - mThreads.back().get()->launch(); + mThreads.back()->launch(); } } @@ -35,9 +35,9 @@ ThreadPool::~ThreadPool() { for ( auto& t : mThreads ) { if ( terminateOnClose() ) { - t.get()->terminate(); + t->terminate(); } else { - t.get()->wait(); + t->wait(); } } } diff --git a/src/eepp/system/translator.cpp b/src/eepp/system/translator.cpp index 1ec6d3a5c..90b57c367 100644 --- a/src/eepp/system/translator.cpp +++ b/src/eepp/system/translator.cpp @@ -64,18 +64,6 @@ bool Translator::loadNodes( pugi::xml_node node, std::string lang ) { return true; } -static size_t countLines( const std::string_view& text ) { - const char* startPtr = text.data(); - const char* endPtr = text.data() + text.size(); - size_t count = 0; - if ( startPtr != endPtr ) { - count = 1 + *startPtr == '\n' ? 1 : 0; - while ( ++startPtr && startPtr != endPtr ) - count += ( '\n' == *startPtr ) ? 1 : 0; - } - return count; -} - bool Translator::loadFromFile( const std::string& path, std::string lang ) { if ( FileSystem::fileExists( path ) ) { lang = lang.size() == 2 @@ -91,10 +79,6 @@ bool Translator::loadFromFile( const std::string& path, std::string lang ) { Log::error( "Couldn't load i18n file: %s", path.c_str() ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); - std::string file; - FileSystem::fileGet( path, file ); - Log::error( "Error line: %d", - countLines( std::string_view{ file }.substr( 0, result.offset ) ) + 1 ); } } else if ( PackManager::instance()->isFallbackToPacksActive() ) { std::string packPath( path ); @@ -116,8 +100,6 @@ bool Translator::loadFromString( const std::string& string, std::string lang ) { Log::error( "Couldn't load i18n file from string: %s", string.c_str() ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); - Log::error( "Error line: %d", - countLines( std::string_view{ string }.substr( 0, result.offset ) ) + 1 ); } return false; } @@ -132,10 +114,6 @@ bool Translator::loadFromMemory( const void* buffer, Int32 bufferSize, std::stri Log::error( "Couldn't load i18n file from buffer" ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); - Log::error( "Error line: %d", - countLines( std::string_view{ (const char*)buffer, (size_t)bufferSize }.substr( - 0, result.offset ) ) + - 1 ); } return false; } diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 4427f5c66..f8796d543 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -1137,7 +1137,7 @@ bool UICodeEditor::onCreateContextMenu( const Vector2i& position, const Uint32& return; UIMenuItem* item = event->getNode()->asType(); std::string txt( item->getId() ); - mDoc.get()->execute( txt, editor ); + mDoc->execute( txt, editor ); menu->hide(); } ); }; diff --git a/src/tools/ecode/filesystemlistener.cpp b/src/tools/ecode/filesystemlistener.cpp index e7827e4e0..9df59a519 100644 --- a/src/tools/ecode/filesystemlistener.cpp +++ b/src/tools/ecode/filesystemlistener.cpp @@ -1,4 +1,5 @@ #include "filesystemlistener.hpp" +#include #include namespace ecode { @@ -50,10 +51,10 @@ void FileSystemListener::handleFileAction( efsw::WatchID, const std::string& dir } if ( mFileSystemModel ) - mFileSystemModel.get()->handleFileEvent( event ); + mFileSystemModel->handleFileEvent( event ); if ( mDirTree ) - mDirTree.get()->onChange( (ProjectDirectoryTree::Action)action, file, oldFilename ); + mDirTree->onChange( (ProjectDirectoryTree::Action)action, file, oldFilename ); if ( action == efsw::Actions::Moved ) { FileInfo oldFile( FileSystem::isRelativePath( oldFilename ) ? dir + oldFilename diff --git a/src/tools/ecode/globalsearchcontroller.cpp b/src/tools/ecode/globalsearchcontroller.cpp index 42f7a8309..c8c578835 100644 --- a/src/tools/ecode/globalsearchcontroller.cpp +++ b/src/tools/ecode/globalsearchcontroller.cpp @@ -61,7 +61,7 @@ size_t GlobalSearchController::replaceInFiles( const std::string& replaceText, return count; } - const ProjectSearch::Result& res = model.get()->getResult(); + const ProjectSearch::Result& res = model->getResult(); bool hasCaptures = model->isResultFromLuaPattern() && LuaPattern::find( replaceText, "$%d+" ).isValid(); diff --git a/src/tools/ecode/ignorematcher.cpp b/src/tools/ecode/ignorematcher.cpp index f01e42e0d..578318277 100644 --- a/src/tools/ecode/ignorematcher.cpp +++ b/src/tools/ecode/ignorematcher.cpp @@ -14,8 +14,8 @@ namespace ecode { #define PATHSEP '/' #define CASE( c, caseInsensitive ) ( caseInsensitive ? std::tolower( c ) : ( c ) ) -bool gitignore_glob_match( const std::string& text, const std::string& glob, - bool caseInsensitive = false ) { +bool IgnoreMatcher::globMatch( const std::string& text, const std::string_view& glob, + bool caseInsensitive ) { size_t i = 0; size_t j = 0; size_t n = text.size(); @@ -142,6 +142,15 @@ bool gitignore_glob_match( const std::string& text, const std::string& glob, return j >= m; } +bool IgnoreMatcher::globMatch( const std::string& text, const std::vector& globs, + bool caseInsensitive ) { + for ( const auto& glob : globs ) { + if ( globMatch( text, glob, caseInsensitive ) ) + return true; + } + return false; +} + IgnoreMatcher::IgnoreMatcher( const std::string& rootPath ) : mPath( rootPath ) { FileSystem::dirAddSlashAtEnd( mPath ); } @@ -198,7 +207,7 @@ bool GitIgnoreMatcher::match( const std::string& value ) const { bool match = false; for ( size_t i = 0; i < mPatterns.size(); i++ ) { auto& pattern = mPatterns[i]; - match = gitignore_glob_match( value, pattern.first ); + match = globMatch( value, pattern.first ); if ( pattern.second ) match = !match; if ( match && !pattern.second ) { @@ -206,7 +215,7 @@ bool GitIgnoreMatcher::match( const std::string& value ) const { for ( size_t n = i + 1; n < mPatterns.size(); n++ ) { // Check if there's a positive negate after the match if ( mPatterns[n].second ) { - if ( gitignore_glob_match( value, mPatterns[n].first ) ) + if ( globMatch( value, mPatterns[n].first ) ) return false; } else { break; diff --git a/src/tools/ecode/ignorematcher.hpp b/src/tools/ecode/ignorematcher.hpp index e6786faea..22a2f94a8 100644 --- a/src/tools/ecode/ignorematcher.hpp +++ b/src/tools/ecode/ignorematcher.hpp @@ -1,7 +1,7 @@ #ifndef ECODE_IGNOREMATCHER_HPP #define ECODE_IGNOREMATCHER_HPP -#include +#include #include #include @@ -28,6 +28,12 @@ class IgnoreMatcher { const bool& matcherReady() const { return mMatcherReady; } + static bool globMatch( const std::string& text, const std::string_view& glob, + bool caseInsensitive = false ); + + static bool globMatch( const std::string& text, const std::vector& globs, + bool caseInsensitive = false ); + protected: std::string mPath; bool mMatcherReady{ false }; diff --git a/src/tools/ecode/plugins/git/git.cpp b/src/tools/ecode/plugins/git/git.cpp index d9177b9c6..67dc1dab2 100644 --- a/src/tools/ecode/plugins/git/git.cpp +++ b/src/tools/ecode/plugins/git/git.cpp @@ -1,3 +1,4 @@ +#include "../../stringhelper.hpp" #include "git.hpp" #include #include @@ -14,30 +15,6 @@ using namespace std::literals; namespace ecode { -static size_t countLines( const std::string& text ) { - const char* startPtr = text.c_str(); - const char* endPtr = text.c_str() + text.size(); - size_t count = 0; - if ( startPtr != endPtr ) { - count = 1 + *startPtr == '\n' ? 1 : 0; - while ( ++startPtr && startPtr != endPtr ) - count += ( '\n' == *startPtr ) ? 1 : 0; - } - return count; -} - -static void readAllLines( const std::string_view& buf, - std::function onLineRead, - char sep = '\n' ) { - auto lastNL = 0; - auto nextNL = buf.find_first_of( sep ); - while ( nextNL != std::string_view::npos ) { - onLineRead( buf.substr( lastNL, nextNL - lastNL ) ); - lastNL = nextNL + 1; - nextNL = buf.find_first_of( sep, nextNL + 1 ); - } -} - static constexpr auto sNotCommitedYetHash = "0000000000000000000000000000000000000000"; Git::Blame::Blame( const std::string& error ) : error( error ), line( 0 ) {} @@ -469,9 +446,9 @@ std::vector Git::getAllBranchesAndTags( RefType ref, std::string_vi std::string buf; if ( EXIT_SUCCESS == git( args, projectDir, buf ) ) { - branches.reserve( countLines( buf ) ); + branches.reserve( StringHelper::countLines( buf ) ); - readAllLines( buf, [&]( const std::string_view& line ) { + StringHelper::readBySeparator( buf, [&]( const std::string_view& line ) { auto branch = String::trim( String::trim( line, '\'' ), '\t' ); if ( ( ref & Head ) && String::startsWith( branch, "refs/heads/" ) ) { branches.emplace_back( parseLocalBranch( branch ) ); @@ -484,10 +461,10 @@ std::vector Git::getAllBranchesAndTags( RefType ref, std::string_vi } if ( ( ref & RefType::Stash ) && EXIT_SUCCESS == git( "stash list", projectDir, buf ) ) { - branches.reserve( branches.size() + countLines( buf ) ); + branches.reserve( branches.size() + StringHelper::countLines( buf ) ); std::string ptrn( "(stash@{%d+}):%s(.*)" ); LuaPattern pattern( ptrn ); - readAllLines( buf, [&]( const std::string_view& line ) { + StringHelper::readBySeparator( buf, [&]( const std::string_view& line ) { LuaPattern::Range matches[3]; if ( pattern.matches( line.data(), 0, matches, line.size() ) ) { std::string id( @@ -512,7 +489,7 @@ std::vector Git::fetchSubModules( const std::string& projectDir ) { FileSystem::fileGet( ( !projectDir.empty() ? projectDir : mProjectPath ) + ".gitmodules", buf ); std::string ptrn( "^%s*path%s*=%s*(.+)" ); LuaPattern pattern( ptrn ); - readAllLines( buf, [&pattern, &submodules]( const std::string_view& line ) { + StringHelper::readBySeparator( buf, [&pattern, &submodules]( const std::string_view& line ) { LuaPattern::Range matches[2]; if ( pattern.matches( line.data(), 0, matches, line.size() ) ) { submodules.emplace_back( String::trim( @@ -597,12 +574,12 @@ Git::Status Git::status( bool recurseSubmodules, const std::string& projectDir ) std::string subModulePath = ""; std::string ptrn = "^([mMARTUD?%s][mMARTUD?%s])%s(.*)"; LuaPattern pattern( ptrn ); - size_t changesCount = countLines( buf ); + size_t changesCount = StringHelper::countLines( buf ); if ( changesCount > 1000 ) return; - readAllLines( buf, [&]( const std::string_view& line ) { + StringHelper::readBySeparator( buf, [&]( const std::string_view& line ) { LuaPattern::Range matches[3]; if ( subModulePattern.matches( line.data(), 0, matches, line.size() ) ) { subModulePath = String::trim( @@ -678,7 +655,7 @@ Git::Status Git::status( bool recurseSubmodules, const std::string& projectDir ) std::string ptrn( "(%d+)%s+(%d+)%s+(.+)" ); LuaPattern pattern( ptrn ); std::string subModulePath = ""; - readAllLines( buf, [&]( const std::string_view& line ) { + StringHelper::readBySeparator( buf, [&]( const std::string_view& line ) { LuaPattern::Range matches[4]; if ( subModulePattern.matches( line.data(), 0, matches, line.size() ) ) { subModulePath = String::trim( @@ -753,7 +730,7 @@ Git::Status Git::status( bool recurseSubmodules, const std::string& projectDir ) std::string fileText; FileSystem::fileGet( ( projectDir.empty() ? mProjectPath : projectDir ) + val.file, fileText ); - val.inserts = countLines( fileText ); + val.inserts = StringHelper::countLines( fileText ); s.totalInserts += val.inserts; } } diff --git a/src/tools/ecode/plugins/linter/linterplugin.cpp b/src/tools/ecode/plugins/linter/linterplugin.cpp index 7c4e504b5..898bbe680 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.cpp +++ b/src/tools/ecode/plugins/linter/linterplugin.cpp @@ -1,4 +1,5 @@ -#include "linterplugin.hpp" +#include "../../stringhelper.hpp" +#include "linterplugin.hpp" #include #include #include @@ -1351,18 +1352,6 @@ void LinterPlugin::unregisterNativeLinter( const std::string& cmd ) { mNativeLinters.erase( cmd ); } -static size_t countLines( const std::string_view& text ) { - const char* startPtr = text.data(); - const char* endPtr = text.data() + text.size(); - size_t count = 0; - if ( startPtr != endPtr ) { - count = 1 + *startPtr == '\n' ? 1 : 0; - while ( ++startPtr && startPtr != endPtr ) - count += ( '\n' == *startPtr ) ? 1 : 0; - } - return count; -} - void LinterPlugin::registerNativeLinters() { if ( !mNativeLinters.empty() ) return; @@ -1374,7 +1363,7 @@ void LinterPlugin::registerNativeLinters() { std::string file; FileSystem::fileGet( path, file ); std::string_view filesv{ file }; - Int64 line = countLines( filesv.substr( 0, result.offset ) ); + Int64 line = StringHelper::countLines( filesv.substr( 0, result.offset ) ); Int64 offset = 0; auto lastNL = filesv.substr( 0, result.offset ).find_last_of( '\n' ); if ( lastNL != std::string_view::npos ) diff --git a/src/tools/ecode/projectdirectorytree.cpp b/src/tools/ecode/projectdirectorytree.cpp index 4472839a5..961568d72 100644 --- a/src/tools/ecode/projectdirectorytree.cpp +++ b/src/tools/ecode/projectdirectorytree.cpp @@ -418,8 +418,15 @@ void ProjectDirectoryTree::moveFile( const FileInfo& file, const std::string& ol FileSystem::dirAddSlashAtEnd( dir ); size_t index = findFileIndex( dir + oldFilename ); if ( index != std::string::npos ) { - mFiles[index] = file.getFilepath(); - mNames[index] = file.getFileName(); + IgnoreMatcherManager matcher( getIgnoreMatcherFromPath( file.getFilepath() ) ); + if ( !( mIgnoreHidden && file.isHidden() ) && + ( !matcher.foundMatch() || !matcher.match( file ) ) ) { + mFiles[index] = file.getFilepath(); + mNames[index] = file.getFileName(); + } else { + mFiles.erase( mFiles.begin() + index ); + mNames.erase( mNames.begin() + index ); + } } else { tryAddFile( file ); } diff --git a/src/tools/ecode/stringhelper.cpp b/src/tools/ecode/stringhelper.cpp new file mode 100644 index 000000000..a329016e7 --- /dev/null +++ b/src/tools/ecode/stringhelper.cpp @@ -0,0 +1,29 @@ +#include "stringhelper.hpp" + +namespace ecode { + +void StringHelper::readBySeparator( const std::string_view& buf, + std::function onSepChunkRead, + char sep ) { + auto lastNL = 0; + auto nextNL = buf.find_first_of( sep ); + while ( nextNL != std::string_view::npos ) { + onSepChunkRead( buf.substr( lastNL, nextNL - lastNL ) ); + lastNL = nextNL + 1; + nextNL = buf.find_first_of( sep, nextNL + 1 ); + } +} + +size_t StringHelper::countLines( const std::string_view& text ) { + const char* startPtr = text.data(); + const char* endPtr = text.data() + text.size(); + size_t count = 0; + if ( startPtr != endPtr ) { + count = 1 + *startPtr == '\n' ? 1 : 0; + while ( ++startPtr && startPtr != endPtr ) + count += ( '\n' == *startPtr ) ? 1 : 0; + } + return count; +} + +} // namespace ecode diff --git a/src/tools/ecode/stringhelper.hpp b/src/tools/ecode/stringhelper.hpp new file mode 100644 index 000000000..01d3c991f --- /dev/null +++ b/src/tools/ecode/stringhelper.hpp @@ -0,0 +1,19 @@ +#ifndef ECODE_STRINGHELPER +#define ECODE_STRINGHELPER + +#include +#include + +namespace ecode { + +struct StringHelper { + static void readBySeparator( const std::string_view& buf, + std::function onSepChunkRead, + char sep = '\n' ); + + static size_t countLines( const std::string_view& text ); +}; + +} // namespace ecode + +#endif