diff options
author | Ira Rice <irarice@gmail.com> | 2009-01-20 18:05:26 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-01-20 18:05:26 -0700 |
commit | c6d75d9aad1775e60cc63516e844cf54623a3974 (patch) | |
tree | bc704b0beb8bff0e8579034ab30c69c50dec721e /src/gui/chat.cpp | |
parent | 36bd28ec6bfcf1e15fdf4378ce7a5687cad604bd (diff) | |
download | mana-c6d75d9aad1775e60cc63516e844cf54623a3974.tar.gz mana-c6d75d9aad1775e60cc63516e844cf54623a3974.tar.bz2 mana-c6d75d9aad1775e60cc63516e844cf54623a3974.tar.xz mana-c6d75d9aad1775e60cc63516e844cf54623a3974.zip |
Added the ability to parse multiple item links, as well as removing
extra spaces before or after the [] tags.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/chat.cpp')
-rw-r--r-- | src/gui/chat.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 4c03f618..ef625753 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -358,27 +358,34 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) // check for item link std::string::size_type start = msg.find('['); - if (start != std::string::npos && msg[start+1] != '@') + while (start != std::string::npos && msg[start+1] != '@') { std::string::size_type end = msg.find(']', start); if (end != std::string::npos) { - std::string temp = msg.substr(start+1, end-1); + std::string temp = msg.substr(start+1, end - start - 1); + + while (temp[0] == ' ') + { + temp = temp.substr(1, temp.size()); + } + while (temp[temp.size()] == ' ') + { + temp = temp.substr(0, temp.size() - 1); + } for (unsigned int i = 0; i < temp.size(); i++) { temp[i] = (char) tolower(temp[i]); } - std::cout << temp << std::endl; - - ItemInfo itemInfo = ItemDB::get(temp); + const ItemInfo itemInfo = ItemDB::get(temp); msg.insert(end, "@@"); msg.insert(start+1, "|"); msg.insert(start+1, toString(itemInfo.getId())); msg.insert(start+1, "@@"); - } + start = msg.find('[', start + 1); } // Prepare ordinary message |