mirror of
https://github.com/boostorg/lexical_cast.git
synced 2025-05-09 02:33:52 +00:00
Drop Boost.Range dependecy (#63)
This commit is contained in:
parent
c65a020401
commit
1ca93a8e27
@ -19,7 +19,6 @@ target_link_libraries(boost_lexical_cast
|
||||
Boost::core
|
||||
Boost::integer
|
||||
Boost::numeric_conversion
|
||||
Boost::range
|
||||
Boost::throw_exception
|
||||
Boost::type_traits
|
||||
)
|
||||
|
@ -27,7 +27,8 @@
|
||||
#define BOOST_LCAST_NO_WCHAR_T
|
||||
#endif
|
||||
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/lexical_cast/detail/buffer_view.hpp>
|
||||
|
||||
#include <boost/lexical_cast/bad_lexical_cast.hpp>
|
||||
#include <boost/lexical_cast/try_lexical_convert.hpp>
|
||||
|
||||
@ -49,7 +50,7 @@ namespace boost
|
||||
inline Target lexical_cast(const char* chars, std::size_t count)
|
||||
{
|
||||
return ::boost::lexical_cast<Target>(
|
||||
::boost::iterator_range<const char*>(chars, chars + count)
|
||||
::boost::conversion::detail::make_buffer_view(chars, chars + count)
|
||||
);
|
||||
}
|
||||
|
||||
@ -57,7 +58,7 @@ namespace boost
|
||||
inline Target lexical_cast(const unsigned char* chars, std::size_t count)
|
||||
{
|
||||
return ::boost::lexical_cast<Target>(
|
||||
::boost::iterator_range<const unsigned char*>(chars, chars + count)
|
||||
::boost::conversion::detail::make_buffer_view(chars, chars + count)
|
||||
);
|
||||
}
|
||||
|
||||
@ -65,7 +66,7 @@ namespace boost
|
||||
inline Target lexical_cast(const signed char* chars, std::size_t count)
|
||||
{
|
||||
return ::boost::lexical_cast<Target>(
|
||||
::boost::iterator_range<const signed char*>(chars, chars + count)
|
||||
::boost::conversion::detail::make_buffer_view(chars, chars + count)
|
||||
);
|
||||
}
|
||||
|
||||
@ -74,7 +75,7 @@ namespace boost
|
||||
inline Target lexical_cast(const wchar_t* chars, std::size_t count)
|
||||
{
|
||||
return ::boost::lexical_cast<Target>(
|
||||
::boost::iterator_range<const wchar_t*>(chars, chars + count)
|
||||
::boost::conversion::detail::make_buffer_view(chars, chars + count)
|
||||
);
|
||||
}
|
||||
#endif
|
||||
@ -82,14 +83,14 @@ namespace boost
|
||||
inline Target lexical_cast(const char16_t* chars, std::size_t count)
|
||||
{
|
||||
return ::boost::lexical_cast<Target>(
|
||||
::boost::iterator_range<const char16_t*>(chars, chars + count)
|
||||
::boost::conversion::detail::make_buffer_view(chars, chars + count)
|
||||
);
|
||||
}
|
||||
template <typename Target>
|
||||
inline Target lexical_cast(const char32_t* chars, std::size_t count)
|
||||
{
|
||||
return ::boost::lexical_cast<Target>(
|
||||
::boost::iterator_range<const char32_t*>(chars, chars + count)
|
||||
::boost::conversion::detail::make_buffer_view(chars, chars + count)
|
||||
);
|
||||
}
|
||||
|
||||
|
59
include/boost/lexical_cast/detail/buffer_view.hpp
Normal file
59
include/boost/lexical_cast/detail/buffer_view.hpp
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright Antony Polukhin, 2011-2023.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
|
||||
#define BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#ifdef BOOST_HAS_PRAGMA_ONCE
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace boost { namespace conversion { namespace detail {
|
||||
|
||||
template < typename CharT >
|
||||
struct buffer_view {
|
||||
const CharT* begin;
|
||||
const CharT* end;
|
||||
};
|
||||
|
||||
template < typename CharT >
|
||||
buffer_view<CharT> make_buffer_view(const CharT* begin, const CharT* end) {
|
||||
return buffer_view<CharT>{begin, end};
|
||||
}
|
||||
|
||||
inline buffer_view<char> make_buffer_view(const signed char* begin, const signed char* end) {
|
||||
return buffer_view<char>{
|
||||
reinterpret_cast<const char*>(begin),
|
||||
reinterpret_cast<const char*>(end)
|
||||
};
|
||||
}
|
||||
|
||||
inline buffer_view<char> make_buffer_view(const unsigned char* begin, const unsigned char* end) {
|
||||
return buffer_view<char>{
|
||||
reinterpret_cast<const char*>(begin),
|
||||
reinterpret_cast<const char*>(end)
|
||||
};
|
||||
}
|
||||
|
||||
template< typename CharT, typename Elem, typename Traits >
|
||||
std::basic_ostream<Elem,Traits>& operator<<(
|
||||
std::basic_ostream<Elem, Traits>& os,
|
||||
buffer_view<CharT> r)
|
||||
{
|
||||
while (r.begin != r.end) {
|
||||
os << r.begin[0];
|
||||
++r.begin;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
}}} // namespace boost::conversion::detail
|
||||
|
||||
#endif // BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/lexical_cast/detail/buffer_view.hpp>
|
||||
#include <boost/container/container_fwd.hpp>
|
||||
|
||||
#include <boost/lexical_cast/detail/converter_lexical_streams.hpp>
|
||||
@ -54,6 +54,8 @@ namespace boost {
|
||||
// Forward declaration
|
||||
template<class T, std::size_t N>
|
||||
class array;
|
||||
template<class IteratorT>
|
||||
class iterator_range;
|
||||
|
||||
namespace detail // normalize_single_byte_char<Char>
|
||||
{
|
||||
@ -110,6 +112,12 @@ namespace boost {
|
||||
boost::detail::deduce_character_type_later< const Char* >
|
||||
> {};
|
||||
|
||||
template < typename Char >
|
||||
struct stream_char_common< boost::conversion::detail::buffer_view< Char > >
|
||||
{
|
||||
typedef Char type;
|
||||
};
|
||||
|
||||
template < typename Char >
|
||||
struct stream_char_common< boost::iterator_range< Char* > >: public boost::conditional<
|
||||
boost::detail::is_character< Char >::value,
|
||||
|
@ -69,11 +69,12 @@
|
||||
#include <boost/type_traits/make_unsigned.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/type_traits/is_float.hpp>
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/lexical_cast/detail/buffer_view.hpp>
|
||||
#include <boost/container/container_fwd.hpp>
|
||||
#include <boost/integer.hpp>
|
||||
#include <boost/detail/basic_pointerbuf.hpp>
|
||||
#include <boost/core/noncopyable.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#ifndef BOOST_NO_CWCHAR
|
||||
# include <cwchar>
|
||||
#endif
|
||||
@ -83,6 +84,8 @@ namespace boost {
|
||||
// Forward declaration
|
||||
template<class T, std::size_t N>
|
||||
class array;
|
||||
template<class IteratorT>
|
||||
class iterator_range;
|
||||
|
||||
namespace detail // basic_unlockedbuf
|
||||
{
|
||||
@ -217,7 +220,11 @@ namespace boost {
|
||||
|
||||
bool shl_char_array_limited(CharT const* str, std::size_t max_size) noexcept {
|
||||
start = str;
|
||||
finish = std::find(start, start + max_size, Traits::to_char_type(0));
|
||||
finish = start;
|
||||
const auto zero = Traits::to_char_type(0);
|
||||
while (finish < start + max_size && zero != *finish) {
|
||||
++ finish;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -363,30 +370,15 @@ namespace boost {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
typename boost::disable_if<boost::is_const<C>, bool>::type
|
||||
operator<<(const iterator_range<C*>& rng) noexcept {
|
||||
return (*this) << iterator_range<const C*>(rng.begin(), rng.end());
|
||||
}
|
||||
|
||||
bool operator<<(const iterator_range<const CharT*>& rng) noexcept {
|
||||
start = rng.begin();
|
||||
finish = rng.end();
|
||||
bool operator<<(boost::conversion::detail::buffer_view<CharT> rng) noexcept {
|
||||
start = rng.begin;
|
||||
finish = rng.end;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator<<(const iterator_range<const signed char*>& rng) noexcept {
|
||||
return (*this) << iterator_range<const char*>(
|
||||
reinterpret_cast<const char*>(rng.begin()),
|
||||
reinterpret_cast<const char*>(rng.end())
|
||||
);
|
||||
}
|
||||
|
||||
bool operator<<(const iterator_range<const unsigned char*>& rng) noexcept {
|
||||
return (*this) << iterator_range<const char*>(
|
||||
reinterpret_cast<const char*>(rng.begin()),
|
||||
reinterpret_cast<const char*>(rng.end())
|
||||
);
|
||||
template <class C>
|
||||
bool operator<<(const iterator_range<C*>& rng) noexcept {
|
||||
return (*this) << boost::conversion::detail::make_buffer_view(rng.begin(), rng.end());
|
||||
}
|
||||
|
||||
bool operator<<(char ch) { return shl_char(ch); }
|
||||
|
@ -39,11 +39,11 @@
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_arithmetic.hpp>
|
||||
|
||||
#include <boost/lexical_cast/detail/buffer_view.hpp>
|
||||
#include <boost/lexical_cast/detail/is_character.hpp>
|
||||
#include <boost/lexical_cast/detail/converter_numeric.hpp>
|
||||
#include <boost/lexical_cast/detail/converter_lexical.hpp>
|
||||
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/container/container_fwd.hpp>
|
||||
|
||||
namespace boost {
|
||||
@ -209,7 +209,8 @@ namespace boost {
|
||||
"This overload of try_lexical_convert is meant to be used only with arrays of characters."
|
||||
);
|
||||
return ::boost::conversion::detail::try_lexical_convert(
|
||||
::boost::iterator_range<const CharacterT*>(chars, chars + count), result
|
||||
::boost::conversion::detail::make_buffer_view(chars, chars + count),
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user