|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74361 - in branches/release: boost libs/conversion
From: antoshkka_at_[hidden]
Date: 2011-09-12 14:15:32
Author: apolukhin
Date: 2011-09-12 14:15:31 EDT (Mon, 12 Sep 2011)
New Revision: 74361
URL: http://svn.boost.org/trac/boost/changeset/74361
Log:
Mereged from r74355
Basic support for char16_t and char32_t
Text files modified:
branches/release/boost/lexical_cast.hpp | 223 ++++++++++++++++++++++++---------------
branches/release/libs/conversion/lexical_cast_test.cpp | 34 +++++
2 files changed, 166 insertions(+), 91 deletions(-)
Modified: branches/release/boost/lexical_cast.hpp
==============================================================================
--- branches/release/boost/lexical_cast.hpp (original)
+++ branches/release/boost/lexical_cast.hpp 2011-09-12 14:15:31 EDT (Mon, 12 Sep 2011)
@@ -133,60 +133,102 @@
namespace detail // selectors for choosing stream character type
{
- template<typename Type>
- struct stream_char
- {
- typedef char type;
- };
+ template<typename Type>
+ struct stream_char
+ {
+ typedef char type;
+ };
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- template<class CharT, class Traits, class Alloc>
- struct stream_char< std::basic_string<CharT,Traits,Alloc> >
- {
- typedef CharT type;
- };
+ template<class CharT, class Traits, class Alloc>
+ struct stream_char< std::basic_string<CharT,Traits,Alloc> >
+ {
+ typedef CharT type;
+ };
#endif
#ifndef BOOST_LCAST_NO_WCHAR_T
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
- template<>
- struct stream_char<wchar_t>
- {
- typedef wchar_t type;
- };
+ template<>
+ struct stream_char<wchar_t>
+ {
+ typedef wchar_t type;
+ };
#endif
- template<>
- struct stream_char<wchar_t *>
- {
- typedef wchar_t type;
- };
+ template<>
+ struct stream_char<wchar_t *>
+ {
+ typedef wchar_t type;
+ };
- template<>
- struct stream_char<const wchar_t *>
- {
- typedef wchar_t type;
- };
+ template<>
+ struct stream_char<const wchar_t *>
+ {
+ typedef wchar_t type;
+ };
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- template<>
- struct stream_char<std::wstring>
- {
- typedef wchar_t type;
- };
+ template<>
+ struct stream_char<std::wstring>
+ {
+ typedef wchar_t type;
+ };
+#endif
#endif
+
+
+#ifndef BOOST_NO_CHAR16_T
+
+ template<>
+ struct stream_char<char16_t>
+ {
+ typedef char16_t type;
+ };
+
+ template<>
+ struct stream_char<char16_t *>
+ {
+ typedef char16_t type;
+ };
+
+ template<>
+ struct stream_char<const char16_t *>
+ {
+ typedef char16_t type;
+ };
+
+#endif
+
+#ifndef BOOST_NO_CHAR32_T
+
+ template<>
+ struct stream_char<char32_t>
+ {
+ typedef char32_t type;
+ };
+
+ template<>
+ struct stream_char<char32_t *>
+ {
+ typedef char32_t type;
+ };
+
+ template<>
+ struct stream_char<const char32_t *>
+ {
+ typedef char32_t type;
+ };
+
#endif
template<typename TargetChar, typename SourceChar>
struct widest_char
{
- typedef TargetChar type;
- };
-
- template<>
- struct widest_char<char, wchar_t>
- {
- typedef wchar_t type;
+ typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
+ (sizeof(TargetChar) > sizeof(SourceChar))
+ , TargetChar
+ , SourceChar >::type type;
};
}
@@ -231,8 +273,7 @@
namespace detail // lcast_src_length
{
// Return max. length of string representation of Source;
- template< class CharT // A result of widest_char transformation.
- , class Source // Source type of lexical_cast.
+ template< class Source // Source type of lexical_cast.
>
struct lcast_src_length
{
@@ -269,20 +310,12 @@
BOOST_STATIC_ASSERT(sizeof(Source) * CHAR_BIT <= 256);
#endif
};
-
-#define BOOST_LCAST_DEF1(CharT, T) \
- template<> struct lcast_src_length<CharT, T> \
+// TODO: FIX for char16_t, char32_t, we can ignore CharT
+#define BOOST_LCAST_DEF(T) \
+ template<> struct lcast_src_length<T> \
: lcast_src_length_integral<T> \
{ static void check_coverage() {} };
-#ifdef BOOST_LCAST_NO_WCHAR_T
-#define BOOST_LCAST_DEF(T) BOOST_LCAST_DEF1(char, T)
-#else
-#define BOOST_LCAST_DEF(T) \
- BOOST_LCAST_DEF1(char, T) \
- BOOST_LCAST_DEF1(wchar_t, T)
-#endif
-
BOOST_LCAST_DEF(short)
BOOST_LCAST_DEF(unsigned short)
BOOST_LCAST_DEF(int)
@@ -298,7 +331,6 @@
#endif
#undef BOOST_LCAST_DEF
-#undef BOOST_LCAST_DEF1
#ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
// Helper for floating point types.
@@ -324,49 +356,26 @@
};
template<>
- struct lcast_src_length<char,float>
+ struct lcast_src_length<float>
: lcast_src_length_floating<float>
{
static void check_coverage() {}
};
template<>
- struct lcast_src_length<char,double>
+ struct lcast_src_length<double>
: lcast_src_length_floating<double>
{
static void check_coverage() {}
};
template<>
- struct lcast_src_length<char,long double>
+ struct lcast_src_length<long double>
: lcast_src_length_floating<long double>
{
static void check_coverage() {}
};
-#ifndef BOOST_LCAST_NO_WCHAR_T
- template<>
- struct lcast_src_length<wchar_t,float>
- : lcast_src_length_floating<float>
- {
- static void check_coverage() {}
- };
-
- template<>
- struct lcast_src_length<wchar_t,double>
- : lcast_src_length_floating<double>
- {
- static void check_coverage() {}
- };
-
- template<>
- struct lcast_src_length<wchar_t,long double>
- : lcast_src_length_floating<long double>
- {
- static void check_coverage() {}
- };
-
-#endif // #ifndef BOOST_LCAST_NO_WCHAR_T
#endif // #ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
}
@@ -397,6 +406,32 @@
BOOST_STATIC_CONSTANT(wchar_t, c_decimal_separator = L'.');
};
#endif
+
+#ifndef BOOST_NO_CHAR16_T
+ template<>
+ struct lcast_char_constants<char16_t>
+ {
+ BOOST_STATIC_CONSTANT(char16_t, zero = u'0');
+ BOOST_STATIC_CONSTANT(char16_t, minus = u'-');
+ BOOST_STATIC_CONSTANT(char16_t, plus = u'+');
+ BOOST_STATIC_CONSTANT(char16_t, lowercase_e = u'e');
+ BOOST_STATIC_CONSTANT(char16_t, capital_e = u'E');
+ BOOST_STATIC_CONSTANT(char16_t, c_decimal_separator = u'.');
+ };
+#endif
+
+#ifndef BOOST_NO_CHAR32_T
+ template<>
+ struct lcast_char_constants<char32_t>
+ {
+ BOOST_STATIC_CONSTANT(char32_t, zero = U'0');
+ BOOST_STATIC_CONSTANT(char32_t, minus = U'-');
+ BOOST_STATIC_CONSTANT(char32_t, plus = U'+');
+ BOOST_STATIC_CONSTANT(char32_t, lowercase_e = U'e');
+ BOOST_STATIC_CONSTANT(char32_t, capital_e = U'E');
+ BOOST_STATIC_CONSTANT(char32_t, c_decimal_separator = U'.');
+ };
+#endif
}
namespace detail // lcast_to_unsigned
@@ -1553,28 +1588,38 @@
template<typename T>
struct is_char_or_wchar
{
+ private:
#ifndef BOOST_LCAST_NO_WCHAR_T
- BOOST_STATIC_CONSTANT(bool, value =
- (
- ::boost::type_traits::ice_or<
- is_same< T, char >::value,
- is_same< T, wchar_t >::value,
- is_same< T, unsigned char >::value,
- is_same< T, signed char >::value
- >::value
- )
- );
+ typedef wchar_t wchar_t_if_supported;
+#else
+ typedef char wchar_t_if_supported;
+#endif
+
+#ifndef BOOST_NO_CHAR16_T
+ typedef char16_t char16_t_if_supported;
+#else
+ typedef char char16_t_if_supported;
+#endif
+
+#ifndef BOOST_NO_CHAR32_T
+ typedef char32_t char32_t_if_supported;
#else
+ typedef char char32_t_if_supported;
+#endif
+ public:
+
BOOST_STATIC_CONSTANT(bool, value =
(
::boost::type_traits::ice_or<
is_same< T, char >::value,
+ is_same< T, wchar_t_if_supported >::value,
+ is_same< T, char16_t_if_supported >::value,
+ is_same< T, char32_t_if_supported >::value,
is_same< T, unsigned char >::value,
is_same< T, signed char >::value
>::value
)
);
-#endif
};
template<typename Target, typename Source>
@@ -1658,7 +1703,7 @@
, BOOST_DEDUCED_TYPENAME detail::stream_char<src>::type
>::type char_type;
- typedef detail::lcast_src_length<char_type, src> lcast_src_length;
+ typedef detail::lcast_src_length<src> lcast_src_length;
std::size_t const src_len = lcast_src_length::value;
char_type buf[src_len + 1];
lcast_src_length::check_coverage();
Modified: branches/release/libs/conversion/lexical_cast_test.cpp
==============================================================================
--- branches/release/libs/conversion/lexical_cast_test.cpp (original)
+++ branches/release/libs/conversion/lexical_cast_test.cpp 2011-09-12 14:15:31 EDT (Mon, 12 Sep 2011)
@@ -100,6 +100,13 @@
#endif
void test_char_types_conversions();
void operators_overload_test();
+#ifndef BOOST_NO_CHAR16_T
+void test_char16_conversions();
+#endif
+#ifndef BOOST_NO_CHAR32_T
+void test_char32_conversions();
+#endif
+
unit_test::test_suite *init_unit_test_suite(int, char *[])
{
@@ -142,6 +149,12 @@
suite->add(BOOST_TEST_CASE(&test_char_types_conversions));
suite->add(BOOST_TEST_CASE(&operators_overload_test));
+#ifndef BOOST_NO_CHAR16_T
+ suite->add(BOOST_TEST_CASE(&test_char16_conversions));
+#endif
+#ifndef BOOST_NO_CHAR32_T
+ suite->add(BOOST_TEST_CASE(&test_char32_conversions));
+#endif
return suite;
}
@@ -582,7 +595,7 @@
// Test values around zero:
if(limits::is_signed)
- for(t = -counter; t < static_cast<T>(counter); ++t)
+ for(t = static_cast<T>(-counter); t < static_cast<T>(counter); ++t)
BOOST_CHECK(lexical_cast<string_type>(t) == to_str<CharT>(t));
// Test values around 100, 1000, 10000, ...
@@ -679,7 +692,7 @@
// Test values around zero:
if(limits::is_signed)
- for(t = -counter; t < static_cast<T>(counter); ++t)
+ for(t = static_cast<T>(-counter); t < static_cast<T>(counter); ++t)
BOOST_CHECK(lexical_cast<T>(to_str<CharT>(t)) == t);
// Test values around 100, 1000, 10000, ...
@@ -990,3 +1003,20 @@
(void)boost::lexical_cast<foo_operators_test>(foo);
}
+
+#ifndef BOOST_NO_CHAR16_T
+void test_char16_conversions()
+{
+ BOOST_CHECK(u"100" == lexical_cast<std::u16string>(u"100"));
+ BOOST_CHECK(u"1" == lexical_cast<std::u16string>(u'1'));
+}
+#endif
+
+#ifndef BOOST_NO_CHAR32_T
+void test_char32_conversions()
+{
+ BOOST_CHECK(U"100" == lexical_cast<std::u32string>(U"100"));
+ BOOST_CHECK(U"1" == lexical_cast<std::u32string>(U'1'));
+}
+#endif
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk