]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
WIP: Clean-up DNSName constructor unify with string_view.
authorAxel Viala <axel.viala@darnuria.eu>
Mon, 22 Aug 2022 10:17:16 +0000 (12:17 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 30 Nov 2022 13:23:38 +0000 (14:23 +0100)
pdns/dnsname.cc
pdns/dnsname.hh

index 74a166a596040e5ada99ed662ecfccd764f87d48..747225e02b1feaac7e9f7b2601609d1a09992ab5 100644 (file)
@@ -53,8 +53,11 @@ void DNSName::throwSafeRangeError(const std::string& msg, const char* buf, size_
   throw std::range_error(msg + label + dots);
 }
 
-DNSName::DNSName(const char* p, size_t length)
+DNSName::DNSName(const std::string_view sw)
 {
+  const char* p = sw.data();
+  size_t length = sw.length();
+
   if(length == 0 || (length == 1 && p[0]=='.')) {
     d_storage.assign(1, (char)0);
   } else {
index a88c2586e0a462baa24195803746a17040425c19..90c752be3fa493a53a5c66cfcf7a355c473021e2 100644 (file)
@@ -31,6 +31,7 @@
 #include <sstream>
 #include <iterator>
 #include <unordered_set>
+#include <string_view>
 
 #include <boost/version.hpp>
 
@@ -97,9 +98,8 @@ public:
   }
   DNSName(const DNSName& a) = default;
   DNSName(DNSName&& a) = default;
-  explicit DNSName(const char* p): DNSName(p, std::strlen(p)) {} //!< Constructs from a human formatted, escaped presentation
-  explicit DNSName(const char* p, size_t len);      //!< Constructs from a human formatted, escaped presentation
-  explicit DNSName(const std::string& str) : DNSName(str.c_str(), str.length()) {}; //!< Constructs from a human formatted, escaped presentation
+
+  explicit DNSName(const std::string_view sw); //!< Constructs from a human formatted, escaped presentation
   DNSName(const char* p, int len, int offset, bool uncompress, uint16_t* qtype=nullptr, uint16_t* qclass=nullptr, unsigned int* consumed=nullptr, uint16_t minOffset=0); //!< Construct from a DNS Packet, taking the first question if offset=12. If supplied, consumed is set to the number of bytes consumed from the packet, which will not be equal to the wire length of the resulting name in case of compression.
 
   bool isPartOf(const DNSName& rhs) const;   //!< Are we part of the rhs name? Note that name.isPartOf(name).