mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
config: trim spaces and tabs
This commit is contained in:
parent
57b874ee6d
commit
6ef38709a6
11
common.cpp
11
common.cpp
@ -607,3 +607,14 @@ int run_command_no_log(string command0,char * &output) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
// Remove preceding and trailing characters
|
||||||
|
string trim(const string& str, char c) {
|
||||||
|
size_t first = str.find_first_not_of(c);
|
||||||
|
if(string::npos==first)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
size_t last = str.find_last_not_of(c);
|
||||||
|
return str.substr(first,(last-first+1));
|
||||||
|
}
|
||||||
|
2
common.h
2
common.h
@ -164,6 +164,8 @@ int read_file(const char * file,char * &output);
|
|||||||
vector<string> string_to_vec(const char * s,const char * sp);
|
vector<string> string_to_vec(const char * s,const char * sp);
|
||||||
vector< vector <string> > string_to_vec2(const char * s);
|
vector< vector <string> > string_to_vec2(const char * s);
|
||||||
|
|
||||||
|
string trim(const string& str, char c);
|
||||||
|
|
||||||
//extern string iptables_pattern;
|
//extern string iptables_pattern;
|
||||||
|
|
||||||
#endif /* COMMON_H_ */
|
#endif /* COMMON_H_ */
|
||||||
|
11
main.cpp
11
main.cpp
@ -2545,6 +2545,12 @@ void print_help()
|
|||||||
//printf("common options,these options must be same on both side\n");
|
//printf("common options,these options must be same on both side\n");
|
||||||
}
|
}
|
||||||
void process_arg(int argc, char *argv[], bool read_config = true);
|
void process_arg(int argc, char *argv[], bool read_config = true);
|
||||||
|
std::string trim_config_line(std::string line)
|
||||||
|
{
|
||||||
|
auto str = trim(line, ' '); // Space
|
||||||
|
str = trim(str, ' '); // Tab
|
||||||
|
return str;
|
||||||
|
}
|
||||||
void load_config(char *config_file, int argc_orig, char *argv_orig[])
|
void load_config(char *config_file, int argc_orig, char *argv_orig[])
|
||||||
{
|
{
|
||||||
// Load configurations from config_file instead of the command line.
|
// Load configurations from config_file instead of the command line.
|
||||||
@ -2554,6 +2560,7 @@ void load_config(char *config_file, int argc_orig, char *argv_orig[])
|
|||||||
std::vector<std::string> arguments;
|
std::vector<std::string> arguments;
|
||||||
while(std::getline(conf_file,line))
|
while(std::getline(conf_file,line))
|
||||||
{
|
{
|
||||||
|
line = trim_config_line(line);
|
||||||
if(line==""||line.at(0)=='#')
|
if(line==""||line.at(0)=='#')
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -2567,8 +2574,8 @@ void load_config(char *config_file, int argc_orig, char *argv_orig[])
|
|||||||
{
|
{
|
||||||
auto p1 = line.substr(0,pos);
|
auto p1 = line.substr(0,pos);
|
||||||
auto p2 = line.substr(pos+1,line.length() - pos - 1);
|
auto p2 = line.substr(pos+1,line.length() - pos - 1);
|
||||||
arguments.push_back(p1);
|
arguments.push_back(trim_config_line(p1));
|
||||||
arguments.push_back(p2);
|
arguments.push_back(trim_config_line(p2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conf_file.close();
|
conf_file.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user