string_view refactor

This commit is contained in:
Jack Andersen 2017-11-12 20:18:02 -10:00
parent 3c4a99fbe8
commit ec0589ec23
2 changed files with 5 additions and 5 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) # because of CMAKE_CXX_STANDARD cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) # because of CMAKE_CXX_STANDARD
project(jbus) project(jbus)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(WIN32) if(WIN32)

View File

@ -39,7 +39,7 @@ class IPAddress
uint32_t m_address = 0; uint32_t m_address = 0;
bool m_valid = false; bool m_valid = false;
void resolve(const std::string& address) void resolve(std::string_view address)
{ {
m_address = 0; m_address = 0;
m_valid = false; m_valid = false;
@ -60,7 +60,7 @@ class IPAddress
{ {
/* Try to convert the address as a byte representation ("xxx.xxx.xxx.xxx") */ /* Try to convert the address as a byte representation ("xxx.xxx.xxx.xxx") */
struct in_addr addr; struct in_addr addr;
if (inet_pton(AF_INET, address.c_str(), &addr) == 1) if (inet_pton(AF_INET, address.data(), &addr) == 1)
{ {
m_address = addr.s_addr; m_address = addr.s_addr;
m_valid = true; m_valid = true;
@ -72,7 +72,7 @@ class IPAddress
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
addrinfo* result = NULL; addrinfo* result = NULL;
if (getaddrinfo(address.c_str(), NULL, &hints, &result) == 0) if (getaddrinfo(address.data(), NULL, &hints, &result) == 0)
{ {
if (result) if (result)
{ {
@ -87,7 +87,7 @@ class IPAddress
} }
public: public:
IPAddress(const std::string& address) IPAddress(std::string_view address)
{ {
resolve(address); resolve(address);
} }