summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-06-15 19:25:09 +0300
committerAndrei Karas <akaras@inbox.ru>2013-06-15 19:25:09 +0300
commit649fdb1c512e9608aa05c99a08b867c8758eeaf8 (patch)
tree36aefb040eefdc08cef57f760b3ac67a842b56b8 /src/utils
parentffabda4c473711ffa8fdfe37c2a4460fe31347ac (diff)
downloadplus-649fdb1c512e9608aa05c99a08b867c8758eeaf8.tar.gz
plus-649fdb1c512e9608aa05c99a08b867c8758eeaf8.tar.bz2
plus-649fdb1c512e9608aa05c99a08b867c8758eeaf8.tar.xz
plus-649fdb1c512e9608aa05c99a08b867c8758eeaf8.zip
Add support for monster look.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/stringutils.cpp30
-rw-r--r--src/utils/stringutils.h3
-rw-r--r--src/utils/stringutils_unittest.cc14
3 files changed, 47 insertions, 0 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index a07cd1a96..a0e31f06d 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -508,6 +508,36 @@ std::string combineDye2(std::string file, const std::string &dye)
}
}
+std::string combineDye3(std::string file, const std::string &dye)
+{
+ if (dye.empty())
+ return file;
+
+ const size_t pos = file.find_last_of("|");
+ if (pos != std::string::npos)
+ {
+ const std::string dye1 = file.substr(pos + 1);
+ std::string str;
+ file = file.substr(0, pos);
+ const std::list<std::string> list1 = splitToStringList(dye1, ';');
+ const std::list<std::string> list2 = splitToStringList(dye, ';');
+ for (std::list<std::string>::const_iterator it1 = list1.begin(),
+ it2 = list2.begin(), it1_end = list1.end(), it2_end = list2.end();
+ it1 != it1_end && it2 != it2_end; ++it1, ++it2)
+ {
+ str.append(*it1).append(":").append(*it2).append(";");
+ }
+ return file.append("|").append(str);
+ }
+ else
+ {
+ if (dye.empty() || file.empty())
+ return file;
+ else
+ return file.append("|").append(dye);
+ }
+}
+
std::string packList(const std::list<std::string> &list)
{
std::list<std::string>::const_iterator i = list.begin();
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index eae73ce40..96645261b 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -198,6 +198,9 @@ std::string combineDye(std::string file, const std::string &dye) A_WARN_UNUSED;
std::string combineDye2(std::string file,
const std::string &dye) A_WARN_UNUSED;
+std::string combineDye3(std::string file,
+ const std::string &dye) A_WARN_UNUSED;
+
std::string packList(const std::list<std::string> &list) A_WARN_UNUSED;
std::list<std::string> unpackList(const std::string &str) A_WARN_UNUSED;
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index d3d274597..75f4f2f35 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -372,6 +372,20 @@ TEST(stringuntils, combineDye2)
combineDye2("test.xml|#43413d,59544f,7a706c;#123456", "W;B"));
}
+TEST(stringuntils, combineDye3)
+{
+ EXPECT_EQ("", combineDye3("", ""));
+ EXPECT_EQ("test", combineDye3("test", ""));
+ EXPECT_EQ("", combineDye3("", "line"));
+ EXPECT_EQ("test.xml|123", combineDye3("test.xml", "123"));
+ EXPECT_EQ("test.xml|#43413d,59544f,7a706c",
+ combineDye3("test.xml|#43413d,59544f,7a706c", ""));
+ EXPECT_EQ("test.xml|#43413d,59544f,7a706c:W;",
+ combineDye3("test.xml|#43413d,59544f,7a706c", "W"));
+ EXPECT_EQ("test.xml|#43413d,59544f,7a706c:W;#123456:B;",
+ combineDye3("test.xml|#43413d,59544f,7a706c;#123456", "W;B"));
+}
+
TEST(stringuntils, packList1)
{
std::list <std::string> list;