summaryrefslogtreecommitdiff
path: root/src/utils/stringutils.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-03-03 02:50:03 +0200
committerAndrei Karas <akaras@inbox.ru>2011-03-03 02:50:03 +0200
commitde51eaa43e05c2126fc1eef2a7e115843f972547 (patch)
tree286a05a069e048247f90c7595f1b8939be784608 /src/utils/stringutils.cpp
parentd4c08d3bf69410a35a50875de50cc6fe74b3bf3e (diff)
parent8627c7745f47492ab349da6a74e98e3d5813418f (diff)
downloadplus-de51eaa43e05c2126fc1eef2a7e115843f972547.tar.gz
plus-de51eaa43e05c2126fc1eef2a7e115843f972547.tar.bz2
plus-de51eaa43e05c2126fc1eef2a7e115843f972547.tar.xz
plus-de51eaa43e05c2126fc1eef2a7e115843f972547.zip
Merge branch 'coloritems'
Diffstat (limited to 'src/utils/stringutils.cpp')
-rw-r--r--src/utils/stringutils.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index d914efe30..63924eb78 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -387,3 +387,54 @@ std::list<int> splitToIntList(const std::string &text, char separator)
return tokens;
}
+
+
+std::list<std::string> splitToStringList(const std::string &text,
+ char separator)
+{
+ std::list<std::string> 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())
+ return file;
+ size_t pos = file.find_last_of("|");
+ if (pos != std::string::npos)
+ 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<std::string> list1 = splitToStringList(dye1, ';');
+ std::list<std::string> list2 = splitToStringList(dye, ';');
+ std::list<std::string>::iterator it1, it1_end = list1.end();
+ std::list<std::string>::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;
+ }
+}