summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-17 00:55:09 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-17 00:55:18 +0300
commitfcf4c08536267a7be624b057c28586f510c0af2c (patch)
treebec56b865c84c4bd03f4120d8432f05cd2da0742 /src
parentcaf2e3c4fb749561c37eaff324de86a9edf83808 (diff)
downloadmanaverse-fcf4c08536267a7be624b057c28586f510c0af2c.tar.gz
manaverse-fcf4c08536267a7be624b057c28586f510c0af2c.tar.bz2
manaverse-fcf4c08536267a7be624b057c28586f510c0af2c.tar.xz
manaverse-fcf4c08536267a7be624b057c28586f510c0af2c.zip
Improve a bit links replace function.
Diffstat (limited to 'src')
-rw-r--r--src/utils/stringutils.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index e000b83c7..830b0346a 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -976,11 +976,13 @@ void replaceItemLinks(std::string &msg)
// Check for item link
size_t start2 = msg.find('[');
size_t sz = msg.size();
- while (start2 + 1 < sz && start2 != std::string::npos
- && msg[start2 + 1] != '@')
+ while (start2 + 1 < sz &&
+ start2 != std::string::npos &&
+ msg[start2 + 1] != '@')
{
const size_t end = msg.find(']', start2);
- if (start2 + 1 != end && end != std::string::npos)
+ if (start2 + 1 != end &&
+ end != std::string::npos)
{
// Catch multiple embeds and ignore them
// so it doesn't crash the client.
@@ -990,18 +992,18 @@ void replaceItemLinks(std::string &msg)
start2 = msg.find('[', start2 + 1);
}
- std::string temp;
- if (start2 + 1 < sz && end < sz && end > start2 + 1)
+ if (start2 + 1 < sz &&
+ end < sz &&
+ end > start2 + 1)
{
- temp = msg.substr(start2 + 1, end - start2 - 1);
+ std::string itemStr = msg.substr(start2 + 1, end - start2 - 1);
- const ItemInfo &itemInfo = ItemDB::get(temp);
+ const ItemInfo &itemInfo = ItemDB::get(itemStr);
if (itemInfo.getId() != 0)
{
+ std::string temp = strprintf("@@%d|", itemInfo.getId());
msg.insert(end, "@@");
- msg.insert(start2 + 1, "|");
- msg.insert(start2 + 1, toString(itemInfo.getId()));
- msg.insert(start2 + 1, "@@");
+ msg.insert(start2 + 1, temp);
sz = msg.size();
}
}