diff options
Diffstat (limited to 'src/address.cc')
-rw-r--r-- | src/address.cc | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/src/address.cc b/src/address.cc index 378eff5..94c812f 100644 --- a/src/address.cc +++ b/src/address.cc @@ -1,8 +1,8 @@ /** - * @file address.cc - * @brief Implementation of the Address class - * @author Andreas Aardal Hanssen - * @date 2005 + * @file address.cc + * @brief Implementation of the Address class + * @author Andreas Aardal Hanssen + * @date 2005 */ #include "address.h" @@ -13,48 +13,34 @@ using namespace Binc; using std::string; +using std::string_view; -Address::Address(const string &name, const string &addr) +Address Address::from(string name, string_view addr) { - auto pos = addr.find('@'); - - this->name = name; - - if (pos != string::npos) { - this->local = addr.substr(0, pos); - this->host = addr.substr(pos + 1); - } else { - this->local = addr; - } + if (auto pos = addr.find('@'); pos != string::npos) + return Address{std::move(name), string{addr.substr(0, pos)}, string{addr.substr(pos + 1)}}; + else + return Address{std::move(name), string{addr}}; } -Address::Address(const string &wholeaddress) +Address Address::from(string_view wholeaddress) { auto start = wholeaddress.find('<'); - string addr; - - if (start != string::npos) - addr = wholeaddress.substr(start + 1); - else - addr = wholeaddress; + auto addr = start != string::npos ? wholeaddress.substr(start + 1) : wholeaddress; + auto name = start != string::npos ? wholeaddress.substr(0, start) : ""; trim(addr, "<>"); - - if (start != string::npos) - name = wholeaddress.substr(0, start); - else - name = ""; - trim(name); trim(name, "\""); start = addr.find('@'); - local = addr.substr(0, start); - host = addr.substr(start + 1); + auto local = addr.substr(0, start); + auto host = addr.substr(start + 1); trim(local); trim(host); - trim(name); + + return Address{string{name}, string{local}, string{host}}; } string Address::toParenList() const |