This will avoid future chicken-and-egg problems.
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
return dns_tolower_table[chr];
}
+inline int pdns_ilexicographical_compare_three_way(std::string_view a, std::string_view b) __attribute__((pure));
+inline int pdns_ilexicographical_compare_three_way(std::string_view a, std::string_view b)
+{
+ const unsigned char *aPtr = (const unsigned char*)a.data(), *bPtr = (const unsigned char*)b.data();
+ const unsigned char *aEptr = aPtr + a.length(), *bEptr = bPtr + b.length();
+ while(aPtr != aEptr && bPtr != bEptr) {
+ if (*aPtr != *bPtr) {
+ if (int rc = dns_tolower(*aPtr) - dns_tolower(*bPtr); rc != 0) {
+ return rc;
+ }
+ }
+ aPtr++;
+ bPtr++;
+ }
+ // At this point, one of the strings has been completely processed.
+ // Either both have the same length, and they are equal, or one of them
+ // is larger, and compares as higher.
+ if (aPtr == aEptr) {
+ if (bPtr != bEptr) {
+ return -1; // a < b
+ }
+ }
+ else {
+ return 1; // a > b
+ }
+ return 0; // a == b
+}
+
+inline bool pdns_ilexicographical_compare(const std::string& a, const std::string& b) __attribute__((pure));
+inline bool pdns_ilexicographical_compare(const std::string& a, const std::string& b)
+{
+ return pdns_ilexicographical_compare_three_way(a, b) < 0;
+}
+
+inline bool pdns_iequals(const std::string& a, const std::string& b) __attribute__((pure));
+inline bool pdns_iequals(const std::string& a, const std::string& b)
+{
+ if (a.length() != b.length())
+ return false;
+
+ return pdns_ilexicographical_compare_three_way(a, b) == 0;
+}
+
+inline bool pdns_iequals_ch(const char a, const char b) __attribute__((pure));
+inline bool pdns_iequals_ch(const char a, const char b)
+{
+ if ((a != b) && (dns_tolower(a) != dns_tolower(b)))
+ return false;
+
+ return true;
+}
+
#include "burtle.hh"
#include "views.hh"
}
-inline int pdns_ilexicographical_compare_three_way(std::string_view a, std::string_view b) __attribute__((pure));
-inline int pdns_ilexicographical_compare_three_way(std::string_view a, std::string_view b)
-{
- const unsigned char *aPtr = (const unsigned char*)a.data(), *bPtr = (const unsigned char*)b.data();
- const unsigned char *aEptr = aPtr + a.length(), *bEptr = bPtr + b.length();
- while(aPtr != aEptr && bPtr != bEptr) {
- if (*aPtr != *bPtr) {
- if (int rc = dns_tolower(*aPtr) - dns_tolower(*bPtr); rc != 0) {
- return rc;
- }
- }
- aPtr++;
- bPtr++;
- }
- // At this point, one of the strings has been completely processed.
- // Either both have the same length, and they are equal, or one of them
- // is larger, and compares as higher.
- if (aPtr == aEptr) {
- if (bPtr != bEptr) {
- return -1; // a < b
- }
- }
- else {
- return 1; // a > b
- }
- return 0; // a == b
-}
-
-inline bool pdns_ilexicographical_compare(const std::string& a, const std::string& b) __attribute__((pure));
-inline bool pdns_ilexicographical_compare(const std::string& a, const std::string& b)
-{
- return pdns_ilexicographical_compare_three_way(a, b) < 0;
-}
-
-inline bool pdns_iequals(const std::string& a, const std::string& b) __attribute__((pure));
-inline bool pdns_iequals(const std::string& a, const std::string& b)
-{
- if (a.length() != b.length())
- return false;
-
- return pdns_ilexicographical_compare_three_way(a, b) == 0;
-}
-
-inline bool pdns_iequals_ch(const char a, const char b) __attribute__((pure));
-inline bool pdns_iequals_ch(const char a, const char b)
-{
- if ((a != b) && (dns_tolower(a) != dns_tolower(b)))
- return false;
-
- return true;
-}
-
-
typedef unsigned long AtomicCounterInner;
typedef std::atomic<AtomicCounterInner> AtomicCounter ;
#define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp>
+#include <boost/assign/list_of.hpp>
+#include <boost/tuple/tuple.hpp>
#include <cmath>
#include <numeric>
}
#endif
+BOOST_AUTO_TEST_CASE(test_pdns_ilexicographical_compare) {
+ typedef boost::tuple<const std::string, const std::string, bool> case_t;
+ typedef std::list<case_t> cases_t;
+
+ cases_t cases = boost::assign::list_of
+ (case_t(std::string(""), std::string(""), false))
+ (case_t(std::string(""), std::string("abc"), true))
+ (case_t(std::string("abc"), std::string(""), false))
+ (case_t(std::string("abc"), std::string("abcd"), true))
+ (case_t(std::string("abcd"), std::string("abc"), false))
+ (case_t(std::string("abd"), std::string("abc"), false))
+ (case_t(std::string("abc"), std::string("abd"), true))
+ (case_t(std::string("abc"), std::string("Abc"), false))
+ (case_t(std::string("Abc"), std::string("abc"), false))
+ ;
+
+ for(const case_t& val : cases) {
+ bool res;
+ res = pdns_ilexicographical_compare(val.get<0>(), val.get<1>());
+ BOOST_CHECK_EQUAL(res, val.get<2>());
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_pdns_iequals) {
+ typedef boost::tuple<const std::string, const std::string, bool> case_t;
+ typedef std::list<case_t> cases_t;
+
+ cases_t cases = boost::assign::list_of
+ (case_t(std::string(""), std::string(""), true))
+ (case_t(std::string(""), std::string("abc"), false))
+ (case_t(std::string("abc"), std::string(""), false))
+ (case_t(std::string("abc"), std::string("abcd"), false))
+ (case_t(std::string("abcd"), std::string("abc"), false))
+ (case_t(std::string("abd"), std::string("abc"), false))
+ (case_t(std::string("abc"), std::string("abd"), false))
+ (case_t(std::string("abc"), std::string("Abc"), true))
+ (case_t(std::string("Abc"), std::string("abc"), true))
+ ;
+
+ for(const case_t& val : cases) {
+ bool res;
+ res = pdns_iequals(val.get<0>(), val.get<1>());
+ BOOST_CHECK_EQUAL(res, val.get<2>());
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()
#include <boost/test/unit_test.hpp>
#include <boost/assign/list_of.hpp>
-#include <boost/tuple/tuple.hpp>
-
#include <arpa/inet.h>
#include "dns.hh"
BOOST_CHECK_EQUAL(s.str(), "(|1)(abc|1)(abc|2)(def|1)(ns.example.com|0)(ns.example.com|1)");
}
-BOOST_AUTO_TEST_CASE(test_pdns_ilexicographical_compare) {
- typedef boost::tuple<const std::string, const std::string, bool> case_t;
- typedef std::list<case_t> cases_t;
-
- cases_t cases = boost::assign::list_of
- (case_t(std::string(""), std::string(""), false))
- (case_t(std::string(""), std::string("abc"), true))
- (case_t(std::string("abc"), std::string(""), false))
- (case_t(std::string("abc"), std::string("abcd"), true))
- (case_t(std::string("abcd"), std::string("abc"), false))
- (case_t(std::string("abd"), std::string("abc"), false))
- (case_t(std::string("abc"), std::string("abd"), true))
- (case_t(std::string("abc"), std::string("Abc"), false))
- (case_t(std::string("Abc"), std::string("abc"), false))
- ;
-
- for(const case_t& val : cases) {
- bool res;
- res = pdns_ilexicographical_compare(val.get<0>(), val.get<1>());
- BOOST_CHECK_EQUAL(res, val.get<2>());
- }
-}
-
-BOOST_AUTO_TEST_CASE(test_pdns_iequals) {
- typedef boost::tuple<const std::string, const std::string, bool> case_t;
- typedef std::list<case_t> cases_t;
-
- cases_t cases = boost::assign::list_of
- (case_t(std::string(""), std::string(""), true))
- (case_t(std::string(""), std::string("abc"), false))
- (case_t(std::string("abc"), std::string(""), false))
- (case_t(std::string("abc"), std::string("abcd"), false))
- (case_t(std::string("abcd"), std::string("abc"), false))
- (case_t(std::string("abd"), std::string("abc"), false))
- (case_t(std::string("abc"), std::string("abd"), false))
- (case_t(std::string("abc"), std::string("Abc"), true))
- (case_t(std::string("Abc"), std::string("abc"), true))
- ;
-
- for(const case_t& val : cases) {
- bool res;
- res = pdns_iequals(val.get<0>(), val.get<1>());
- BOOST_CHECK_EQUAL(res, val.get<2>());
- }
-}
-
BOOST_AUTO_TEST_CASE(test_stripDot) {
BOOST_CHECK_EQUAL(stripDot("."), "");
BOOST_CHECK_EQUAL(stripDot(""), "");