mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-02-02 05:52:31 +01:00
Some improvements to priority handling
Fixes issues with some strings that caused issues previously For example: 4,,1 is now handled correctly
This commit is contained in:
parent
a8e09a7f48
commit
887ac52563
@ -44,6 +44,7 @@ namespace Util
|
||||
std::string getHomeDir();
|
||||
std::string getConfigHome();
|
||||
std::string getCacheHome();
|
||||
std::vector<std::string> tokenize(const std::string& str, const std::string& separator = ",");
|
||||
}
|
||||
|
||||
#endif // UTIL_H
|
||||
|
9
main.cpp
9
main.cpp
@ -29,14 +29,11 @@ template<typename T> void set_vm_value(std::map<std::string, bpo::variable_value
|
||||
// Parse the priority string, making it an array of numeric codes, and override the ORed type if required
|
||||
void handle_priority(const std::string &what, const std::string &priority_string, std::vector<unsigned int> &priority, unsigned int &type)
|
||||
{
|
||||
size_t idx = 0, found;
|
||||
|
||||
while ((found = priority_string.find(',', idx)) != std::string::npos)
|
||||
std::vector<std::string> tokens = Util::tokenize(priority_string, ",");
|
||||
for (std::vector<std::string>::iterator it = tokens.begin(); it != tokens.end(); it++)
|
||||
{
|
||||
priority.push_back(std::stoi(priority_string.substr(idx, found - idx)));
|
||||
idx = found + 1;
|
||||
priority.push_back(std::stoi(*it));
|
||||
}
|
||||
priority.push_back(std::stoi(priority_string.substr(idx)));
|
||||
|
||||
unsigned int wanted = 0;
|
||||
#ifdef DEBUG
|
||||
|
19
src/util.cpp
19
src/util.cpp
@ -405,3 +405,22 @@ std::string Util::getCacheHome()
|
||||
cacheHome = Util::getHomeDir() + "/.cache";
|
||||
return cacheHome;
|
||||
}
|
||||
|
||||
std::vector<std::string> Util::tokenize(const std::string& str, const std::string& separator)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
std::string token;
|
||||
size_t idx = 0, found;
|
||||
while ((found = str.find(separator, idx)) != std::string::npos)
|
||||
{
|
||||
token = str.substr(idx, found - idx);
|
||||
if (!token.empty())
|
||||
tokens.push_back(token);
|
||||
idx = found + separator.length();
|
||||
}
|
||||
token = str.substr(idx);
|
||||
if (!token.empty())
|
||||
tokens.push_back(token);
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user