|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76154 - in trunk: boost libs/conversion/doc libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2011-12-25 13:55:33
Author: apolukhin
Date: 2011-12-25 13:55:33 EST (Sun, 25 Dec 2011)
New Revision: 76154
URL: http://svn.boost.org/trac/boost/changeset/76154
Log:
Fixes #6290
Tiny documentation update
Updated char16_t and char32_t support (still some work required)
lexical_cast_empty_input_test.cpp refactored
Text files modified:
trunk/boost/lexical_cast.hpp | 24 +++++++++++-
trunk/libs/conversion/doc/lexical_cast.qbk | 2
trunk/libs/conversion/test/lexical_cast_empty_input_test.cpp | 80 ++++++++++++++++++++++++++++------------
3 files changed, 79 insertions(+), 27 deletions(-)
Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp (original)
+++ trunk/boost/lexical_cast.hpp 2011-12-25 13:55:33 EST (Sun, 25 Dec 2011)
@@ -18,7 +18,7 @@
// with additional fixes and suggestions from Gennaro Prota,
// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
// Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
-// Cheng Yang and other Boosters
+// Cheng Yang, Matthew Bradbury and other Boosters
// when: November 2000, March 2003, June 2005, June 2006, March 2011
#include <climits>
@@ -744,6 +744,26 @@
, L'(', L')');
}
#endif
+#ifndef BOOST_NO_CHAR16_T
+ template <class T>
+ bool parse_inf_nan(const char16_t* begin, const char16_t* end, T& value)
+ {
+ return parse_inf_nan_impl(begin, end, value
+ , u"NAN", u"nan"
+ , u"INFINITY", u"infinity"
+ , u'(', u')');
+ }
+#endif
+#ifndef BOOST_NO_CHAR32_T
+ template <class T>
+ bool parse_inf_nan(const char32_t* begin, const char32_t* end, T& value)
+ {
+ return parse_inf_nan_impl(begin, end, value
+ , U"NAN", U"nan"
+ , U"INFINITY", U"infinity"
+ , U'(', U')');
+ }
+#endif
template <class CharT, class T>
bool parse_inf_nan(const CharT* begin, const CharT* end, T& value)
@@ -864,7 +884,7 @@
CharT const thousands_sep = grouping_size ? np.thousands_sep() : 0;
CharT const decimal_point = np.decimal_point();
bool found_grouping = false;
- unsigned int last_grouping_pos = grouping_size - 1;
+ std::string::size_type last_grouping_pos = grouping_size - 1;
#else
CharT const decimal_point = lcast_char_constants<CharT>::c_decimal_separator;
#endif
Modified: trunk/libs/conversion/doc/lexical_cast.qbk
==============================================================================
--- trunk/libs/conversion/doc/lexical_cast.qbk (original)
+++ trunk/libs/conversion/doc/lexical_cast.qbk 2011-12-25 13:55:33 EST (Sun, 25 Dec 2011)
@@ -172,7 +172,7 @@
[section Changes]
* [*boost 1.49.0 :]
- * Added code to work with typedefed wchar_t (compilation flag /Zc:wchar_t- for Visual Studio).
+ * Restored work with typedefed wchar_t (compilation flag /Zc:wchar_t- for Visual Studio).
* [*boost 1.48.0 :]
Modified: trunk/libs/conversion/test/lexical_cast_empty_input_test.cpp
==============================================================================
--- trunk/libs/conversion/test/lexical_cast_empty_input_test.cpp (original)
+++ trunk/libs/conversion/test/lexical_cast_empty_input_test.cpp 2011-12-25 13:55:33 EST (Sun, 25 Dec 2011)
@@ -22,34 +22,78 @@
using namespace boost;
-void test_empty_iterator_range()
+#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
+#define BOOST_LCAST_NO_WCHAR_T
+#endif
+
+template <class T>
+void do_test_on_empty_input(T& v)
{
- boost::iterator_range<const char*> v;
BOOST_CHECK_THROW(lexical_cast<int>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<float>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<double>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned int>(v), bad_lexical_cast);
- BOOST_CHECK_EQUAL(lexical_cast<std::string>(v), std::string());
BOOST_CHECK_THROW(lexical_cast<unsigned short>(v), bad_lexical_cast);
+#if defined(BOOST_HAS_LONG_LONG)
+ BOOST_CHECK_THROW(lexical_cast<boost::ulong_long_type>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<boost::long_long_type>(v), bad_lexical_cast);
+#elif defined(BOOST_HAS_MS_INT64)
+ BOOST_CHECK_THROW(lexical_cast<unsigned __int64>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<__int64>(v), bad_lexical_cast);
+#endif
+}
+
+void test_empty_iterator_range()
+{
+
+ boost::iterator_range<char*> v;
+ do_test_on_empty_input(v);
+ BOOST_CHECK_EQUAL(lexical_cast<std::string>(v), std::string());
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
+
+ boost::iterator_range<const char*> cv;
+ do_test_on_empty_input(cv);
+ BOOST_CHECK_EQUAL(lexical_cast<std::string>(cv), std::string());
+ BOOST_CHECK_THROW(lexical_cast<char>(cv), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned char>(cv), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<signed char>(cv), bad_lexical_cast);
+
+ const boost::iterator_range<const char*> ccv;
+ do_test_on_empty_input(ccv);
+ BOOST_CHECK_EQUAL(lexical_cast<std::string>(ccv), std::string());
+ BOOST_CHECK_THROW(lexical_cast<char>(ccv), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned char>(ccv), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<signed char>(ccv), bad_lexical_cast);
}
void test_empty_string()
{
std::string v;
- BOOST_CHECK_THROW(lexical_cast<int>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<float>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<double>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<unsigned int>(v), bad_lexical_cast);
- BOOST_CHECK_EQUAL(lexical_cast<std::string>(v), std::string());
- BOOST_CHECK_THROW(lexical_cast<unsigned short>(v), bad_lexical_cast);
+ do_test_on_empty_input(v);
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
+
+#ifndef BOOST_LCAST_NO_WCHAR_T
+ std::wstring vw;
+ do_test_on_empty_input(vw);
+ BOOST_CHECK_THROW(lexical_cast<wchar_t>(vw), bad_lexical_cast);
+#endif
+
+// Currently, no compiler and STL library fully support char16_t and char32_t
+//#ifndef BOOST_NO_CHAR16_T
+// std::basic_string<char16_t> v16w;
+// do_test_on_empty_input(v16w);
+// BOOST_CHECK_THROW(lexical_cast<char16_t>(v16w), bad_lexical_cast);
+//#endif
+//#ifndef BOOST_NO_CHAR32_T
+// std::basic_string<char32_t> v32w;
+// do_test_on_empty_input(v32w);
+// BOOST_CHECK_THROW(lexical_cast<char32_t>(v32w), bad_lexical_cast);
+//#endif
}
struct Escape
@@ -69,13 +113,7 @@
void test_empty_user_class()
{
Escape v("");
- BOOST_CHECK_THROW(lexical_cast<int>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<float>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<double>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<unsigned int>(v), bad_lexical_cast);
- BOOST_CHECK_EQUAL(lexical_cast<std::string>(v), std::string());
- BOOST_CHECK_THROW(lexical_cast<unsigned short>(v), bad_lexical_cast);
+ do_test_on_empty_input(v);
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
@@ -94,13 +132,7 @@
void test_empty_vector()
{
std::vector<long> v;
- BOOST_CHECK_THROW(lexical_cast<int>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<float>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<double>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<unsigned int>(v), bad_lexical_cast);
- BOOST_CHECK_EQUAL(lexical_cast<std::string>(v), std::string());
- BOOST_CHECK_THROW(lexical_cast<unsigned short>(v), bad_lexical_cast);
+ do_test_on_empty_input(v);
BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<unsigned char>(v), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<signed char>(v), bad_lexical_cast);
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