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

View file

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

View file

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

View file

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