From 48e35c1ebd873fa7e150f8149c16d6e3d74f389c Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 4 Mar 2024 13:37:29 +0100 Subject: [PATCH] =?UTF-8?q?sgml:=20std::basic=5Fstring=5Fview=20=E2=86=92?= =?UTF-8?q?=20std::basic=5Fstring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MSVC fails to deduce character type from std::string/wstring when converting to std::basic_string_view. Reference: f5bce32d06cdcf677ce8080027d3317c6387e715 Signed-off-by: Simon Rozman --- include/stdex/sgml.hpp | 101 +++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/include/stdex/sgml.hpp b/include/stdex/sgml.hpp index b6aad55d4..e9d773ff1 100644 --- a/include/stdex/sgml.hpp +++ b/include/stdex/sgml.hpp @@ -11,7 +11,6 @@ #include "string.hpp" #include #include -#include #include #if defined(__GNUC__) @@ -117,9 +116,9 @@ namespace stdex /// /// Checks SGML string for error /// - /// \param[in] src SGML string - /// \param[in] count_src SGML string character count limit - /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra checks. Currently, only stdex::sgml_full is used, which enforces 7-bit/ASCII checking. + /// \param[in] src SGML string + /// \param[in] count_src SGML string character count limit + /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra checks. Currently, only stdex::sgml_full is used, which enforces 7-bit/ASCII checking. /// /// \return Index of error; or stdex::npos if no error detected. /// @@ -163,6 +162,22 @@ namespace stdex return npos; } + /// + /// Checks SGML string for error + /// + /// \param[in] src SGML string + /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra checks. Currently, only stdex::sgml_full is used, which enforces 7-bit/ASCII checking. + /// + /// \return Index of error; or stdex::npos if no error detected. + /// + template , class AX_from = std::allocator> + size_t sgmlerr( + _In_ const std::basic_string& src, + _In_ int what = 0) + { + return sgmlerr(src.data(), src.size(), what); + } + /// /// Convert SGML string to Unicode and append to string /// @@ -173,7 +188,7 @@ namespace stdex /// \param[in] offset Logical starting offset of source and destination strings. Unused when map parameter is nullptr. /// \param[in,out] map The vector to append index mapping between source and destination string to. /// - template , class AX_to = std::allocator> + template , class AX_to = std::allocator> void sgml2strcat( _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src, @@ -238,13 +253,13 @@ namespace stdex /// /// Convert SGML string to Unicode and append to string /// - /// \param[in,out] dst String to append Unicode to - /// \param[in] src SGML string - /// \param[in] skip Bitwise flag of stdex::sgml_* constants that list SGML entities to skip converting - /// \param[in] offset Logical starting offset of source and destination strings. Unused when map parameter is nullptr. - /// \param[in,out] map The vector to append index mapping between source and destination string to. + /// \param[in,out] dst String to append Unicode to + /// \param[in] src SGML string + /// \param[in] skip Bitwise flag of stdex::sgml_* constants that list SGML entities to skip converting + /// \param[in] offset Logical starting offset of source and destination strings. Unused when map parameter is nullptr. + /// \param[in,out] map The vector to append index mapping between source and destination string to. /// - template , class AX_to = std::allocator, class TR_from = std::char_traits, class AX_from = std::allocator> + template , class AX_to = std::allocator, class TR_from = std::char_traits, class AX_from = std::allocator> void sgml2strcat( _Inout_ std::basic_string& dst, _In_ const std::basic_string& src, @@ -268,7 +283,7 @@ namespace stdex /// /// \return Final length of SGML string in code points excluding zero-terminator /// - template + template size_t sgml2strcat( _Inout_cap_(count_dst) T_to* dst, _In_ size_t count_dst, _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src, @@ -349,7 +364,7 @@ namespace stdex /// \param[in] offset Logical starting offset of source and destination strings. Unused when map parameter is nullptr. /// \param[in,out] map The vector to write index mapping between source and destination string to. /// - template , class AX_to = std::allocator> + template , class AX_to = std::allocator> void sgml2strcpy( _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src, @@ -366,13 +381,13 @@ namespace stdex /// /// Convert SGML string to Unicode /// - /// \param[in,out] dst String to write Unicode to - /// \param[in] src SGML string - /// \param[in] skip Bitwise flag of stdex::sgml_* constants that list SGML entities to skip converting - /// \param[in] offset Logical starting offset of source and destination strings. Unused when map parameter is nullptr. - /// \param[in,out] map The vector to write index mapping between source and destination string to. + /// \param[in,out] dst String to write Unicode to + /// \param[in] src SGML string + /// \param[in] skip Bitwise flag of stdex::sgml_* constants that list SGML entities to skip converting + /// \param[in] offset Logical starting offset of source and destination strings. Unused when map parameter is nullptr. + /// \param[in,out] map The vector to write index mapping between source and destination string to. /// - template, class AX_to = std::allocator, class TR_from = std::char_traits, class AX_from = std::allocator> + template, class AX_to = std::allocator, class TR_from = std::char_traits, class AX_from = std::allocator> void sgml2strcpy( _Inout_ std::basic_string& dst, _In_ const std::basic_string& src, @@ -396,7 +411,7 @@ namespace stdex /// /// \return Final length of SGML string in code points excluding zero-terminator /// - template + template size_t sgml2strcpy( _Inout_cap_(count_dst) T_to* dst, _In_ size_t count_dst, _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src, @@ -438,10 +453,10 @@ namespace stdex /// /// Convert SGML string to Unicode string (UTF-16 on Windows) /// - /// \param[in] src SGML string - /// \param[in] skip Bitwise flag of stdex::sgml_* constants that list SGML entities to skip converting - /// \param[in] offset Logical starting offset of source and destination strings. Unused when map parameter is nullptr. - /// \param[in,out] map The vector to append index mapping between source and destination string to. + /// \param[in] src SGML string + /// \param[in] skip Bitwise flag of stdex::sgml_* constants that list SGML entities to skip converting + /// \param[in] offset Logical starting offset of source and destination strings. Unused when map parameter is nullptr. + /// \param[in,out] map The vector to append index mapping between source and destination string to. /// /// \return Unicode string /// @@ -546,7 +561,7 @@ namespace stdex /// \param[in] count_src Unicode string character count limit /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML /// - template , class AX_to = std::allocator> + template , class AX_to = std::allocator> void str2sgmlcat( _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src, @@ -634,14 +649,14 @@ namespace stdex /// /// Convert Unicode string to SGML and append to string /// - /// \param[in,out] dst String to append SGML to - /// \param[in] src Unicode string - /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML + /// \param[in,out] dst String to append SGML to + /// \param[in] src Unicode string + /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML /// - template , class AX_to = std::allocator> + template , class AX_to = std::allocator, class TR_from = std::char_traits, class AX_from = std::allocator> void str2sgmlcat( _Inout_ std::basic_string& dst, - _In_ const std::basic_string_view> src, + _In_ const std::basic_string& src, _In_ int what = 0) { str2sgmlcat(dst, src.data(), src.size(), what); @@ -658,7 +673,7 @@ namespace stdex /// /// \return Final length of SGML string in code points excluding zero-terminator /// - template + template size_t str2sgmlcat( _Inout_cap_(count_dst) char* dst, _In_ size_t count_dst, _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src, @@ -779,7 +794,7 @@ namespace stdex /// \param[in] count_src Unicode string character count limit /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML /// - template , class AX_to = std::allocator> + template , class AX_to = std::allocator> void str2sgmlcpy( _Inout_ std::basic_string& dst, _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src, @@ -792,14 +807,14 @@ namespace stdex /// /// Convert Unicode string to SGML /// - /// \param[in,out] dst String to write SGML to - /// \param[in] src Unicode string - /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML + /// \param[in,out] dst String to write SGML to + /// \param[in] src Unicode string + /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML /// - template , class AX_to = std::allocator> + template , class AX_to = std::allocator, class TR_from = std::char_traits, class AX_from = std::allocator> void str2sgmlcpy( _Inout_ std::basic_string& dst, - _In_ const std::basic_string_view> src, + _In_ const std::basic_string& src, _In_ int what = 0) { str2sgmlcpy(dst, src.data(), src.size(), what); @@ -816,7 +831,7 @@ namespace stdex /// /// \return Final length of SGML string in code points excluding zero-terminator /// - template + template size_t str2sgmlcpy( _Inout_cap_(count_dst) char* dst, _In_ size_t count_dst, _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src, @@ -837,7 +852,7 @@ namespace stdex /// /// \return SGML string /// - template + template std::string str2sgml( _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src, _In_ int what = 0) @@ -850,14 +865,14 @@ namespace stdex /// /// Convert Unicode string to SGML string /// - /// \param[in] src Unicode string - /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML + /// \param[in] src Unicode string + /// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML /// /// \return SGML string /// - template + template , class AX_from = std::allocator> std::string str2sgml( - _In_ const std::basic_string_view> src, + _In_ const std::basic_string& src, _In_ int what = 0) { return str2sgml(src.data(), src.size(), what);