Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76233 - in branches/release: boost libs/conversion/doc libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2011-12-30 10:18:01


Author: apolukhin
Date: 2011-12-30 10:18:00 EST (Fri, 30 Dec 2011)
New Revision: 76233
URL: http://svn.boost.org/trac/boost/changeset/76233

Log:
Merge from trunk r76232
Text files modified:
   branches/release/boost/lexical_cast.hpp | 31 +++++++++-
   branches/release/libs/conversion/doc/lexical_cast.qbk | 2
   branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp | 115 ++++++++++++++++++++++++++++++++++++---
   3 files changed, 132 insertions(+), 16 deletions(-)

Modified: branches/release/boost/lexical_cast.hpp
==============================================================================
--- branches/release/boost/lexical_cast.hpp (original)
+++ branches/release/boost/lexical_cast.hpp 2011-12-30 10:18:00 EST (Fri, 30 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>
@@ -586,7 +586,7 @@
             --end;
             value = 0;
 
- if ( *end < czero || *end >= czero + 10 || begin > end)
+ if (begin > end || *end < czero || *end >= czero + 10)
                 return false;
             value = *end - czero;
             --end;
@@ -684,6 +684,7 @@
             , const CharT opening_brace, const CharT closing_brace)
         {
             using namespace std;
+ if (begin == end) return false;
             const CharT minus = lcast_char_constants<CharT>::minus;
             const CharT plus = lcast_char_constants<CharT>::plus;
             const int inifinity_size = 8;
@@ -743,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)
@@ -863,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
@@ -1183,7 +1204,7 @@
                 bool const result = !(stream << input).fail();
                 start = stringbuffer.pbase();
                 finish = stringbuffer.pptr();
- return result && (start != finish);
+ return result;
             }
 
             template <class T>
@@ -1358,6 +1379,7 @@
             template <typename Type>
             bool shr_unsigned(Type& output)
             {
+ if (start == finish) return false;
                 CharT const minus = lcast_char_constants<CharT>::minus;
                 CharT const plus = lcast_char_constants<CharT>::plus;
                 bool has_minus = false;
@@ -1392,6 +1414,7 @@
             template <typename Type>
             bool shr_signed(Type& output)
             {
+ if (start == finish) return false;
                 CharT const minus = lcast_char_constants<CharT>::minus;
                 CharT const plus = lcast_char_constants<CharT>::plus;
                 typedef BOOST_DEDUCED_TYPENAME make_unsigned<Type>::type utype;

Modified: branches/release/libs/conversion/doc/lexical_cast.qbk
==============================================================================
--- branches/release/libs/conversion/doc/lexical_cast.qbk (original)
+++ branches/release/libs/conversion/doc/lexical_cast.qbk 2011-12-30 10:18:00 EST (Fri, 30 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: branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_empty_input_test.cpp 2011-12-30 10:18:00 EST (Fri, 30 Dec 2011)
@@ -22,29 +22,120 @@
 
 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_THROW(lexical_cast<std::string>(v), bad_lexical_cast);
     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()
 {
- BOOST_CHECK_THROW(lexical_cast<int>(std::string()), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<float>(std::string()), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<double>(std::string()), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<long double>(std::string()), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<unsigned int>(std::string()), bad_lexical_cast);
- BOOST_CHECK_EQUAL(lexical_cast<std::string>(std::string()), std::string());
- BOOST_CHECK_THROW(lexical_cast<unsigned short>(std::string()), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast<char>(std::string()), bad_lexical_cast);
+ std::string v;
+ 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
+{
+ Escape(const std::string& s)
+ : str_(s)
+ {}
+
+ std::string str_;
+};
+
+inline std::ostream& operator<< (std::ostream& o, const Escape& rhs)
+{
+ return o << rhs.str_;
+}
+
+void test_empty_user_class()
+{
+ Escape v("");
+ 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);
+}
+
+namespace std {
+inline std::ostream & operator<<(std::ostream & out, const std::vector<long> & v)
+{
+ std::ostream_iterator<long> it(out);
+ std::copy(v.begin(), v.end(), it);
+ assert(out);
+ return out;
+}
+}
+
+void test_empty_vector()
+{
+ std::vector<long> v;
+ 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);
 }
 
 unit_test::test_suite *init_unit_test_suite(int, char *[])
@@ -53,6 +144,8 @@
         BOOST_TEST_SUITE("lexical_cast. Empty input unit test");
     suite->add(BOOST_TEST_CASE(&test_empty_iterator_range));
     suite->add(BOOST_TEST_CASE(&test_empty_string));
+ suite->add(BOOST_TEST_CASE(&test_empty_user_class));
+ suite->add(BOOST_TEST_CASE(&test_empty_vector));
 
     return suite;
 }


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