From: Mikko Rasa Date: Sun, 11 Dec 2022 12:06:36 +0000 (+0200) Subject: Use the append function from string utilities X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=commitdiff_plain;h=1ccb251524403a7318908e076c4f805bd3927247 Use the append function from string utilities --- diff --git a/source/http/request.cpp b/source/http/request.cpp index 437b8ba..685de33 100644 --- a/source/http/request.cpp +++ b/source/http/request.cpp @@ -53,11 +53,7 @@ Request Request::from_url(const string &str) string path = urlencode(url.path); if(path.empty()) path = "/"; - if(!url.query.empty()) - { - path += '?'; - path += url.query; - } + append(path, "?", url.query); Request result("GET", path); result.set_header("Host", url.host); diff --git a/source/http/utils.cpp b/source/http/utils.cpp index 8aa966c..7e1037e 100644 --- a/source/http/utils.cpp +++ b/source/http/utils.cpp @@ -106,16 +106,8 @@ string build_url(const Url &url) str += url.scheme+"://"; str += url.host; str += urlencode(url.path); - if(!url.query.empty()) - { - str += '?'; - str += url.query; - } - if(!url.fragment.empty()) - { - str += '#'; - str += url.fragment; - } + append(str, "?", url.query); + append(str, "#", url.fragment); return str; } @@ -137,9 +129,7 @@ string build_query(const Query &query) string str; for(const auto &kvp: query) { - if(!str.empty()) - str += '&'; - str += urlencode_plus(kvp.first); + append(str, "&", urlencode_plus(kvp.first)); str += '='; str += urlencode_plus(kvp.second); } diff --git a/source/net/inet6.cpp b/source/net/inet6.cpp index 7580058..da584d4 100644 --- a/source/net/inet6.cpp +++ b/source/net/inet6.cpp @@ -1,6 +1,7 @@ #include "inet6.h" #include "platform_api.h" #include +#include #include "sockaddr_private.h" using namespace std; @@ -34,9 +35,9 @@ string Inet6Addr::str() const string result = "["; for(unsigned i=0; i<16; i+=2) { - unsigned short part = (addr[i]<<8) | addr[i+1]; if(i>0) result += ':'; + unsigned short part = (addr[i]<<8) | addr[i+1]; result += format("%x", part); } result += ']';