|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72348 - in branches/release: boost libs/conversion libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2011-06-02 12:20:37
Author: apolukhin
Date: 2011-06-02 12:20:36 EDT (Thu, 02 Jun 2011)
New Revision: 72348
URL: http://svn.boost.org/trac/boost/changeset/72348
Log:
lexical-cast mereged from trunk r72347 (allow "C" locale grouping for other locales)
Text files modified:
branches/release/boost/lexical_cast.hpp | 28 ++++++++++++++++++++++++----
branches/release/libs/conversion/lexical_cast_test.cpp | 3 +++
branches/release/libs/conversion/test/lexical_cast_abstract_test.cpp | 2 +-
3 files changed, 28 insertions(+), 5 deletions(-)
Modified: branches/release/boost/lexical_cast.hpp
==============================================================================
--- branches/release/boost/lexical_cast.hpp (original)
+++ branches/release/boost/lexical_cast.hpp 2011-06-02 12:20:36 EDT (Thu, 02 Jun 2011)
@@ -654,6 +654,7 @@
unsigned char current_grouping = 0;
CharT const thousands_sep = np.thousands_sep();
char remained = grouping[current_grouping] - 1;
+ bool shall_we_return = true;
for(;end>=begin; --end)
{
@@ -671,12 +672,31 @@
multiplier *= 10;
--remained;
} else {
- if ( !Traits::eq(*end, thousands_sep) || begin == end ) return false;
- if (current_grouping < grouping_size-1 ) ++current_grouping;
- remained = grouping[current_grouping];
+ if ( !Traits::eq(*end, thousands_sep) ) //|| begin == end ) return false;
+ {
+ /*
+ * According to Programming languages - C++
+ * Digit grouping is checked. That is, the positions of discarded
+ * separators is examined for consistency with
+ * use_facet<numpunct<charT> >(loc ).grouping()
+ *
+ * BUT what if there is no separators at all and grouping()
+ * is not empty? Well, we have no extraced separators, so we
+ * won`t check them for consistency. This will allow us to
+ * work with "C" locale from other locales
+ */
+ shall_we_return = false;
+ break;
+ } else {
+ if ( begin == end ) return false;
+ if (current_grouping < grouping_size-1 ) ++current_grouping;
+ remained = grouping[current_grouping];
+ }
}
}
- } else
+
+ if (shall_we_return) return true;
+ }
#endif
{
while ( begin <= end )
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-06-02 12:20:36 EDT (Thu, 02 Jun 2011)
@@ -677,6 +677,9 @@
, bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( std::string("100") + np.thousands_sep() ), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<T>( np.thousands_sep() + std::string("100") ), bad_lexical_cast);
+
+ // Exception must not be thrown, when we are using no separators at all
+ BOOST_CHECK( lexical_cast<T>("10000") == static_cast<T>(10000) );
}
test_conversion_from_integral_to_integral<T>();
Modified: branches/release/libs/conversion/test/lexical_cast_abstract_test.cpp
==============================================================================
--- branches/release/libs/conversion/test/lexical_cast_abstract_test.cpp (original)
+++ branches/release/libs/conversion/test/lexical_cast_abstract_test.cpp 2011-06-02 12:20:36 EDT (Thu, 02 Jun 2011)
@@ -51,7 +51,7 @@
{
a.out(O);
return O;
-};
+}
void test_abstract()
{
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