Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
luxe committed Aug 9, 2024
1 parent b97825e commit a3a41c8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions source/code/programs/repo_tools/visibility_adjuster/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ hcp(
"//code/utilities/types/strings/transformers/trimming:lib",
"//code/utilities/filesystem/files/getting:lib",
"//code/utilities/types/strings/observers/regex:lib",
"//code/utilities/types/strings/transformers/search_replace:lib",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ boost::program_options::options_description Program_Options::Get_Options_Descrip
("commands",value<std::vector<std::string>>(),"commands to check with")
("start-at",value<int>(),"where to start in the file iteration")
("find",value<std::string>(),"regex to match on")
("literal-find",value<std::string>(),"literal substring to match on")
("replace",value<std::string>(),"what to replace the regex match with")

//+----------------------------------------------------------+
Expand Down Expand Up @@ -155,6 +156,13 @@ std::string Program_Options::Find() const{
}
return data;
}
std::string Program_Options::Literal_Find() const{
std::string data;
if (vm.count("literal-find")){
data = vm["literal-find"].as<std::string>();
}
return data;
}
std::string Program_Options::Replace() const{
std::string data;
if (vm.count("replace")){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Program_Options {
std::vector<std::string> Commands() const;
int Start_At() const;
std::string Find() const;
std::string Literal_Find() const;
std::string Replace() const;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class
"code/utilities/types/strings/transformers/other/lib"
"code/utilities/linguistics/computer/header_detection/cpp_header_detector"
"code/utilities/types/strings/observers/regex/lib"
"code/utilities/types/strings/observers/other/lib"
"code/utilities/types/strings/transformers/search_replace/lib"
⚞⚟

Expand Down Expand Up @@ -46,13 +48,29 @@ class
private: static▶ std::string ☀Search_And_Replace(const std::string& input, const std::regex& pattern, const std::string& replacement) ❰
return std::regex_replace(input, pattern, replacement);
private: static▶ std::vector<size_t>Get_Indexes(const std::vector<std::string> & lines, Program_Options const& options) ❰
if (!options.Find().empty())
{
return Get_Indexes_Where_Regex_Matches(lines,options.Find());
}
return Get_Index_Of_All_Lines_That_Contain_Substring(lines,options.Literal_Find());
private: static▶ std::string ☀Perform_Search_And_Replace(std::string str, Program_Options const& options)
if (!options.Find().empty())
{
return Search_And_Replace(str,std::regex(options.Find()),options.Replace());
}
return string_replace_all(str,options.Literal_Find(),options.Replace());


private: static▶ void ☀Prune_File(std::string file, Program_Options const& options) ❰

//open the file
auto file_lines = Read_Each_Line_Of_File_Into_Vector(file);

auto file_indexes = Get_Indexes_Where_Regex_Matches(file_lines,options.Find());
auto file_indexes = Get_Indexes(file_lines,options);

std::cout << file_indexes.size() << " visibilities detected." << std::endl;
//std::cout << Profile_Compilation_Timer::Profile(file) << std::endl;
Expand All @@ -63,7 +81,7 @@ class
auto visibility_line = file_lines[index];

//get rid of the include statement
file_lines[index] = Search_And_Replace(file_lines[index],std::regex(options.Find()),options.Replace());
file_lines[index] = Perform_Search_And_Replace(file_lines[index],options);
Write_Each_Line_Of_Vector_Into_File(file,file_lines);

std::cout << "removing " << visibility_line << " ";
Expand Down Expand Up @@ -91,7 +109,7 @@ class


//print how many visibilities were fixed
auto file_indexes_after = Get_Indexes_Where_Regex_Matches(file_lines,options.Find());
auto file_indexes_after = Get_Indexes(file_lines,options);
auto visibilities_fixed = file_indexes.size() - file_indexes_after.size();
std::cout << visibilities_fixed << " visibilities fixed." << std::endl;

Expand Down
12 changes: 12 additions & 0 deletions source/code/utilities/types/strings/observers/other/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ bool Contains_Substring(std::string const& str, char const& part){
}
return false;
}
std::vector<size_t> Get_Index_Of_All_Lines_That_Contain_Substring(std::vector<std::string> const& lines, std::string const& substring)
{
std::vector<size_t> indexes;
for (size_t i = 0; i < lines.size(); ++i)
{
if (Contains_Substring(lines[i],substring))
{
indexes.emplace_back(i);
}
}
return indexes;
}
bool Contains_Only_Whitespace_Characters(std::string const& str){

for (auto const& it: str){
Expand Down
2 changes: 2 additions & 0 deletions source/code/utilities/types/strings/observers/other/lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ bool Ends_With(std::string const& str, char const& end_part);
bool Begins_And_Ends_With(std::string const& str, char const& part);
bool Contains_Substring(std::string const& str, std::string const& part);
bool Contains_Substring(std::string const& str, char const& part);
std::vector<size_t> Get_Index_Of_All_Lines_That_Contain_Substring(std::vector<std::string> const& lines, std::string const& substring);

std::string Get_Substring_Found_Between_First_Instance_Of_Two_Characters(std::string str, char first, char last);
std::string Get_Substring_Found_Between_Two_Strings(std::string const& str, std::string const& before, std::string const& after);

Expand Down

0 comments on commit a3a41c8

Please sign in to comment.