mirror of
https://github.com/boostorg/lexical_cast.git
synced 2026-07-21 13:23:34 +00:00
Fixed conversion of std::basic_string_view and boost::basic_string_view containing one or more \0 characters.
Issue was introduced in 1.85.0
This commit is contained in:
@@ -235,6 +235,11 @@ limitation of compiler options that you use.
|
||||
|
||||
[section Changes]
|
||||
|
||||
* [*boost 1.86.0 :]
|
||||
|
||||
* Fixed conversion of `std::basic_string_view` and `boost::basic_string_view`
|
||||
containing one or more `\0` characters. Issue was introduced in 1.85.0.
|
||||
|
||||
* [*boost 1.85.0 :]
|
||||
|
||||
* Significant rewrite of the internal logic to separate optimized and C++ Standard Library IO-based streams:
|
||||
|
||||
@@ -346,13 +346,17 @@ namespace boost { namespace detail { namespace lcast {
|
||||
template <class C, class CharTraits>
|
||||
enable_if_compatible_char_t<C>
|
||||
stream_in(lcast::exact<std::basic_string_view<C, CharTraits>> x) noexcept {
|
||||
return shl_char_array_limited(reinterpret_cast<const CharT*>(x.payload.data()), x.payload.size());
|
||||
start = reinterpret_cast<const CharT*>(x.payload.data());
|
||||
finish = start + x.payload.size();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
template <class C, class CharTraits>
|
||||
enable_if_compatible_char_t<C>
|
||||
stream_in(lcast::exact<boost::basic_string_view<C, CharTraits>> x) noexcept {
|
||||
return shl_char_array_limited(reinterpret_cast<const CharT*>(x.payload.data()), x.payload.size());
|
||||
start = reinterpret_cast<const CharT*>(x.payload.data());
|
||||
finish = start + x.payload.size();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,18 +19,30 @@
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
template <class StringView>
|
||||
void test_string_view_conversion() {
|
||||
using boost::lexical_cast;
|
||||
|
||||
StringView sw = "1";
|
||||
BOOST_TEST_EQ(lexical_cast<std::string>(sw), "1");
|
||||
BOOST_TEST_EQ(lexical_cast<int>(sw), 1);
|
||||
|
||||
sw = StringView("a\0b", 3);
|
||||
BOOST_TEST_EQ(lexical_cast<std::string>(sw), std::string("a\0b", 3));
|
||||
|
||||
sw = StringView("a\0b", 4);
|
||||
BOOST_TEST_EQ(lexical_cast<std::string>(sw), std::string("a\0b", 4));
|
||||
|
||||
sw = StringView("\0a\0", 3);
|
||||
BOOST_TEST_EQ(lexical_cast<std::string>(sw), std::string("\0a\0", 3));
|
||||
}
|
||||
|
||||
int main() {
|
||||
boost::string_view bsw = "1";
|
||||
BOOST_TEST_EQ(lexical_cast<std::string>(bsw), "1");
|
||||
BOOST_TEST_EQ(lexical_cast<int>(bsw), 1);
|
||||
test_string_view_conversion<boost::string_view>();
|
||||
|
||||
#ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
|
||||
std::string_view ssw = "42";
|
||||
BOOST_TEST_EQ(lexical_cast<std::string>(ssw), "42");
|
||||
BOOST_TEST_EQ(lexical_cast<int>(ssw), 42);
|
||||
test_string_view_conversion<std::string_view>();
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
|
||||
Reference in New Issue
Block a user