From d36d7a385d2d2fd1d6185250ca989ba746ee295b Mon Sep 17 00:00:00 2001 From: zvon Date: Sat, 1 Jun 2019 21:54:45 +0200 Subject: [PATCH] Formatting --- .clang-format | 24 ++++++++++++++++++++++++ filesystem.hpp | 1 - functions.cpp | 21 +++++++++++---------- main.cpp | 8 ++++---- network.cpp | 2 +- network.hpp | 2 +- seasonwindow.cpp | 2 +- tv_rename.cpp | 2 +- unix/filesystem.cpp | 8 +++++--- windows/filesystem.cpp | 6 +++--- 10 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b790a1c --- /dev/null +++ b/.clang-format @@ -0,0 +1,24 @@ +--- +AccessModifierOffset: -4 +AllowShortFunctionsOnASingleLine: Empty +BasedOnStyle: LLVM +ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' +ConstructorInitializerIndentWidth: 8 +Cpp11BracedListStyle: 'false' +IndentWidth: '4' +Language: Cpp +PointerAlignment: Right +SortIncludes: 'true' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: 'false' +SpacesInAngles: 'true' +SpacesInCStyleCastParentheses: 'true' +SpacesInContainerLiterals: 'true' +SpacesInParentheses: 'true' +SpacesInSquareBrackets: 'false' +Standard: Cpp11 +TabWidth: '4' +UseTab: Never + +... diff --git a/filesystem.hpp b/filesystem.hpp index 4a2cfa6..177156e 100644 --- a/filesystem.hpp +++ b/filesystem.hpp @@ -118,7 +118,6 @@ public: return dir_path.c_str(); } - private: string dir_path; }; diff --git a/functions.cpp b/functions.cpp index b4753fa..6411674 100644 --- a/functions.cpp +++ b/functions.cpp @@ -129,7 +129,7 @@ bool searchSpecificSeason( const char_t *const path, size_t &ep_pos, while ( path[cur_pos] == '0' ) cur_pos++; // if season number is 0, move back because previous loop skipped it - if( number == TEXT("0") ) + if ( number == TEXT( "0" ) ) cur_pos--; // make sure season's number is the same as provided in argument // `number` @@ -193,8 +193,8 @@ void iterateFS( std::map< int, std::set< string > > &seasons, // if file is a correct format, add it to file list // for its season if ( searchSeason( p, season_pos ) ) - seasons[std::stoi( p + season_pos )].insert( - path + dir_divider + p ); + seasons[std::stoi( p + season_pos )].insert( path + dir_divider + + p ); } } @@ -286,11 +286,13 @@ void printHelp() { cout << "Usage:" << std::endl; cout << " tv_rename [options] [path]" << std::endl << std::endl; cout << " -h, --help show this help message and exit" - << std::endl << std::endl; + << std::endl + << std::endl; cout << " path can be either a file or a directory, if it's a directory" << std::endl; cout << " all files in it and its subdirectories will be renamed" - << std::endl << std::endl; + << std::endl + << std::endl; cout << "OPTIONS" << std::endl; cout << " -s, --show TV show from which you want the"; cout << " episode names" << std::endl; @@ -394,12 +396,11 @@ getPossibleShows( string show, const string &language, Curl &c ) { show = encodeUrl( show ); #ifdef _WIN32 auto source_code = utf8_to_wstring( - c.execute( TEXT( "https://www.thetvdb.com/search?q=" ) + - show + TEXT( "&l=" ) + language ) ); + c.execute( TEXT( "https://www.thetvdb.com/search?q=" ) + show + + TEXT( "&l=" ) + language ) ); #else - auto source_code = - c.execute( TEXT( "https://www.thetvdb.com/search?q=" ) + - show + TEXT( "&l=" ) + language ); + auto source_code = c.execute( TEXT( "https://www.thetvdb.com/search?q=" ) + + show + TEXT( "&l=" ) + language ); #endif size_t pos{}; std::vector< std::pair< string, string > > urls; diff --git a/main.cpp b/main.cpp index 0bc9792..d216178 100644 --- a/main.cpp +++ b/main.cpp @@ -163,7 +163,7 @@ int parseCommandLine( string &show, std::set< int > &seasons_num, string &path, { "print-langs", no_argument, 0, '0' }, { "name-pattern", required_argument, 0, '1' }, { "help", no_argument, 0, 'h' }, - { 0, 0, 0, 0} + { 0, 0, 0, 0 } }; int i{}; // this is useless, but needed for handleArgument @@ -224,7 +224,7 @@ int main if ( !FSLib::isDirectory( path ) && FSLib::exists( path ) ) { // specified file, not directory - auto *file_set = new std::set; + auto *file_set = new std::set< string >; file_set->insert( path ); size_t season_pos{}; if ( !searchSeason( path.c_str(), season_pos ) ) { @@ -233,8 +233,8 @@ int main return 1; } else { auto season = std::stoi( path.c_str() + season_pos ); - singleSeason( path, show, season, TEXT(""), language, pattern, - linux, trust, c, file_set ); + singleSeason( path, show, season, TEXT( "" ), language, pattern, + linux, trust, c, file_set ); return 0; } } else if ( !FSLib::isDirectory( path ) ) { diff --git a/network.cpp b/network.cpp index 74ee373..23dbdb1 100644 --- a/network.cpp +++ b/network.cpp @@ -1,5 +1,5 @@ -#include #include "network.hpp" +#include #ifdef _WIN32 diff --git a/network.hpp b/network.hpp index 41ec21b..09226e7 100644 --- a/network.hpp +++ b/network.hpp @@ -3,8 +3,8 @@ #ifdef _WIN32 -#include #include +#include using string = std::wstring; diff --git a/seasonwindow.cpp b/seasonwindow.cpp index f473d3b..008cf6b 100644 --- a/seasonwindow.cpp +++ b/seasonwindow.cpp @@ -1,5 +1,5 @@ -#include #include "seasonwindow.hpp" +#include void SeasonWindow::confirm() { // go through all checkbuttons and save numbers diff --git a/tv_rename.cpp b/tv_rename.cpp index 7a318a7..b3056c9 100644 --- a/tv_rename.cpp +++ b/tv_rename.cpp @@ -13,10 +13,10 @@ #ifndef GUI +#include "filesystem.hpp" #include #include #include -#include "filesystem.hpp" #endif diff --git a/unix/filesystem.cpp b/unix/filesystem.cpp index 9918d12..a748830 100644 --- a/unix/filesystem.cpp +++ b/unix/filesystem.cpp @@ -1,9 +1,10 @@ -#include #include "../filesystem.hpp" +#include FSLib::Directory::Directory( const string &path_ ) : dir_path( path_ ) {} -FSLib::Directory::Iterator::Iterator( const Directory &d_ ) : d( opendir( d_.path() ) ) { +FSLib::Directory::Iterator::Iterator( const Directory &d_ ) + : d( opendir( d_.path() ) ) { current_entry = readdir( d ); if ( current_entry != nullptr && ( !strcmp( current_entry->d_name, "." ) || @@ -11,7 +12,8 @@ FSLib::Directory::Iterator::Iterator( const Directory &d_ ) : d( opendir( d_.pat ++( *this ); } -FSLib::Directory::Iterator::Iterator( const Directory &d_, const struct dirent *current_entry_ ) +FSLib::Directory::Iterator::Iterator( const Directory &d_, + const struct dirent *current_entry_ ) : d( opendir( d_.path() ) ), current_entry( current_entry_ ) {} FSLib::Directory::Iterator::~Iterator() { diff --git a/windows/filesystem.cpp b/windows/filesystem.cpp index fa49268..8077530 100644 --- a/windows/filesystem.cpp +++ b/windows/filesystem.cpp @@ -1,10 +1,10 @@ +#include "../filesystem.hpp" #include #include -#include "../filesystem.hpp" FSLib::Directory::Directory( const string &path_ ) : dir_path( path_ ) { - // need to append \\* for windows to search files in directory - dir_path.append( L"\\*" ); + // need to append \\* for windows to search files in directory + dir_path.append( L"\\*" ); } FSLib::Directory::Iterator::Iterator( const Directory &d_ ) {