forked from boostorg/conversion
overloading fix + less permissive wide character support
[SVN r17893]
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
#ifndef BOOST_LEXICAL_CAST_INCLUDED
|
||||
#define BOOST_LEXICAL_CAST_INCLUDED
|
||||
|
||||
// boost lexical_cast.hpp header --------------------------------------------//
|
||||
|
||||
// See http://www.boost.org/libs/conversion for documentation.
|
||||
// Boost lexical_cast.hpp header -------------------------------------------//
|
||||
//
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
// See end of this header for rights and permissions.
|
||||
//
|
||||
// what: lexical_cast custom keyword cast
|
||||
// who: contributed by Kevlin Henney,
|
||||
// enhanced with contributions from Terje Sletteb<65>,
|
||||
// with additional fixes and suggestions from Gennaro Prota,
|
||||
// Dave Abrahams, Daryle Walker, and other Boosters on the list
|
||||
// Beman Dawes, Dave Abrahams, Daryle Walker, and other Boosters
|
||||
// when: November 2000, March 2003
|
||||
|
||||
#include <string>
|
||||
@@ -25,6 +25,12 @@
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NO_STRINGSTREAM) || \
|
||||
defined(BOOST_NO_STD_WSTRING) || \
|
||||
defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
||||
#define DISABLE_WIDE_CHAR_SUPPORT
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
// exception used to indicate runtime lexical_cast failure
|
||||
@@ -69,7 +75,7 @@ namespace boost
|
||||
typedef char type;
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_STRINGSTREAM
|
||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||
template<>
|
||||
struct stream_char<wchar_t>
|
||||
{
|
||||
@@ -88,7 +94,6 @@ namespace boost
|
||||
typedef wchar_t type;
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_STD_WSTRING
|
||||
template<>
|
||||
struct stream_char<std::wstring>
|
||||
{
|
||||
@@ -96,8 +101,6 @@ namespace boost
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
template<typename TargetChar, typename SourceChar>
|
||||
struct widest_char
|
||||
{
|
||||
@@ -143,11 +146,16 @@ namespace boost
|
||||
stream >> output &&
|
||||
(stream >> std::ws).eof();
|
||||
}
|
||||
template<typename Char, typename Traits, typename Allocator>
|
||||
bool operator>>(std::basic_string<Char, Traits, Allocator> &output)
|
||||
bool operator>>(std::string &output)
|
||||
{
|
||||
return std::getline(stream, output, char_type()).eof();
|
||||
}
|
||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||
bool operator>>(std::wstring &output)
|
||||
{
|
||||
return std::getline(stream, output, char_type()).eof();
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
typedef typename widest_char<
|
||||
typename stream_char<Target>::type,
|
||||
@@ -181,4 +189,5 @@ namespace boost
|
||||
//
|
||||
// This software is provided "as is" without express or implied warranty.
|
||||
|
||||
#undef DISABLE_WIDE_CHAR_SUPPORT
|
||||
#endif
|
||||
|
@@ -22,11 +22,10 @@
|
||||
#include <boost/test/floating_point_comparison.hpp>
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
// If BOOST_NO_STRINGSTREAM is defined wide character support is unavailable,
|
||||
// and all wide character tests are disabled.
|
||||
|
||||
#ifdef BOOST_NO_STRINGSTREAM
|
||||
#define NO_WIDE_CHAR_SUPPORT
|
||||
#if defined(BOOST_NO_STRINGSTREAM) || \
|
||||
defined(BOOST_NO_STD_WSTRING) || \
|
||||
defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
||||
#define DISABLE_WIDE_CHAR_SUPPORT
|
||||
#endif
|
||||
|
||||
using namespace boost;
|
||||
@@ -52,7 +51,7 @@ unit_test_framework::test_suite *init_unit_test_suite(int, char **)
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_to_bool));
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_to_pointer));
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_to_string));
|
||||
#ifndef NO_WIDE_CHAR_SUPPORT
|
||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_from_wchar_t));
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_to_wchar_t));
|
||||
suite->add(BOOST_TEST_CASE(test_conversion_from_wstring));
|
||||
@@ -175,7 +174,6 @@ void test_conversion_to_bool()
|
||||
|
||||
void test_conversion_to_string()
|
||||
{
|
||||
// *** All the following gives compilation error (ambiguity) on MSVC 6
|
||||
BOOST_CHECK_EQUAL("A", lexical_cast<std::string>('A'));
|
||||
BOOST_CHECK_EQUAL(" ", lexical_cast<std::string>(' '));
|
||||
BOOST_CHECK_EQUAL("123", lexical_cast<std::string>(123));
|
||||
@@ -197,14 +195,14 @@ void test_conversion_to_string()
|
||||
void test_conversion_to_pointer()
|
||||
{
|
||||
BOOST_CHECK_THROW(lexical_cast<char *>("Test"), boost::bad_lexical_cast);
|
||||
#ifndef NO_WIDE_CHAR_SUPPORT
|
||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||
BOOST_CHECK_THROW(lexical_cast<wchar_t *>("Test"), boost::bad_lexical_cast);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_conversion_from_wchar_t()
|
||||
{
|
||||
#ifndef NO_WIDE_CHAR_SUPPORT
|
||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||
BOOST_CHECK_EQUAL(1, lexical_cast<int>(L'1'));
|
||||
BOOST_CHECK_THROW(lexical_cast<int>(L'A'), boost::bad_lexical_cast);
|
||||
|
||||
@@ -241,7 +239,7 @@ void test_conversion_from_wchar_t()
|
||||
|
||||
void test_conversion_to_wchar_t()
|
||||
{
|
||||
#ifndef NO_WIDE_CHAR_SUPPORT
|
||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||
BOOST_CHECK_EQUAL(L'1', lexical_cast<wchar_t>(1));
|
||||
BOOST_CHECK_EQUAL(L'0', lexical_cast<wchar_t>(0));
|
||||
BOOST_CHECK_THROW(lexical_cast<wchar_t>(123), boost::bad_lexical_cast);
|
||||
@@ -270,7 +268,7 @@ void test_conversion_to_wchar_t()
|
||||
|
||||
void test_conversion_from_wstring()
|
||||
{
|
||||
#ifndef NO_WIDE_CHAR_SUPPORT
|
||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||
BOOST_CHECK_EQUAL(123, lexical_cast<int>(std::wstring(L"123")));
|
||||
BOOST_CHECK_THROW(
|
||||
lexical_cast<int>(std::wstring(L"")), boost::bad_lexical_cast);
|
||||
@@ -294,7 +292,7 @@ void test_conversion_from_wstring()
|
||||
|
||||
void test_conversion_to_wstring()
|
||||
{
|
||||
#ifndef NO_WIDE_CHAR_SUPPORT
|
||||
#ifndef DISABLE_WIDE_CHAR_SUPPORT
|
||||
BOOST_CHECK(L"123" == lexical_cast<std::wstring>(123));
|
||||
BOOST_CHECK(L"1.23" == lexical_cast<std::wstring>(1.23));
|
||||
BOOST_CHECK(L"1.111111111" == lexical_cast<std::wstring>(1.111111111));
|
||||
|
Reference in New Issue
Block a user