]> git.tdb.fi Git - libs/net.git/commitdiff
Use the append function from string utilities
authorMikko Rasa <tdb@tdb.fi>
Sun, 11 Dec 2022 12:06:36 +0000 (14:06 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 11 Dec 2022 16:26:44 +0000 (18:26 +0200)
source/http/request.cpp
source/http/utils.cpp
source/net/inet6.cpp

index 437b8ba6aff4ab476d3388192d3db7aa78fbdfab..685de332371749d35b7665e7619e399c39726f29 100644 (file)
@@ -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);
index 8aa966cd09fc88a45092d46b4d37e72323beb9c3..7e1037e693d42094679d59ec905375eb6cd81ffe 100644 (file)
@@ -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);
        }
index 758005860582dc968ef2064e6d2047e19376fe5c..da584d4880ebd43dda084565fa90233b0a0792cb 100644 (file)
@@ -1,6 +1,7 @@
 #include "inet6.h"
 #include "platform_api.h"
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #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 += ']';