Commit 8de2bac5 authored by Guolin Ke's avatar Guolin Ke
Browse files

fix error while using quotation marks in parameters.

parent 9649512e
...@@ -34,6 +34,15 @@ inline static std::string& Trim(std::string& str) { ...@@ -34,6 +34,15 @@ inline static std::string& Trim(std::string& str) {
return str; return str;
} }
inline static std::string& RemoveQuotationSymbol(std::string& str) {
if (str.size() <= 0) {
return str;
}
str.erase(str.find_last_not_of("'\"") + 1);
str.erase(0, str.find_first_not_of("'\""));
return str;
}
inline static std::vector<std::string> Split(const char* str, char delimiter) { inline static std::vector<std::string> Split(const char* str, char delimiter) {
std::stringstream ss(str); std::stringstream ss(str);
std::string tmp_str; std::string tmp_str;
......
...@@ -61,8 +61,8 @@ void Application::LoadParameters(int argc, char** argv) { ...@@ -61,8 +61,8 @@ void Application::LoadParameters(int argc, char** argv) {
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
std::vector<std::string> tmp_strs = Common::Split(argv[i], '='); std::vector<std::string> tmp_strs = Common::Split(argv[i], '=');
if (tmp_strs.size() == 2) { if (tmp_strs.size() == 2) {
std::string key = Common::Trim(tmp_strs[0]); std::string key = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[0]));
std::string value = Common::Trim(tmp_strs[1]); std::string value = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[1]));
if (key.size() <= 0) { if (key.size() <= 0) {
continue; continue;
} }
...@@ -84,8 +84,8 @@ void Application::LoadParameters(int argc, char** argv) { ...@@ -84,8 +84,8 @@ void Application::LoadParameters(int argc, char** argv) {
} }
std::vector<std::string> tmp_strs = Common::Split(line.c_str(), '='); std::vector<std::string> tmp_strs = Common::Split(line.c_str(), '=');
if (tmp_strs.size() == 2) { if (tmp_strs.size() == 2) {
std::string key = Common::Trim(tmp_strs[0]); std::string key = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[0]));
std::string value = Common::Trim(tmp_strs[1]); std::string value = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[1]));
if (key.size() <= 0) { if (key.size() <= 0) {
continue; continue;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment