1111
1212#include < boost/nowide/replacement.hpp>
1313#include < boost/nowide/utf/utf.hpp>
14+ #include < cassert>
1415#include < cstdint>
1516#include < locale>
1617
@@ -48,6 +49,11 @@ namespace nowide {
4849 template <typename CharType, int CharSize = sizeof (CharType)>
4950 class utf8_codecvt ;
5051
52+ #ifdef BOOST_MSVC
53+ #pragma warning(push)
54+ #pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char16_t, char, ...>
55+ #endif
56+
5157 // / Specialization for the UTF-8 <-> UTF-16 variant of the std::codecvt implementation
5258 template <typename CharType>
5359 class BOOST_SYMBOL_VISIBLE utf8_codecvt<CharType, 2 > : public std::codecvt<CharType, char , std::mbstate_t >
@@ -58,6 +64,10 @@ namespace nowide {
5864 utf8_codecvt (size_t refs = 0 ) : std::codecvt<CharType, char , std::mbstate_t >(refs)
5965 {}
6066
67+ #ifdef BOOST_MSVC
68+ #pragma warning(pop)
69+ #endif
70+
6171 protected:
6272 using uchar = CharType;
6373
@@ -81,8 +91,10 @@ namespace nowide {
8191 return false ;
8292 }
8393
94+ // LCOV_EXCL_START
8495 int do_length (std::mbstate_t & std_state, const char * from, const char * from_end, size_t max) const override
8596 {
97+ // LCOV_EXCL_STOP
8698 using utf16_traits = utf::utf_traits<uchar, 2 >;
8799 std::uint16_t state = detail::read_state (std_state);
88100 const char * save_from = from;
@@ -225,11 +237,7 @@ namespace nowide {
225237 ch = BOOST_NOWIDE_REPLACEMENT_CHARACTER;
226238 }
227239 }
228- if (!utf::is_valid_codepoint (ch))
229- {
230- r = std::codecvt_base::error;
231- break ;
232- }
240+ assert (utf::is_valid_codepoint (ch)); // Any valid UTF16 sequence is a valid codepoint
233241 int len = utf::utf_traits<char >::width (ch);
234242 if (to_end - to < len)
235243 {
@@ -248,6 +256,11 @@ namespace nowide {
248256 }
249257 };
250258
259+ #ifdef BOOST_MSVC
260+ #pragma warning(push)
261+ #pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char32_t, char, ...>
262+ #endif
263+
251264 // / Specialization for the UTF-8 <-> UTF-32 variant of the std::codecvt implementation
252265 template <typename CharType>
253266 class BOOST_SYMBOL_VISIBLE utf8_codecvt<CharType, 4 > : public std::codecvt<CharType, char , std::mbstate_t >
@@ -256,6 +269,10 @@ namespace nowide {
256269 utf8_codecvt (size_t refs = 0 ) : std::codecvt<CharType, char , std::mbstate_t >(refs)
257270 {}
258271
272+ #ifdef BOOST_MSVC
273+ #pragma warning(pop)
274+ #endif
275+
259276 protected:
260277 using uchar = CharType;
261278
@@ -296,7 +313,7 @@ namespace nowide {
296313 }
297314 max--;
298315 }
299- return from - start_from;
316+ return static_cast < int >( from - start_from) ;
300317 }
301318
302319 std::codecvt_base::result do_in (std::mbstate_t & /* state*/ ,
0 commit comments