code format
This commit is contained in:
+24
-24
@@ -36,34 +36,34 @@ std::string join(const std::vector<std::string> _vec, const std::string& _delim)
|
||||
return str;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim,
|
||||
const char _conn) {
|
||||
int first = 0;
|
||||
int last = str.find_first_of(_delim);
|
||||
std::vector<std::string> result;
|
||||
|
||||
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim, const char _conn){
|
||||
int first = 0;
|
||||
int last = str.find_first_of(_delim);
|
||||
std::vector<std::string> result;
|
||||
|
||||
while (first < str.size()) {
|
||||
result.push_back(str.substr(first, last - first));
|
||||
first = last + 1;
|
||||
last = str.find_first_of(_delim, first);
|
||||
if (last == std::string::npos) last = str.size();
|
||||
}
|
||||
while (first < str.size()) {
|
||||
result.push_back(str.substr(first, last - first));
|
||||
first = last + 1;
|
||||
last = str.find_first_of(_delim, first);
|
||||
if (last == std::string::npos) last = str.size();
|
||||
}
|
||||
|
||||
auto mp = std::unordered_map<std::string, std::string>();
|
||||
for(auto elm: result){
|
||||
int pos = elm.find_first_of(_conn);
|
||||
auto mp = std::unordered_map<std::string, std::string>();
|
||||
for (auto elm : result) {
|
||||
int pos = elm.find_first_of(_conn);
|
||||
|
||||
std::cout << pos << std::endl;
|
||||
if(pos == std::string::npos){
|
||||
mp.insert_or_assign(elm, "");
|
||||
}else{
|
||||
auto key = elm.substr(0, pos);
|
||||
auto val = elm.substr(pos + 1);
|
||||
mp.insert_or_assign(key, val);
|
||||
}
|
||||
}
|
||||
std::cout << pos << std::endl;
|
||||
if (pos == std::string::npos) {
|
||||
mp.insert_or_assign(elm, "");
|
||||
} else {
|
||||
auto key = elm.substr(0, pos);
|
||||
auto val = elm.substr(pos + 1);
|
||||
mp.insert_or_assign(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
return mp;
|
||||
return mp;
|
||||
}
|
||||
|
||||
} // namespace CocoaTweet::Util
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
namespace CocoaTweet::Util {
|
||||
std::string urlEncode(const std::string& _str);
|
||||
std::string join(const std::vector<std::string> _vec, const std::string& _delim);
|
||||
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim, const char _conn);
|
||||
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim,
|
||||
const char _conn);
|
||||
} // namespace CocoaTweet::Util
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user