From 22f79fd0d623c8e11994905534f53da267e22935 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 3 Mar 2011 01:25:21 +0200 Subject: Dehardcode item colors. Now reading all from configs. --- src/utils/stringutils.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/utils/stringutils.h | 5 +++++ 2 files changed, 46 insertions(+) (limited to 'src/utils') diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 835f9ce00..63924eb78 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -388,6 +388,19 @@ std::list splitToIntList(const std::string &text, char separator) return tokens; } + +std::list splitToStringList(const std::string &text, + char separator) +{ + std::list tokens; + std::stringstream ss(text); + std::string item; + while(std::getline(ss, item, separator)) + tokens.push_back(item); + + return tokens; +} + std::string combineDye(std::string file, std::string dye) { if (dye.empty()) @@ -397,3 +410,31 @@ std::string combineDye(std::string file, std::string dye) return file.substr(0, pos) + "|" + dye; return file + "|" + dye; } + +std::string combineDye2(std::string file, std::string dye) +{ + if (dye.empty()) + return file; + + size_t pos = file.find_last_of("|"); + if (pos != std::string::npos) + { + std::string dye1 = file.substr(pos + 1); + std::string str = ""; + file = file.substr(0, pos); + std::list list1 = splitToStringList(dye1, ';'); + std::list list2 = splitToStringList(dye, ';'); + std::list::iterator it1, it1_end = list1.end(); + std::list::iterator it2, it2_end = list2.end(); + for (it1 = list1.begin(), it2 = list2.begin(); + it1 != it1_end && it2 != it2_end; ++it1, ++it2) + { + str += (*it1) + ":" + (*it2) + ";"; + } + return file + "|" + str; + } + else + { + return file; + } +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 52b47e6a2..02c25eddb 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -170,6 +170,11 @@ std::set splitToIntSet(const std::string &text, char separator); std::list splitToIntList(const std::string &text, char separator); +std::list splitToStringList(const std::string &text, + char separator); + std::string combineDye(std::string file, std::string dye); +std::string combineDye2(std::string file, std::string dye); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-70-g09d2