From ff9b6aa18e1ac0e1ae3f43d2754fcedc85954cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Thu, 26 Sep 2024 23:46:31 +0300 Subject: [PATCH] Remove C++11 only code --- include/upa/config.h | 9 -- include/upa/str_arg.h | 12 +-- include/upa/str_view.h | 145 ------------------------------- include/upa/url_percent_encode.h | 47 ---------- include/upa/util.h | 5 +- src/url_percent_encode.cpp | 44 ---------- test/test-utils.h | 6 -- 7 files changed, 3 insertions(+), 265 deletions(-) delete mode 100644 include/upa/str_view.h diff --git a/include/upa/config.h b/include/upa/config.h index 46a5bc5d..89787eec 100644 --- a/include/upa/config.h +++ b/include/upa/config.h @@ -30,15 +30,6 @@ # define UPA_NOEXCEPT_17 #endif -// Define UPA_CPP_14 if compiler supports C++14 or later -// Note: Visual Studio 2015 (14.0; _MSC_VER == 1900) lacks sufficient C++14 support -#if defined(_MSVC_LANG) ? (_MSVC_LANG >= 201402 && _MSC_VER > 1900) : (__cplusplus >= 201402) -# define UPA_CPP_14 -# define UPA_CONSTEXPR_14 constexpr -#else -# define UPA_CONSTEXPR_14 inline -#endif - // Barrier for pointer anti-aliasing optimizations even across function boundaries. // This is a slightly modified U_ALIASING_BARRIER macro from the char16ptr.h file // of the ICU 75.1 library. diff --git a/include/upa/str_arg.h b/include/upa/str_arg.h index 9bd550a6..d3309885 100644 --- a/include/upa/str_arg.h +++ b/include/upa/str_arg.h @@ -18,27 +18,19 @@ inline void procfn(Args&&... args) { #ifndef UPA_STR_ARG_H #define UPA_STR_ARG_H -#include "config.h" #include "url_utf.h" #include #include #include +#include #include #include -#ifdef UPA_CPP_17 -# include -# define UPA_STRING_VIEW_TYPE std::string_view -#else -# include "str_view.h" -# define UPA_STRING_VIEW_TYPE upa::str_view -#endif - namespace upa { // String view type -using string_view = UPA_STRING_VIEW_TYPE; +using string_view = std::string_view; // Supported char and size types diff --git a/include/upa/str_view.h b/include/upa/str_view.h deleted file mode 100644 index 535c2496..00000000 --- a/include/upa/str_view.h +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2016-2024 Rimas Misevičius -// Distributed under the BSD-style license that can be -// found in the LICENSE file. -// - -#ifndef UPA_STR_VIEW_H -#define UPA_STR_VIEW_H - -#include "config.h" -#include -#include -#include -#include -#include -#include - -namespace upa { - -/// @brief A very simplified implementation of the basic_string_view -/// -/// It is used when compiling with C++11 or C++14 compilers. -template> -class str_view { -public: - // types - using traits_type = Traits; - using value_type = CharT; - using pointer = CharT*; - using const_pointer = const CharT*; - using reference = CharT&; - using const_reference = const CharT&; - using const_iterator = const CharT*; // implementation-defined; see 21.4.2.2 in C++20 standard - using iterator = const_iterator; - using const_reverse_iterator = std::reverse_iterator; - using reverse_iterator = const_reverse_iterator; - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - // static constexpr size_type npos = size_type(-1); - - // constructors - constexpr str_view() noexcept = default; - constexpr str_view(const str_view&) noexcept = default; - constexpr str_view(const CharT* ptr, size_type len) noexcept : ptr_(ptr), len_(len) {} - str_view(const CharT* ptr) : ptr_(ptr), len_(Traits::length(ptr)) {} - - // assignment - UPA_CONSTEXPR_14 str_view& operator=(const str_view&) noexcept = default; - - // destructor - ~str_view() noexcept = default; - - // iterator support - constexpr const_iterator begin() const noexcept { return ptr_; } - constexpr const_iterator end() const noexcept { return ptr_ + len_; } - - // capacity - constexpr size_type size() const noexcept { return len_; } - constexpr size_type length() const noexcept { return len_; } - constexpr bool empty() const noexcept { return len_ == 0; } - - // element access - constexpr const_reference operator[](size_type ind) const { - return ptr_[ind]; - } - constexpr const_pointer data() const noexcept { return ptr_; } - - // modifiers - UPA_CONSTEXPR_14 void remove_prefix(size_type n) { - ptr_ += n; - len_ -= n; - } - UPA_CONSTEXPR_14 void remove_suffix(size_type n) { - len_ -= n; - } - UPA_CONSTEXPR_14 void swap(str_view& x) noexcept { - const str_view tmp{x}; - x = *this; - *this = tmp; - } - - // string operations - int compare(str_view x) const { - const int cmp = Traits::compare(ptr_, x.ptr_, std::min(len_, x.len_)); - return cmp != 0 ? cmp : (len_ == x.len_ ? 0 : len_ < x.len_ ? -1 : 1); - } - - - // non-standard - bool equal(str_view x) const { - return len_ == x.len_ && Traits::compare(ptr_, x.ptr_, len_) == 0; - } - - // basic_string, basic_string_view support - template ::value, int>::type = 0> - str_view(const StrT& str) : ptr_(str.data()), len_(str.length()) {} - - //template ::value, int>::type = 0> - //operator StrT() const { return StrT(ptr_, len_); } - template - operator std::basic_string() const { - return std::basic_string(ptr_, len_); - } - -private: - const_pointer ptr_ = nullptr; - size_type len_ = 0; -}; - - -// compare two str_view -template -/*constexpr*/ bool operator==(str_view lhs, str_view rhs) /*noexcept*/ { - return lhs.equal(rhs); -} - -template -/*constexpr*/ bool operator!=(str_view lhs, str_view rhs) /*noexcept*/ { - return !lhs.equal(rhs); -} - -// compare objects convertible to str_view for equality -template>::value, int>::type = 0> -/*constexpr*/ bool operator==(StrT&& lhs, const str_view rhs) { - return rhs.equal(std::forward(lhs)); -} - -template>::value, int>::type = 0> -/*constexpr*/ bool operator==(const str_view lhs, StrT&& rhs) { - return lhs.equal(std::forward(rhs)); -} - -// stream output -template -std::basic_ostream& operator<<(std::basic_ostream& os, - str_view v) { - // TODO FormattedOutputFunction - return os.write(v.data(), v.length()); -} - - -} // namespace upa - -#endif // UPA_STR_VIEW_H diff --git a/include/upa/url_percent_encode.h b/include/upa/url_percent_encode.h index b9d06ecc..078c80f2 100644 --- a/include/upa/url_percent_encode.h +++ b/include/upa/url_percent_encode.h @@ -32,7 +32,6 @@ namespace upa { /// class code_point_set { public: -#ifdef UPA_CPP_17 /// @brief constructor for code point set initialization /// /// Function @a fun must iniatialize @a self object by using code_point_set @@ -82,7 +81,6 @@ class code_point_set { for (auto c = from; c <= to; ++c) include(c); } -#endif /// @brief test code point set contains code point @a c /// @param[in] c code point to test @@ -92,12 +90,6 @@ class code_point_set { return is_8bit(uc) && (arr_[uc >> 3] & (1u << (uc & 0x07))) != 0; } -#ifdef UPA_CPP_17 - // for dump program - static constexpr std::size_t arr_size() noexcept { return arr_size_; } - constexpr uint8_t arr_val(std::size_t i) const { return arr_[i]; } -#endif - private: // Check code point value is 8 bit (<=0xFF) static constexpr bool is_8bit(unsigned char) noexcept { @@ -111,19 +103,12 @@ class code_point_set { // Data static const std::size_t arr_size_ = 32; -#ifdef UPA_CPP_17 uint8_t arr_[arr_size_] = {}; -#else -public: - uint8_t arr_[arr_size_]; -#endif }; // Percent encode sets -#ifdef UPA_CPP_17 - // If you edit following data, then please compile tools/dumpCharBitSets.cpp program // with C++17 compiler, run it and copy output to the url_percent_encode.cpp file. // This is required to support C++11, C++14 compilers. @@ -185,21 +170,6 @@ inline constexpr code_point_set component_no_encode_set{ [](code_point_set& self } }; -#else - -// For C++11, C++14 - -extern const code_point_set fragment_no_encode_set; -extern const code_point_set query_no_encode_set; -extern const code_point_set special_query_no_encode_set; -extern const code_point_set path_no_encode_set; -extern const code_point_set raw_path_no_encode_set; -extern const code_point_set posix_path_no_encode_set; -extern const code_point_set userinfo_no_encode_set; -extern const code_point_set component_no_encode_set; - -#endif - namespace detail { // Code point sets in one bytes array @@ -215,7 +185,6 @@ enum CP_SET : std::uint8_t { class code_points_multiset { public: -#ifdef UPA_CPP_17 constexpr code_points_multiset() { // Forbidden host code points: U+0000 NULL, U+0009 TAB, U+000A LF, U+000D CR, // U+0020 SPACE, U+0023 (#), U+002F (/), U+003A (:), U+003C (<), U+003E (>), @@ -260,11 +229,6 @@ class code_points_multiset { include(SCHEME_SET, { 0x2B, 0x2D, 0x2E }); } - // for dump program - static constexpr std::size_t arr_size() noexcept { return arr_size_; } - constexpr uint8_t arr_val(std::size_t i) const { return arr_[i]; } -#endif - /// @brief test the @a cps code points set contains code point @a c /// @param[in] c code point to test /// @param[in] cps code point set @@ -275,7 +239,6 @@ class code_points_multiset { } private: -#ifdef UPA_CPP_17 /// @brief include @a c code point to @a cpsbits sets /// @param[in] cpsbits code points sets /// @param[in] c code point to include @@ -313,7 +276,6 @@ class code_points_multiset { for (auto c : clist) exclude(cpsbits, c); } -#endif // Check code point value is 8 bit (<=0xFF) static constexpr bool is_8bit(unsigned char) noexcept { @@ -327,19 +289,10 @@ class code_points_multiset { // Data static const std::size_t arr_size_ = 256; -#ifdef UPA_CPP_17 uint8_t arr_[arr_size_] = {}; -#else -public: - uint8_t arr_[arr_size_]; -#endif }; -#ifdef UPA_CPP_17 inline constexpr code_points_multiset code_points; -#else -extern const code_points_multiset code_points; -#endif // ---------------------------------------------------------------------------- // Check char is in predefined set diff --git a/include/upa/util.h b/include/upa/util.h index 522eec87..13232556 100644 --- a/include/upa/util.h +++ b/include/upa/util.h @@ -138,12 +138,9 @@ inline void append_tr(std::string& dest, const CharT* first, const CharT* last, std::transform(first, last, buff + old_size, unary_op); return new_size; }); -#elif defined(UPA_CPP_17) +#else dest.resize(new_size); std::transform(first, last, dest.data() + old_size, unary_op); -#else - dest.reserve(new_size); - std::transform(first, last, std::back_inserter(dest), unary_op); #endif } diff --git a/src/url_percent_encode.cpp b/src/url_percent_encode.cpp index 210ee2b1..4c1ce3bb 100644 --- a/src/url_percent_encode.cpp +++ b/src/url_percent_encode.cpp @@ -10,50 +10,6 @@ #include "upa/url_percent_encode.h" namespace upa { // NOLINT(modernize-concat-nested-namespaces) - -#ifndef UPA_CPP_17 - -// These data were generated by tools/dumpCharBitSets.cpp program. -const code_point_set fragment_no_encode_set = { - 0x00, 0x00, 0x00, 0x00, 0xfa, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0x7f -}; -const code_point_set query_no_encode_set = { - 0x00, 0x00, 0x00, 0x00, 0xf2, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f -}; -const code_point_set special_query_no_encode_set = { - 0x00, 0x00, 0x00, 0x00, 0x72, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f -}; -const code_point_set path_no_encode_set = { - 0x00, 0x00, 0x00, 0x00, 0xf2, 0xff, 0xff, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0x57 -}; -const code_point_set raw_path_no_encode_set = { - 0x00, 0x00, 0x00, 0x00, 0xd2, 0xff, 0xff, 0x2f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0x57 -}; -const code_point_set posix_path_no_encode_set = { - 0x00, 0x00, 0x00, 0x00, 0xd2, 0xff, 0xff, 0x2b, 0xff, 0xff, 0xff, 0xef, 0xfe, 0xff, 0xff, 0x47 -}; -const code_point_set userinfo_no_encode_set = { - 0x00, 0x00, 0x00, 0x00, 0xf2, 0x7f, 0xff, 0x03, 0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x47 -}; -const code_point_set component_no_encode_set = { - 0x00, 0x00, 0x00, 0x00, 0x82, 0x67, 0xff, 0x03, 0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x47 -}; - -namespace detail { -const code_points_multiset code_points = { - 0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x06, 0x06, 0x02, 0x02, 0x06, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x06, 0x01, 0x01, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x21, 0x01, 0x21, 0x31, 0x06, - 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x06, 0x01, 0x06, 0x01, 0x06, 0x06, - 0x06, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, - 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x31, 0x21, 0x21, 0x06, 0x06, 0x06, 0x06, 0x01, - 0x01, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, - 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x31, 0x21, 0x21, 0x01, 0x06, 0x01, 0x01, 0x02 -}; -} // namespace detail - -#endif - namespace detail { // Maps hex numerical values to ASCII digits diff --git a/test/test-utils.h b/test/test-utils.h index d99bde6a..1cb08dec 100644 --- a/test/test-utils.h +++ b/test/test-utils.h @@ -62,13 +62,7 @@ inline bool param_eq(const std::string* pval, const T& value) { template inline bool list_eq(const List& val, std::initializer_list lst) { -#ifdef UPA_CPP_14 return std::equal(std::begin(val), std::end(val), std::begin(lst), std::end(lst)); -#else - return - val.size() == lst.size() && - std::equal(std::begin(val), std::end(val), std::begin(lst)); -#endif } template