2018-08-17 10:38:46 +00:00
|
|
|
#include <algorithm>
|
2018-08-17 10:40:14 +00:00
|
|
|
#include <llarp/service/address.hpp>
|
2018-07-16 03:32:13 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
std::string
|
2018-12-03 22:22:59 +00:00
|
|
|
Address::ToString(const char* tld) const
|
2018-07-16 03:32:13 +00:00
|
|
|
{
|
|
|
|
char tmp[(1 + 32) * 2] = {0};
|
|
|
|
std::string str = Base32Encode(*this, tmp);
|
2018-12-03 22:22:59 +00:00
|
|
|
return str + tld;
|
2018-07-16 03:32:13 +00:00
|
|
|
}
|
2018-08-02 00:48:43 +00:00
|
|
|
|
|
|
|
bool
|
2018-12-03 22:22:59 +00:00
|
|
|
Address::FromString(const std::string& str, const char* tld)
|
2018-08-02 00:48:43 +00:00
|
|
|
{
|
2018-12-03 22:22:59 +00:00
|
|
|
auto pos = str.find(tld);
|
2018-08-02 00:48:43 +00:00
|
|
|
if(pos == std::string::npos)
|
|
|
|
return false;
|
|
|
|
auto sub = str.substr(0, pos);
|
2018-08-17 10:38:46 +00:00
|
|
|
// make sure it's lowercase
|
2018-08-17 10:40:14 +00:00
|
|
|
std::transform(sub.begin(), sub.end(), sub.begin(), ::tolower);
|
2018-11-23 14:37:26 +00:00
|
|
|
|
2018-08-02 00:48:43 +00:00
|
|
|
return Base32Decode(sub, *this);
|
|
|
|
}
|
2018-07-16 03:32:13 +00:00
|
|
|
} // namespace service
|
2018-08-17 10:38:46 +00:00
|
|
|
} // namespace llarp
|