Made the delimited string functions in StringUtil more general.

This commit is contained in:
Leon Styhre 2021-02-06 09:30:05 +01:00
parent 280ee6aa4e
commit 72fcef8428
4 changed files with 13 additions and 20 deletions

View file

@ -226,8 +226,8 @@ void CollectionSystemsManager::loadCollectionSystems()
void CollectionSystemsManager::loadEnabledListFromSettings()
{
// We parse the auto collection settings list.
std::vector<std::string> autoSelected = Utils::String::commaStringToVector(
Settings::getInstance()->getString("CollectionSystemsAuto"), true);
std::vector<std::string> autoSelected = Utils::String::delimitedStringToVector(
Settings::getInstance()->getString("CollectionSystemsAuto"), ",", true);
// Iterate the map.
for (std::map<std::string, CollectionSystemData, stringComparator>::iterator
@ -241,8 +241,8 @@ void CollectionSystemsManager::loadEnabledListFromSettings()
mHasEnabledCustomCollection = false;
// Parse the custom collection settings list.
std::vector<std::string> customSelected = Utils::String::commaStringToVector(
Settings::getInstance()->getString("CollectionSystemsCustom"), true);
std::vector<std::string> customSelected = Utils::String::delimitedStringToVector(
Settings::getInstance()->getString("CollectionSystemsCustom"), ",", true);
// Iterate the map.
for (std::map<std::string, CollectionSystemData, stringComparator>::iterator

View file

@ -51,8 +51,8 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(
it->second.isEnabled);
addWithLabel("AUTOMATIC GAME COLLECTIONS", collection_systems_auto);
addSaveFunc([this, autoSystems] {
std::string autoSystemsSelected =
Utils::String::vectorToCommaString(collection_systems_auto->getSelectedObjects(), true);
std::string autoSystemsSelected = Utils::String::vectorToDelimitedString(
collection_systems_auto->getSelectedObjects(), ",", true);
std::string autoSystemsConfig = Settings::getInstance()->getString("CollectionSystemsAuto");
if (autoSystemsSelected != autoSystemsConfig) {
if (CollectionSystemsManager::get()->isEditing())
@ -100,8 +100,8 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(
addWithLabel("CUSTOM GAME COLLECTIONS", collection_systems_custom);
addSaveFunc([this, customSystems] {
if (!mDeletedCustomCollection) {
std::string customSystemsSelected = Utils::String::vectorToCommaString(
collection_systems_custom->getSelectedObjects(), true);
std::string customSystemsSelected = Utils::String::vectorToDelimitedString(
collection_systems_custom->getSelectedObjects(), ",", true);
std::string customSystemsConfig = Settings::getInstance()->
getString("CollectionSystemsCustom");
if (customSystemsSelected != customSystemsConfig) {

View file

@ -522,13 +522,8 @@ namespace Utils
return vector;
}
std::vector<std::string> commaStringToVector(const std::string& _string,
bool sort, bool caseInsensitive)
{
return delimitedStringToVector(_string, ",", sort, caseInsensitive);
}
std::string vectorToCommaString(std::vector<std::string> _vector, bool caseInsensitive)
std::string vectorToDelimitedString(std::vector<std::string> _vector,
const std::string& _delimiter, bool caseInsensitive)
{
std::string string;
@ -541,7 +536,7 @@ namespace Utils
for (std::vector<std::string>::const_iterator it = _vector.cbegin();
it != _vector.cend(); it++)
string += (string.length() ? "," : "") + (*it);
string += (string.length() ? _delimiter : "") + (*it);
return string;
}

View file

@ -36,10 +36,8 @@ namespace Utils
std::string removeParenthesis(const std::string& _string);
std::vector<std::string> delimitedStringToVector(const std::string& _string,
const std::string& _delimiter, bool sort = false, bool caseInsensitive = false);
std::vector<std::string> commaStringToVector(const std::string& _string,
bool sort = false, bool caseInsensitive = false);
std::string vectorToCommaString(std::vector<std::string> _vector,
bool caseInsensitive = false);
std::string vectorToDelimitedString(std::vector<std::string> _vector,
const std::string& _delimiter, bool caseInsensitive = false);
std::string format(const char* _string, ...);
std::string scramble(const std::string& _input, const std::string& key);
}