tab统一替换为4个空格键:#242

This commit is contained in:
xiongziliang 2020-03-20 11:51:24 +08:00
parent 2a0d78fd12
commit 1168174c2b
84 changed files with 6541 additions and 6520 deletions

@ -1 +1 @@
Subproject commit 34b42499ce9ee055b5c7cac9a270239984d0e839 Subproject commit d985d49f28b441216bf50020b7c6587edb5f43dc

View File

@ -126,6 +126,7 @@ void process_file(const char *file,bool rm_bom){
InfoL << (rm_bom ? "删除" : "添加") << "bom:" << file; InfoL << (rm_bom ? "删除" : "添加") << "bom:" << file;
} }
/// 这个程序是为了统一添加或删除utf-8 bom头
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CMD_main cmd_main; CMD_main cmd_main;
try { try {
@ -148,7 +149,7 @@ int main(int argc, char *argv[]) {
bool no_filter = filter_set.find("*") != filter_set.end(); bool no_filter = filter_set.find("*") != filter_set.end();
//设置日志 //设置日志
Logger::Instance().add(std::make_shared<ConsoleChannel>()); Logger::Instance().add(std::make_shared<ConsoleChannel>());
path = File::absolutePath(path, "");
for_each_file(path.data(),[&](const char *path){ for_each_file(path.data(),[&](const char *path){
if(!no_filter){ if(!no_filter){
//开启了过滤器 //开启了过滤器

View File

@ -1,18 +1,9 @@
#include <stdlib.h> #include <memory.h>
#include <memory.h>
#if !defined(_WIN32)
#include <dirent.h>
#endif //!defined(_WIN32)
#include <set> #include <set>
#include "Util/CMD.h" #include "Util/CMD.h"
#include "Util/util.h" #include "Util/util.h"
#include "Util/logger.h" #include "Util/logger.h"
#include "Util/File.h" #include "Util/File.h"
#include "Util/uv_errno.h"
using namespace std; using namespace std;
using namespace toolkit; using namespace toolkit;
@ -41,17 +32,40 @@ public:
virtual ~CMD_main() {} virtual ~CMD_main() {}
}; };
vector<string> split(const string& s, const char *delim) {
vector<string> ret;
int last = 0;
int index = s.find(delim, last);
while (index != string::npos) {
if (index - last >= 0) {
ret.push_back(s.substr(last, index - last));
}
last = index + strlen(delim);
index = s.find(delim, last);
}
if (!s.size() || s.size() - last >= 0) {
ret.push_back(s.substr(last));
}
return ret;
}
void process_file(const char *file) { void process_file(const char *file) {
auto str = File::loadFile(file); auto str = File::loadFile(file);
if (str.empty()) { if (str.empty()) {
return; return;
} }
auto lines = split(str, "\n"); auto lines = ::split(str, "\n");
deque<string> lines_copy; deque<string> lines_copy;
for (auto &line : lines) { for (auto &line : lines) {
if(line.empty()){
lines_copy.push_back("");
continue;
}
string line_copy; string line_copy;
bool flag = false; bool flag = false;
int i = 0;
for (auto &ch : line) { for (auto &ch : line) {
++i;
switch (ch) { switch (ch) {
case '\t' : case '\t' :
line_copy.append(" "); line_copy.append(" ");
@ -65,6 +79,7 @@ void process_file(const char *file) {
break; break;
} }
if (flag) { if (flag) {
line_copy.append(line.substr(i));
break; break;
} }
} }
@ -75,9 +90,13 @@ void process_file(const char *file) {
str.append(line); str.append(line);
str.push_back('\n'); str.push_back('\n');
} }
if(!lines_copy.empty()){
str.pop_back();
}
File::saveFile(str, file); File::saveFile(str, file);
} }
/// 这个程序是为了统一替换tab为4个空格
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
CMD_main cmd_main; CMD_main cmd_main;
try { try {
@ -87,10 +106,9 @@ int main(int argc, char *argv[]) {
return -1; return -1;
} }
bool rm_bom = cmd_main.hasKey("rm");
string path = cmd_main["in"]; string path = cmd_main["in"];
string filter = cmd_main["filter"]; string filter = cmd_main["filter"];
auto vec = split(filter, ","); auto vec = ::split(filter, ",");
set<string> filter_set; set<string> filter_set;
for (auto ext : vec) { for (auto ext : vec) {
@ -100,6 +118,8 @@ int main(int argc, char *argv[]) {
bool no_filter = filter_set.find("*") != filter_set.end(); bool no_filter = filter_set.find("*") != filter_set.end();
//设置日志 //设置日志
Logger::Instance().add(std::make_shared<ConsoleChannel>()); Logger::Instance().add(std::make_shared<ConsoleChannel>());
path = File::absolutePath(path, "");
DebugL << path;
File::scanDir(path, [&](const string &path, bool isDir) { File::scanDir(path, [&](const string &path, bool isDir) {
if (isDir) { if (isDir) {
return true; return true;