From 37891e8a2a6cc1cf5e6a9e68d1cdc37cd6fa7e66 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 18 Dec 2023 17:52:30 +0100 Subject: [PATCH] Simplify and unify template parameter naming Signed-off-by: Simon Rozman --- include/stdex/base64.hpp | 26 +-- include/stdex/chrono.hpp | 16 +- include/stdex/compat.hpp | 2 +- include/stdex/hex.hpp | 8 +- include/stdex/html.hpp | 294 +++++++++++++++++----------------- include/stdex/idrec.hpp | 122 +++++++------- include/stdex/interval.hpp | 4 +- include/stdex/mapping.hpp | 4 +- include/stdex/memory.hpp | 8 +- include/stdex/parser.hpp | 8 +- include/stdex/ring.hpp | 22 +-- include/stdex/sgml.hpp | 60 +++---- include/stdex/stream.hpp | 143 +++++++++-------- include/stdex/string.hpp | 318 +++++++++++++++++++------------------ include/stdex/unicode.hpp | 162 ++++++++++--------- 15 files changed, 614 insertions(+), 583 deletions(-) diff --git a/include/stdex/base64.hpp b/include/stdex/base64.hpp index 300526daa..957e3b7af 100644 --- a/include/stdex/base64.hpp +++ b/include/stdex/base64.hpp @@ -66,8 +66,8 @@ namespace stdex /// \param[in] size Length of `data` in bytes /// \param[in] is_last Is this the last block of data? /// - template - void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size, _In_opt_ bool is_last = true) + template + void encode(_Inout_ std::basic_string &out, _In_bytecount_(size) const void *data, _In_ size_t size, _In_opt_ bool is_last = true) { _Assume_(data || !size); @@ -118,8 +118,8 @@ namespace stdex /// /// Encodes one complete internal buffer of data /// - template - void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out) + template + void encode(_Inout_ std::basic_string &out) { out += base64_enc_lookup[ m_buf[0] >> 2 ]; out += base64_enc_lookup[((m_buf[0] << 4) | (m_buf[1] >> 4)) & 0x3f]; @@ -130,8 +130,8 @@ namespace stdex /// /// Encodes partial internal buffer of data /// - template - void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_ size_t size) + template + void encode(_Inout_ std::basic_string &out, _In_ size_t size) { if (size > 0) { out += base64_enc_lookup[m_buf[0] >> 2]; @@ -287,8 +287,8 @@ namespace stdex /// \param[in] data Data to decode /// \param[in] size Length of `data` in bytes /// - template - void decode(_Inout_ std::vector<_Ty, _Ax> &out, _Out_ bool &is_last, _In_z_count_(size) const _Tchr *data, _In_ size_t size) + template + void decode(_Inout_ std::vector &out, _Out_ bool &is_last, _In_z_count_(size) const T_from *data, _In_ size_t size) { is_last = false; @@ -342,15 +342,15 @@ namespace stdex /// /// Decodes one complete internal buffer of data /// - template - size_t decode(_Inout_ std::vector<_Ty, _Ax> &out) + template + size_t decode(_Inout_ std::vector &out) { m_num = 0; - out.push_back((_Ty)(((m_buf[0] << 2) | (m_buf[1] >> 4)) & 0xff)); + out.push_back((T)(((m_buf[0] << 2) | (m_buf[1] >> 4)) & 0xff)); if (m_buf[2] < 64) { - out.push_back((_Ty)(((m_buf[1] << 4) | (m_buf[2] >> 2)) & 0xff)); + out.push_back((T)(((m_buf[1] << 4) | (m_buf[2] >> 2)) & 0xff)); if (m_buf[3] < 64) { - out.push_back((_Ty)(((m_buf[2] << 6) | m_buf[3]) & 0xff)); + out.push_back((T)(((m_buf[2] << 6) | m_buf[3]) & 0xff)); return 3; } else return 2; diff --git a/include/stdex/chrono.hpp b/include/stdex/chrono.hpp index 352dd5164..da0b30889 100644 --- a/include/stdex/chrono.hpp +++ b/include/stdex/chrono.hpp @@ -323,12 +323,12 @@ namespace stdex { if (hour) *hour = static_cast(u); } - template, class _Ax = std::allocator> - static std::basic_string to_str(_In_ const time_point tp, _In_z_ const char* format, _In_opt_ locale_t locale) + template, class AX = std::allocator> + static std::basic_string to_str(_In_ const time_point tp, _In_z_ const char* format, _In_opt_ locale_t locale) { struct tm date; to_system(tp, date); - std::basic_string str; + std::basic_string str; char stack_buffer[1024 / sizeof(char)]; size_t n; #if _WIN32 @@ -356,12 +356,12 @@ namespace stdex { } } - template, class _Ax = std::allocator> - static std::basic_string to_str(_In_ const time_point tp, _In_z_ const wchar_t* format, _In_opt_ locale_t locale) + template, class AX = std::allocator> + static std::basic_string to_str(_In_ const time_point tp, _In_z_ const wchar_t* format, _In_opt_ locale_t locale) { struct tm date; to_system(tp, date); - std::basic_string str; + std::basic_string str; wchar_t stack_buffer[1024 / sizeof(wchar_t)]; size_t n; #if _WIN32 @@ -389,8 +389,8 @@ namespace stdex { } } - template, class _Ax = std::allocator> - static std::basic_string to_rfc822(_In_ const time_point tp) + template, class AX = std::allocator> + static std::basic_string to_rfc822(_In_ const time_point tp) { return to_str(tp, "%a, %d %b %Y %H:%M:%S GMT", locale_C.get()); } diff --git a/include/stdex/compat.hpp b/include/stdex/compat.hpp index e134a7158..a408c94c0 100644 --- a/include/stdex/compat.hpp +++ b/include/stdex/compat.hpp @@ -185,7 +185,7 @@ #endif #ifndef _WIN32 -template +template size_t _countof(const T (&arr)[N]) { return std::extent::value; diff --git a/include/stdex/hex.hpp b/include/stdex/hex.hpp index 0302c6f22..6a164cc5c 100644 --- a/include/stdex/hex.hpp +++ b/include/stdex/hex.hpp @@ -34,8 +34,8 @@ namespace stdex /// \param[in] data Data to encode /// \param[in] size Length of `data` in bytes /// - template - void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size) + template + void encode(_Inout_ std::basic_string &out, _In_bytecount_(size) const void *data, _In_ size_t size) { _Assume_(data || !size); @@ -93,8 +93,8 @@ namespace stdex /// \param[in] data Data to decode /// \param[in] size Length of `data` in bytes /// - template - void decode(_Inout_ std::vector<_Ty, _Ax> &out, _Out_ bool &is_last, _In_z_count_(size) const _Tchr *data, _In_ size_t size) + template + void decode(_Inout_ std::vector &out, _Out_ bool &is_last, _In_z_count_(size) const T_from *data, _In_ size_t size) { is_last = false; diff --git a/include/stdex/html.hpp b/include/stdex/html.hpp index d849d3e46..ebe26998f 100644 --- a/include/stdex/html.hpp +++ b/include/stdex/html.hpp @@ -39,9 +39,9 @@ namespace stdex /// \param[in] src Source string /// \param[in] num_chars Code unit limit in string `src` /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void escape( - _Inout_ std::basic_string& dst, + _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(num_chars) const char* src, _In_ size_t num_chars) { _Assume_(src || !num_chars); @@ -66,9 +66,9 @@ namespace stdex /// \param[in] src Source string /// \param[in] num_chars Code unit limit in string `src` /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void escape( - _Inout_ std::basic_string& dst, + _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(num_chars) const wchar_t* src, _In_ size_t num_chars) { _Assume_(src || !num_chars); @@ -92,12 +92,12 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc = std::allocator<_Elem>> + template, class AX = std::allocator> void escape( - _Inout_ std::basic_string<_Elem, _Traits, _Alloc>& dst, - _In_ const _Elem (&src)[_Size]) + _Inout_ std::basic_string& dst, + _In_ const T (&src)[N]) { - escape(dst, src, _Size); + escape(dst, src, N); } /// @@ -106,10 +106,10 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc_dst = std::allocator<_Elem>, class _Traits_src = std::char_traits<_Elem>, class _Alloc_src = std::allocator<_Elem>> + template, class AX_dst = std::allocator, class TR_src = std::char_traits, class AX_src = std::allocator> void escape( - _Inout_ std::basic_string<_Elem, _Traits_dst, _Alloc_dst>& dst, - _In_ const std::basic_string<_Elem, _Traits_src, _Alloc_src>& src) + _Inout_ std::basic_string& dst, + _In_ const std::basic_string& src) { escape(dst, src.data(), src.size()); } @@ -120,8 +120,8 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] chr Source character /// - template, class _Alloc = std::allocator> - void escape_min(_Inout_ std::basic_string& dst, _In_ char chr) + template, class AX = std::allocator> + void escape_min(_Inout_ std::basic_string& dst, _In_ char chr) { switch (chr) { case '&': dst += "&"; break; @@ -138,8 +138,8 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] chr Source character /// - template, class _Alloc = std::allocator> - void escape_min(_Inout_ std::basic_string& dst, _In_ wchar_t chr) + template, class AX = std::allocator> + void escape_min(_Inout_ std::basic_string& dst, _In_ wchar_t chr) { switch (chr) { case L'&': dst += L"&"; break; @@ -157,9 +157,9 @@ namespace stdex /// \param[in] src Source string /// \param[in] num_chars Code unit limit in string `src` /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void escape_min( - _Inout_ std::basic_string& dst, + _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(num_chars) const char* src, _In_ size_t num_chars) { _Assume_(src || !num_chars); @@ -181,9 +181,9 @@ namespace stdex /// \param[in] src Source string /// \param[in] num_chars Code unit limit in string `src` /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void escape_min( - _Inout_ std::basic_string& dst, + _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(num_chars) const wchar_t* src, _In_ size_t num_chars) { _Assume_(src || !num_chars); @@ -204,12 +204,12 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc = std::allocator<_Elem>> + template, class AX = std::allocator> void escape_min( - _Inout_ std::basic_string<_Elem, _Traits, _Alloc>& dst, - _In_ const _Elem (&src)[_Size]) + _Inout_ std::basic_string& dst, + _In_ const T (&src)[N]) { - escape_min(dst, src, _Size); + escape_min(dst, src, N); } /// @@ -218,10 +218,10 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc_dst = std::allocator<_Elem>, class _Traits_src = std::char_traits<_Elem>, class _Alloc_src = std::allocator<_Elem>> + template, class AX_dst = std::allocator, class TR_src = std::char_traits, class AX_src = std::allocator> void escape_min( - _Inout_ std::basic_string<_Elem, _Traits_dst, _Alloc_dst>& dst, - _In_ const std::basic_string<_Elem, _Traits_src, _Alloc_src>& src) + _Inout_ std::basic_string& dst, + _In_ const std::basic_string& src) { escape_min(dst, src.data(), src.size()); } @@ -233,9 +233,9 @@ namespace stdex /// \param[in] src Source string /// \param[in] num_chars Code unit limit in string `src` /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void url_unescape( - _Inout_ std::basic_string& dst, + _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(num_chars) const char* src, _In_ size_t num_chars) { _Assume_(src || !num_chars); @@ -274,12 +274,12 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void url_unescape( - _Inout_ std::basic_string& dst, - _In_ const char (&src)[_Size]) + _Inout_ std::basic_string& dst, + _In_ const char (&src)[N]) { - url_unescape(dst, src, _Size); + url_unescape(dst, src, N); } /// @@ -288,10 +288,10 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc_dst = std::allocator> + template, class AX_dst = std::allocator> void url_unescape( - _Inout_ std::basic_string& dst, - _In_ const std::string_view src) + _Inout_ std::basic_string& dst, + _In_ const std::basic_string_view> src) { url_unescape(dst, src.data(), src.size()); } @@ -303,9 +303,9 @@ namespace stdex /// \param[in] src Source string /// \param[in] num_chars Code unit limit in string `src` /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void url_escape( - _Inout_ std::basic_string& dst, + _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(num_chars) const char* src, _In_ size_t num_chars) { _Assume_(src || !num_chars); @@ -353,12 +353,12 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void url_escape( - _Inout_ std::basic_string& dst, - _In_ const char (&src)[_Size]) + _Inout_ std::basic_string& dst, + _In_ const char (&src)[N]) { - url_escape(dst, src, _Size); + url_escape(dst, src, N); } /// @@ -367,10 +367,10 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc_dst = std::allocator> + template, class AX_dst = std::allocator> void url_escape( - _Inout_ std::basic_string& dst, - _In_ const std::string_view src) + _Inout_ std::basic_string& dst, + _In_ const std::basic_string_view> src) { url_escape(dst, src.data(), src.size()); } @@ -382,10 +382,10 @@ namespace stdex /// \param[in] src Source string /// \param[in] num_chars Code unit limit in string `src` /// - template, class _Alloc = std::allocator<_Elem>> + template, class AX = std::allocator> void css_unescape( - _Inout_ std::basic_string<_Elem, _Traits, _Alloc>& dst, - _In_reads_or_z_opt_(num_chars) const _Elem* src, _In_ size_t num_chars) + _Inout_ std::basic_string& dst, + _In_reads_or_z_opt_(num_chars) const T* src, _In_ size_t num_chars) { _Assume_(src || !num_chars); for (size_t i = 0; i < num_chars && src[i];) { @@ -430,7 +430,7 @@ namespace stdex else break; } - dst += static_cast<_Elem>(chr); + dst += static_cast(chr); if (i < end && src[i] == ' ') { // Skip space after `\nnnn`. @@ -451,12 +451,12 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc = std::allocator<_Elem>> + template, class AX = std::allocator> void css_unescape( - _Inout_ std::basic_string<_Elem, _Traits, _Alloc>& dst, - _In_ const _Elem (&src)[_Size]) + _Inout_ std::basic_string& dst, + _In_ const T (&src)[N]) { - css_unescape(dst, src, _Size); + css_unescape(dst, src, N); } /// @@ -465,10 +465,10 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc_dst = std::allocator<_Elem>, class _Traits_src = std::char_traits<_Elem>, class _Alloc_src = std::allocator<_Elem>> + template, class AX_dst = std::allocator, class TR_src = std::char_traits, class AX_src = std::allocator> void css_unescape( - _Inout_ std::basic_string<_Elem, _Traits_dst, _Alloc_dst>& dst, - _In_ const std::basic_string<_Elem, _Traits_src, _Alloc_src>& src) + _Inout_ std::basic_string& dst, + _In_ const std::basic_string& src) { css_unescape(dst, src.data(), src.size()); } @@ -480,9 +480,9 @@ namespace stdex /// \param[in] src Source string /// \param[in] num_chars Code unit limit in string `src` /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void css_escape( - _Inout_ std::basic_string& dst, + _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(num_chars) const char* src, _In_ size_t num_chars) { _Assume_(src || !num_chars); @@ -506,9 +506,9 @@ namespace stdex /// \param[in] src Source string /// \param[in] num_chars Code unit limit in string `src` /// - template, class _Alloc = std::allocator> + template, class AX = std::allocator> void css_escape( - _Inout_ std::basic_string& dst, + _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(num_chars) const wchar_t* src, _In_ size_t num_chars) { _Assume_(src || !num_chars); @@ -531,12 +531,12 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc = std::allocator<_Elem>> + template, class AX = std::allocator> void css_escape( - _Inout_ std::basic_string<_Elem, _Traits, _Alloc>& dst, - _In_ const _Elem (&src)[_Size]) + _Inout_ std::basic_string& dst, + _In_ const T (&src)[N]) { - css_escape(dst, src, _Size); + css_escape(dst, src, N); } /// @@ -545,10 +545,10 @@ namespace stdex /// \param[in,out] dst String to append to /// \param[in] src Source string /// - template, class _Alloc_dst = std::allocator<_Elem>, class _Traits_src = std::char_traits<_Elem>, class _Alloc_src = std::allocator<_Elem>> + template, class AX_dst = std::allocator, class TR_src = std::char_traits, class AX_src = std::allocator> void css_escape( - _Inout_ std::basic_string<_Elem, _Traits_dst, _Alloc_dst>& dst, - _In_ const std::basic_string<_Elem, _Traits_src, _Alloc_src>& src) + _Inout_ std::basic_string& dst, + _In_ const std::basic_string& src) { css_escape(dst, src.data(), src.size()); } @@ -1581,23 +1581,23 @@ namespace stdex /// /// HTML entity /// - template, class _Alloc = std::allocator<_Elem>> + template, class AX = std::allocator> struct entity { stdex::interval name; ///< Name position in source - std::basic_string<_Elem, _Traits, _Alloc> value; ///< Entity value + std::basic_string value; ///< Entity value }; /// /// HTML parser /// - template, class _Alloc = std::allocator<_Elem>> + template, class AX = std::allocator> class parser; /// /// HTML document /// - template, class _Alloc = std::allocator<_Elem>> + template, class AX = std::allocator> class document { public: @@ -1639,7 +1639,7 @@ namespace stdex /// /// Parses HTML source code by chunks /// - void append(_In_reads_or_z_opt_(num_chars) const _Elem* source, _In_ size_t num_chars) + void append(_In_reads_or_z_opt_(num_chars) const T* source, _In_ size_t num_chars) { _Assume_(source || !num_chars); m_source.append(source, stdex::strnlen(source, num_chars)); @@ -1770,7 +1770,7 @@ namespace stdex } if (is_content_type && content_attr) { // found. - stdex::parser::basic_mime_type<_Elem> content; + stdex::parser::basic_mime_type content; if (content.match(source, content_attr->value.start, content_attr->value.end) && content.charset) { @@ -1814,7 +1814,7 @@ namespace stdex stdex::strncmp(source + m_tag.attributes[3].name.start, m_tag.attributes[3].name.size(), "SYSTEM", SIZE_MAX) && stdex::strncmp(source + m_tag.attributes[3].name.start, m_tag.attributes[3].name.size(), "PUBLIC", SIZE_MAX)) { - std::unique_ptr> e(new entity<_Elem, _Traits, _Alloc>()); + std::unique_ptr> e(new entity()); e->name = m_tag.attributes[2].name; e->value = std::move(replace_entities(source + m_tag.attributes[3].name.start, m_tag.attributes[3].name.size())); m_entities.push_back(std::move(e)); @@ -1862,7 +1862,7 @@ namespace stdex /// /// Parses HTML document source code /// - void assign(_In_reads_or_z_opt_(num_chars) const _Elem* source, _In_ size_t num_chars) + void assign(_In_reads_or_z_opt_(num_chars) const T* source, _In_ size_t num_chars) { clear(); append(source, num_chars); @@ -1872,9 +1872,9 @@ namespace stdex /// /// Returns document HTML source code /// - const std::basic_string<_Elem, _Traits, _Alloc>& source() const { return m_source; } + const std::basic_string& source() const { return m_source; } - friend class parser<_Elem, _Traits, _Alloc>; + friend class parser; protected: /// @@ -1888,12 +1888,12 @@ namespace stdex /// /// Replaces entities with their content /// - std::basic_string<_Elem, _Traits, _Alloc> replace_entities(_In_reads_or_z_opt_(num_chars) const _Elem* input, _In_ size_t num_chars) const + std::basic_string replace_entities(_In_reads_or_z_opt_(num_chars) const T* input, _In_ size_t num_chars) const { _Assume_(input || !num_chars); const size_t num_entities = m_entities.size(); - const _Elem* source = m_source.data(); - std::basic_string<_Elem, _Traits, _Alloc> output; + const T* source = m_source.data(); + std::basic_string output; for (size_t i = 0; i < num_chars && input[i];) { if (input[i] == '%') { for (size_t j = 0; j < num_entities; j++) { @@ -1917,7 +1917,7 @@ namespace stdex } protected: - std::basic_string<_Elem, _Traits, _Alloc> m_source; ///< Document HTML source code + std::basic_string m_source; ///< Document HTML source code size_t m_num_parsed; ///< Number of characters already parsed stdex::charset_id m_charset; ///< Document charset @@ -1926,13 +1926,13 @@ namespace stdex size_t m_num_invalid_conditions; ///< Number of started invalid conditions bool m_is_cdata; ///< Inside of CDATA? bool m_is_rcdata; ///< Inside of RCDATA? - stdex::parser::basic_html_declaration_condition_start<_Elem> m_condition_start; - stdex::parser::basic_html_declaration_condition_end<_Elem> m_condition_end; - stdex::parser::basic_any_cu<_Elem> m_any_char; - std::vector>> m_entities; ///< Array of entities + stdex::parser::basic_html_declaration_condition_start m_condition_start; + stdex::parser::basic_html_declaration_condition_end m_condition_end; + stdex::parser::basic_any_cu m_any_char; + std::vector>> m_entities; ///< Array of entities // Element parsing data - stdex::parser::basic_html_tag<_Elem> m_tag; + stdex::parser::basic_html_tag m_tag; sequence_store m_sequences; ///< Store of sequences std::vector m_element_stack; ///< LIFO stack of started elements bool m_is_special_element; ///< Inside of a special element (