Skip to content

Commit a3a41c8

Browse files
committed
updates
1 parent b97825e commit a3a41c8

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

source/code/programs/repo_tools/visibility_adjuster/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ hcp(
2020
"//code/utilities/types/strings/transformers/trimming:lib",
2121
"//code/utilities/filesystem/files/getting:lib",
2222
"//code/utilities/types/strings/observers/regex:lib",
23+
"//code/utilities/types/strings/transformers/search_replace:lib",
2324
],
2425
)
2526

source/code/programs/repo_tools/visibility_adjuster/program_options/program_options.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ boost::program_options::options_description Program_Options::Get_Options_Descrip
4444
("commands",value<std::vector<std::string>>(),"commands to check with")
4545
("start-at",value<int>(),"where to start in the file iteration")
4646
("find",value<std::string>(),"regex to match on")
47+
("literal-find",value<std::string>(),"literal substring to match on")
4748
("replace",value<std::string>(),"what to replace the regex match with")
4849

4950
//+----------------------------------------------------------+
@@ -155,6 +156,13 @@ std::string Program_Options::Find() const{
155156
}
156157
return data;
157158
}
159+
std::string Program_Options::Literal_Find() const{
160+
std::string data;
161+
if (vm.count("literal-find")){
162+
data = vm["literal-find"].as<std::string>();
163+
}
164+
return data;
165+
}
158166
std::string Program_Options::Replace() const{
159167
std::string data;
160168
if (vm.count("replace")){

source/code/programs/repo_tools/visibility_adjuster/program_options/program_options.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Program_Options {
2424
std::vector<std::string> Commands() const;
2525
int Start_At() const;
2626
std::string Find() const;
27+
std::string Literal_Find() const;
2728
std::string Replace() const;
2829

2930

source/code/programs/repo_tools/visibility_adjuster/task_executer.hcp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class
1616
❪"code/utilities/types/strings/transformers/other/lib"❫
1717
❪"code/utilities/linguistics/computer/header_detection/cpp_header_detector"❫
1818
❪"code/utilities/types/strings/observers/regex/lib"❫
19+
❪"code/utilities/types/strings/observers/other/lib"❫
20+
❪"code/utilities/types/strings/transformers/search_replace/lib"❫
1921
2022
⚞⚟
2123

@@ -46,13 +48,29 @@ class
4648
◀private: static▶ std::string ☀Search_And_Replace(const std::string& input, const std::regex& pattern, const std::string& replacement) ❰
4749
return std::regex_replace(input, pattern, replacement);
4850
51+
◀private: static▶ std::vector<size_t> ☀Get_Indexes(const std::vector<std::string> & lines, Program_Options const& options) ❰
52+
if (!options.Find().empty())
53+
{
54+
return Get_Indexes_Where_Regex_Matches(lines,options.Find());
55+
}
56+
return Get_Index_Of_All_Lines_That_Contain_Substring(lines,options.Literal_Find());
57+
58+
◀private: static▶ std::string ☀Perform_Search_And_Replace(std::string str, Program_Options const& options)
59+
60+
if (!options.Find().empty())
61+
{
62+
return Search_And_Replace(str,std::regex(options.Find()),options.Replace());
63+
}
64+
return string_replace_all(str,options.Literal_Find(),options.Replace());
65+
66+
4967

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

5270
//open the file
5371
auto file_lines = Read_Each_Line_Of_File_Into_Vector(file);
5472

55-
auto file_indexes = Get_Indexes_Where_Regex_Matches(file_lines,options.Find());
73+
auto file_indexes = Get_Indexes(file_lines,options);
5674

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

6583
//get rid of the include statement
66-
file_lines[index] = Search_And_Replace(file_lines[index],std::regex(options.Find()),options.Replace());
84+
file_lines[index] = Perform_Search_And_Replace(file_lines[index],options);
6785
Write_Each_Line_Of_Vector_Into_File(file,file_lines);
6886

6987
std::cout << "removing " << visibility_line << " ";
@@ -91,7 +109,7 @@ class
91109

92110

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

source/code/utilities/types/strings/observers/other/lib.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ bool Contains_Substring(std::string const& str, char const& part){
6969
}
7070
return false;
7171
}
72+
std::vector<size_t> Get_Index_Of_All_Lines_That_Contain_Substring(std::vector<std::string> const& lines, std::string const& substring)
73+
{
74+
std::vector<size_t> indexes;
75+
for (size_t i = 0; i < lines.size(); ++i)
76+
{
77+
if (Contains_Substring(lines[i],substring))
78+
{
79+
indexes.emplace_back(i);
80+
}
81+
}
82+
return indexes;
83+
}
7284
bool Contains_Only_Whitespace_Characters(std::string const& str){
7385

7486
for (auto const& it: str){

source/code/utilities/types/strings/observers/other/lib.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ bool Ends_With(std::string const& str, char const& end_part);
1919
bool Begins_And_Ends_With(std::string const& str, char const& part);
2020
bool Contains_Substring(std::string const& str, std::string const& part);
2121
bool Contains_Substring(std::string const& str, char const& part);
22+
std::vector<size_t> Get_Index_Of_All_Lines_That_Contain_Substring(std::vector<std::string> const& lines, std::string const& substring);
23+
2224
std::string Get_Substring_Found_Between_First_Instance_Of_Two_Characters(std::string str, char first, char last);
2325
std::string Get_Substring_Found_Between_Two_Strings(std::string const& str, std::string const& before, std::string const& after);
2426

0 commit comments

Comments
 (0)