diff options
author | louiz’ <louiz@louiz.org> | 2016-12-11 16:34:38 +0100 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2016-12-11 16:34:38 +0100 |
commit | f653906f9de8cbcecf5717e18c696d1029fc2c8f (patch) | |
tree | 0ad6e57692b4728ff744650b3ba238cf35c52209 | |
parent | 36252ad217ee0c8846cafce8fa35c2e776e39605 (diff) | |
download | biboumi-f653906f9de8cbcecf5717e18c696d1029fc2c8f.tar.gz biboumi-f653906f9de8cbcecf5717e18c696d1029fc2c8f.tar.bz2 biboumi-f653906f9de8cbcecf5717e18c696d1029fc2c8f.tar.xz biboumi-f653906f9de8cbcecf5717e18c696d1029fc2c8f.zip |
Add a None type for the Iid class (when the iid is completely empty)
-rw-r--r-- | src/irc/iid.cpp | 5 | ||||
-rw-r--r-- | src/irc/iid.hpp | 1 | ||||
-rw-r--r-- | tests/iid.cpp | 6 |
3 files changed, 11 insertions, 1 deletions
diff --git a/src/irc/iid.cpp b/src/irc/iid.cpp index d442013..6b07793 100644 --- a/src/irc/iid.cpp +++ b/src/irc/iid.cpp @@ -34,9 +34,10 @@ Iid::Iid(const std::string& iid, const Bridge *bridge) void Iid::set_type(const std::set<char>& chantypes) { + if (this->local.empty() && this->server.empty()) + this->type = Iid::Type::None; if (this->local.empty()) return; - if (chantypes.count(this->local[0]) == 1) this->type = Iid::Type::Channel; else @@ -105,6 +106,8 @@ namespace std { { if (iid.type == Iid::Type::Server) return iid.get_server(); + else if (iid.get_local().empty() && iid.get_server().empty()) + return {}; else return iid.get_encoded_local() + iid.separator + iid.get_server(); } diff --git a/src/irc/iid.hpp b/src/irc/iid.hpp index 44861c1..81cf3ca 100644 --- a/src/irc/iid.hpp +++ b/src/irc/iid.hpp @@ -53,6 +53,7 @@ public: Channel, User, Server, + None, }; static constexpr char separator[]{"%"}; Iid(const std::string& iid, const std::set<char>& chantypes); diff --git a/tests/iid.cpp b/tests/iid.cpp index b42b9e5..3da0396 100644 --- a/tests/iid.cpp +++ b/tests/iid.cpp @@ -83,6 +83,12 @@ TEST_CASE("Iid creation") CHECK(iid6.get_local() == "##channel"); CHECK(iid6.get_server() == ""); CHECK(iid6.type == Iid::Type::Channel); + + Iid iid7("", chantypes); + CHECK(std::to_string(iid7) == ""); + CHECK(iid7.get_local() == ""); + CHECK(iid7.get_server() == ""); + CHECK(iid7.type == Iid::Type::None); } TEST_CASE("Iid creation in fixed_server mode") |