Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55754 - in sandbox/SOC/2009/unicode: boost/iterator boost/unicode libs/unicode/example libs/unicode/test libs/unicode/test/iterator libs/unicode/test/unicode
From: loufoque_at_[hidden]
Date: 2009-08-24 02:43:52


Author: mgaunard
Date: 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
New Revision: 55754
URL: http://svn.boost.org/trac/boost/changeset/55754

Log:
a few tests and fixes
Added:
   sandbox/SOC/2009/unicode/libs/unicode/test/
   sandbox/SOC/2009/unicode/libs/unicode/test/Jamfile.v2 (contents, props changed)
   sandbox/SOC/2009/unicode/libs/unicode/test/iterator/
   sandbox/SOC/2009/unicode/libs/unicode/test/iterator/test_consumer.cpp (contents, props changed)
   sandbox/SOC/2009/unicode/libs/unicode/test/iterator/test_join.cpp (contents, props changed)
   sandbox/SOC/2009/unicode/libs/unicode/test/iterator/test_pipe.cpp (contents, props changed)
   sandbox/SOC/2009/unicode/libs/unicode/test/unicode/
   sandbox/SOC/2009/unicode/libs/unicode/test/unicode/range_test.hpp (contents, props changed)
   sandbox/SOC/2009/unicode/libs/unicode/test/unicode/test_compose.cpp (contents, props changed)
   sandbox/SOC/2009/unicode/libs/unicode/test/unicode/test_graphemes.cpp (contents, props changed)
   sandbox/SOC/2009/unicode/libs/unicode/test/unicode/test_utf.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2009/unicode/boost/iterator/join_iterator.hpp | 60 +++-------
   sandbox/SOC/2009/unicode/boost/unicode/cat.hpp | 214 ++++++++++++++-------------------------
   sandbox/SOC/2009/unicode/boost/unicode/hangul.hpp | 2
   sandbox/SOC/2009/unicode/boost/unicode/utf.hpp | 45 ++++++++
   sandbox/SOC/2009/unicode/boost/unicode/utf_codecs.hpp | 4
   sandbox/SOC/2009/unicode/libs/unicode/example/compose.cpp | 12 ++
   6 files changed, 161 insertions(+), 176 deletions(-)

Modified: sandbox/SOC/2009/unicode/boost/iterator/join_iterator.hpp
==============================================================================
--- sandbox/SOC/2009/unicode/boost/iterator/join_iterator.hpp (original)
+++ sandbox/SOC/2009/unicode/boost/iterator/join_iterator.hpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -24,6 +24,7 @@
 
 #include <boost/preprocessor/repetition/enum_params.hpp>
 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
 
 
@@ -93,34 +94,6 @@
         return wrapper<T, N>(t);
     }
     
- struct transform_range
- {
- template<typename>
- struct result
- {
- };
-
- template<typename R>
- struct result<transform_range(R)>
- {
- typedef iterator_range<
- typename range_iterator<const typename remove_reference<R>::type>::type
- > type;
- };
-
- template<typename Range>
- iterator_range<
- typename range_iterator<const Range>::type
- >
- operator()(const Range& r) const
- {
- return make_iterator_range(
- begin(r),
- end(r)
- );
- }
- };
-
     template<typename RangeSequence>
     struct deduce_value_type : common_type_seq<
         mpl::transform_view<
@@ -274,26 +247,26 @@
 struct join_iterator
         : iterator_facade<
                 join_iterator<Tuple>,
- typename detail::deduce_value_type<typename fusion::result_of::as_vector<typename fusion::result_of::transform<const Tuple, detail::transform_range>::type const>::type>::type,
+ typename detail::deduce_value_type<typename fusion::result_of::as_vector<Tuple>::type>::type,
                 std::bidirectional_iterator_tag,
- typename detail::deduce_reference<typename fusion::result_of::as_vector<typename fusion::result_of::transform<const Tuple, detail::transform_range>::type const>::type>::type,
- typename detail::deduce_difference_type<typename fusion::result_of::as_vector<typename fusion::result_of::transform<const Tuple, detail::transform_range>::type const>::type>::type
+ typename detail::deduce_reference<typename fusion::result_of::as_vector<Tuple>::type>::type,
+ typename detail::deduce_difference_type<typename fusion::result_of::as_vector<Tuple>::type>::type
>
 {
     join_iterator() {} // singular
     
- join_iterator(const Tuple& t_) : t(fusion::transform(t_, detail::transform_range())), v(detail::make_wrapper<0>(begin(fusion::get<0>(t))))
+ join_iterator(const Tuple& t_) : t(t_), v(detail::make_wrapper<0>(begin(fusion::get<0>(t))))
     {
     }
     
 private:
- join_iterator(const Tuple& t_, bool) : t(fusion::transform(t_, detail::transform_range())), v(detail::make_wrapper<mpl::size<FusionTuple>::value-1>(end(fusion::get<mpl::size<FusionTuple>::value-1>(t))))
+ join_iterator(const Tuple& t_, bool) : t(t_), v(detail::make_wrapper<mpl::size<FusionTuple>::value-1>(end(fusion::get<mpl::size<FusionTuple>::value-1>(t))))
     {
     }
     
     friend join_iterator<Tuple> make_join_end_iterator<Tuple>(const Tuple& tuple);
         friend class boost::iterator_core_access;
- typedef typename fusion::result_of::as_vector<typename fusion::result_of::transform<const Tuple, detail::transform_range>::type const>::type FusionTuple;
+ typedef typename fusion::result_of::as_vector<Tuple>::type FusionTuple;
     typedef typename detail::deduce_reference<FusionTuple>::type Reference;
 
         Reference dereference() const
@@ -365,15 +338,24 @@
     join_iterator< tuple<T...> >
> joined_n(const T&... n);
 #else
-#define BOOST_ITERATOR_JOIN_DEF(z, n, text) \
+#define BOOST_ITERATOR_JOIN_DEF(z, n, data) \
 template<BOOST_PP_ENUM_PARAMS(n, typename T)> \
 iterator_range< \
- join_iterator< tuple<BOOST_PP_ENUM_PARAMS(n, T)> > \
+ join_iterator< tuple<BOOST_PP_REPEAT(n, BOOST_ITERATOR_JOIN_DEF_A, ~)> > \
> joined_n(BOOST_PP_ENUM_BINARY_PARAMS(n, const T, & t)) \
 { \
- return joined(make_tuple(BOOST_PP_ENUM_PARAMS(n, t))); \
-}
-BOOST_PP_REPEAT_FROM_TO(1, 4, BOOST_ITERATOR_JOIN_DEF, ~)
+ return joined(make_tuple( \
+ BOOST_PP_REPEAT(n, BOOST_ITERATOR_JOIN_DEF_B, ~) \
+ )); \
+} \
+ /**/
+#define BOOST_ITERATOR_JOIN_DEF_A(z, n, data) \
+ BOOST_PP_COMMA_IF(n) iterator_range<typename range_iterator<const BOOST_PP_CAT(T, n)>::type> \
+ /**/
+#define BOOST_ITERATOR_JOIN_DEF_B(z, n, data) \
+ BOOST_PP_COMMA_IF(n) make_iterator_range(BOOST_PP_CAT(t, n)) \
+ /**/
+BOOST_PP_REPEAT_FROM_TO(1, 5, BOOST_ITERATOR_JOIN_DEF, ~)
 #endif
 
 } // namespace boost

Modified: sandbox/SOC/2009/unicode/boost/unicode/cat.hpp
==============================================================================
--- sandbox/SOC/2009/unicode/boost/unicode/cat.hpp (original)
+++ sandbox/SOC/2009/unicode/boost/unicode/cat.hpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -15,6 +15,12 @@
 
 #include <boost/detail/unspecified.hpp>
 
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/seq/elem.hpp>
+#include <boost/preprocessor/cat.hpp>
+
 #if defined(BOOST_UNICODE_DOXYGEN_INVOKED) || !defined(BOOST_NO_RVALUE_REFERENCES)
 /** INTERNAL ONLY */
 #define BOOST_UNICODE_FWD_2(macro) \
@@ -31,20 +37,6 @@
 {
 namespace unicode
 {
-
-namespace detail
-{
- template<typename ValueType, typename OutputIterator>
- pipe_output_iterator<
- OutputIterator,
- utf_encoder<ValueType>
- > utf_encoded_out(OutputIterator out)
- {
- return piped_output(out, utf_encoder<ValueType>());
- }
-
-} // namespace detail
-
 /** INTERNAL ONLY */
 #define BOOST_UNICODE_CAT_LIMITS_FWD(cv1, ref1, cv2, ref2) \
 /** Partitions the two input ranges into a total of four ranges,
@@ -99,141 +91,88 @@
     ); \
 }
 BOOST_UNICODE_FWD_2(BOOST_UNICODE_CAT_LIMITS_FWD)
-
-/** Concatenates two ranges of UTF code units and puts the result in \c out.
- *
- * Throws \c std::out_of_range if the input or resulting strings are not stream-safe.
- * \pre \c Range1 and \c Range2 are in Normalized Form D, have the same value type and are non-empty.
- * \post \c out is in Normalized Form D and is stream-safe. */
-template<typename Range1, typename Range2, typename OutputIterator>
-OutputIterator decomposed_concat(const Range1& range1, const Range2& range2, OutputIterator out)
-{
- tuple<
- sub_range<const Range1>,
- sub_range<const Range1>,
- sub_range<const Range2>,
- sub_range<const Range2>
- >
- t = cat_limits(range1, range2);
-
- out = copy(t.get<0>(), out);
- out = pipe(joined_n(utf_decoded(t.get<1>()), utf_decoded(t.get<2>())), combine_sorter(), detail::utf_encoded_out<typename range_value<const Range1>::type>(out)).base();
- return copy(t.get<3>(), out);
-}
 
+#ifdef BOOST_UNICODE_DOXYGEN_INVOKED
+/** INTERNAL ONLY */
+#define BOOST_UNICODE_COMPOSE_CONCAT_DEF(name, nf, pipe, n) \
 /** Concatenates two ranges of UTF code units and puts the result in \c out.
- *
- * Throws \c std::out_of_range if the input or resulting strings are not stream-safe.
- * \pre \c Range1 and \c Range2 are in Normalized Form C, have the same value type and are non-empty.
- * \post \c out is in Normalized Form C and is stream-safe. */
-template<typename Range1, typename Range2, typename OutputIterator>
-OutputIterator composed_concat(const Range1& range1, const Range2& range2, OutputIterator out, unsigned mask = BOOST_UNICODE_OPTION(ucd::decomposition_type::canonical))
-{
- tuple<
- sub_range<const Range1>,
- sub_range<const Range1>,
- sub_range<const Range2>,
- sub_range<const Range2>
- >
- t = cat_limits(range1, range2);
-
- out = copy(t.get<0>(), out);
- out = pipe(joined_n(t.get<1>(), t.get<2>()), make_piped_pipe(utf_decoder(), normalizer(mask)), detail::utf_encoded_out<typename range_value<const Range1>::type>(out)).base();
- return copy(t.get<3>(), out);
-}
+ Throws \c std::out_of_range if the input or resulting strings are not stream-safe.
+ \pre \c Range1 and \c Range2 are in Normalized Form nf, have the same value type and are non-empty.
+ \post \c out is in Normalized Form nf and is stream-safe. */ \
+template<typename Range1, typename Range2, typename OutputIterator, typename... T> \
+OutputIterator name##_concat(const Range1& range1, const Range2& range2, OutputIterator out, const T&...);
+#else
+#define BOOST_UNICODE_COMPOSE_CONCAT_DEF(name, nf, pipe, n) \
+BOOST_PP_REPEAT(BOOST_PP_INC(n), BOOST_UNICODE_COMPOSE_CONCAT_DEF_A, (name)(pipe))
+#endif
 
 /** INTERNAL ONLY */
-#define BOOST_UNICODE_DECOMPOSED_CONCATED_FWD(cv1, ref1, cv2, ref2) \
-template<typename Range1, typename Range2> \
-typename boost::detail::unspecified< \
- iterator_range< \
- join_iterator< \
- tuple< \
- sub_range<cv1 Range1>, \
- iterator_range< \
- pipe_iterator< \
- join_iterator< \
- tuple< \
- sub_range<cv1 Range1>, \
- sub_range<cv2 Range2> \
- > \
- >, \
- piped_pipe< \
- utf_decoder, \
- multi_pipe< \
- combine_sorter, \
- utf_encoder<typename range_value<cv1 Range1>::type> \
- > \
- > \
- > \
- >, \
- sub_range<cv1 Range2> \
- > \
- > \
- > \
->::type decomposed_concated(cv1 Range1 ref1 range1, cv2 Range2 ref2 range2) \
+#define BOOST_UNICODE_COMPOSE_CONCAT_DEF_A(z, n, seq) \
+template<typename Range1, typename Range2, typename OutputIterator BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename T)> \
+OutputIterator BOOST_PP_CAT(BOOST_PP_SEQ_ELEM(0, seq), _concat)(const Range1& range1, const Range2& range2, OutputIterator out BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, const T, & t)) \
 { \
     tuple< \
- sub_range<cv1 Range1>, \
- sub_range<cv1 Range1>, \
- sub_range<cv2 Range2>, \
- sub_range<cv2 Range2> \
+ sub_range<const Range1>, \
+ sub_range<const Range1>, \
+ sub_range<const Range2>, \
+ sub_range<const Range2> \
> \
     t = cat_limits(range1, range2); \
      \
- return joined_n( \
- t.get<0>(), \
- piped( \
- joined_n(t.get<1>(), t.get<2>()), \
- make_piped_pipe( \
- utf_decoder(), \
- make_multi_pipe( \
- combine_sorter(), \
- utf_encoder<typename range_value<cv1 Range1>::type>() \
- ) \
- ) \
- ), \
- t.get<3>() \
- ); \
+ out = copy(t.get<0>(), out); \
+ out = pipe(joined_n(t.get<1>(), t.get<2>()), make_piped_pipe(utf_decoder(), BOOST_PP_SEQ_ELEM(1, seq)(BOOST_PP_ENUM_PARAMS(n, t))), utf_encoded_out<typename range_value<const Range1>::type>(out)).base(); \
+ return copy(t.get<3>(), out); \
 }
-BOOST_UNICODE_FWD_2(BOOST_UNICODE_DECOMPOSED_CONCATED_FWD)
 
+#ifdef BOOST_UNICODE_DOXYGEN_INVOKED
 /** INTERNAL ONLY */
-#define BOOST_UNICODE_COMPOSED_CONCATED_FWD(cv1, ref1, cv2, ref2) \
-template<typename Range1, typename Range2> \
-typename boost::detail::unspecified< \
- iterator_range< \
- join_iterator< \
- tuple< \
- sub_range<cv1 Range1>, \
- iterator_range< \
- pipe_iterator< \
- join_iterator< \
- tuple< \
- sub_range<cv1 Range1>, \
- sub_range<cv2 Range2> \
- > \
- >, \
- piped_pipe< \
- utf_decoder, \
- multi_pipe< \
- normalizer, \
- utf_encoder<typename range_value<cv1 Range1>::type> \
- > \
+#define BOOST_UNICODE_COMPOSE_CONCATED_DEF(name, nf, pipe, n) \
+/** Concatenates two ranges of UTF code units and returns the result as a lazily
+ evaluated range.
+ Throws \c std::out_of_range if the input or resulting strings are not stream-safe.
+ \pre \c Range1 and \c Range2 are in Normalized Form nf, have the same value type and are non-empty.
+ \return Lazy stream-safe range in Normalized Form nf. */ \
+template<typename Range1, typename Range2, typename... T> \
+detail::unspecified<void> name##_concated(const Range1& range1, const Range2& range2, const T&...);
+#else
+#define BOOST_UNICODE_COMPOSE_CONCATED_DEF(name, nf, pipe, n) \
+BOOST_PP_REPEAT(BOOST_PP_INC(n), BOOST_UNICODE_COMPOSE_CONCATED_DEF_A, (name)(pipe))
+#endif
+
+/** INTERNAL ONLY */
+#define BOOST_UNICODE_COMPOSE_CONCATED_DEF_A(z, n, seq) \
+template<typename Range1, typename Range2 BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename T)> \
+iterator_range< \
+ join_iterator< \
+ tuple< \
+ iterator_range<typename range_iterator<const Range1>::type>, \
+ iterator_range< \
+ pipe_iterator< \
+ join_iterator< \
+ tuple< \
+ iterator_range<typename range_iterator<const Range1>::type>, \
+ iterator_range<typename range_iterator<const Range2>::type> \
+ > \
+ >, \
+ piped_pipe< \
+ utf_decoder, \
+ multi_pipe< \
+ BOOST_PP_SEQ_ELEM(1, seq), \
+ utf_encoder<typename range_value<const Range1>::type> \
> \
> \
- >, \
- sub_range<cv1 Range2> \
- > \
+ > \
+ >, \
+ iterator_range<typename range_iterator<const Range2>::type> \
> \
> \
->::type composed_concated(cv1 Range1 ref1 range1, cv2 Range2 ref2 range2, unsigned mask = BOOST_UNICODE_OPTION(ucd::decomposition_type::canonical)) \
+> BOOST_PP_CAT(BOOST_PP_SEQ_ELEM(0, seq), _concated)(const Range1& range1, const Range2& range2 BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, const T, & t)) \
 { \
     tuple< \
- sub_range<cv1 Range1>, \
- sub_range<cv1 Range1>, \
- sub_range<cv2 Range2>, \
- sub_range<cv2 Range2> \
+ sub_range<const Range1>, \
+ sub_range<const Range1>, \
+ sub_range<const Range2>, \
+ sub_range<const Range2> \
> \
     t = cat_limits(range1, range2); \
      \
@@ -244,15 +183,22 @@
             make_piped_pipe( \
                 utf_decoder(), \
                 make_multi_pipe( \
- normalizer(mask), \
- utf_encoder<typename range_value<cv1 Range1>::type>() \
+ BOOST_PP_SEQ_ELEM(1, seq)(BOOST_PP_ENUM_PARAMS(n, t)), \
+ utf_encoder<typename range_value<const Range1>::type>() \
                 ) \
             ) \
         ), \
         t.get<3>() \
     ); \
 }
-BOOST_UNICODE_FWD_2(BOOST_UNICODE_COMPOSED_CONCATED_FWD)
+
+/** INTERNAL ONLY */
+#define BOOST_UNICODE_COMPOSE_CAT_DEF(name, nf, pipe, n) \
+BOOST_UNICODE_COMPOSE_CONCATED_DEF(name, nf, pipe, n) \
+BOOST_UNICODE_COMPOSE_CONCAT_DEF(name, nf, pipe, n)
+
+BOOST_UNICODE_COMPOSE_CAT_DEF(composed, C, normalizer, 1)
+BOOST_UNICODE_COMPOSE_CAT_DEF(decomposed, D, combine_sorter, 0)
 
     
 } // namespace unicode

Modified: sandbox/SOC/2009/unicode/boost/unicode/hangul.hpp
==============================================================================
--- sandbox/SOC/2009/unicode/boost/unicode/hangul.hpp (original)
+++ sandbox/SOC/2009/unicode/boost/unicode/hangul.hpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -206,7 +206,7 @@
 
     static char32 combine_lv_t(char32 lv, char32 t)
     {
- char32 TIndex = lv - detail::TBase;
+ char32 TIndex = t - detail::TBase;
         return lv + TIndex;
     }
 };

Modified: sandbox/SOC/2009/unicode/boost/unicode/utf.hpp
==============================================================================
--- sandbox/SOC/2009/unicode/boost/unicode/utf.hpp (original)
+++ sandbox/SOC/2009/unicode/boost/unicode/utf.hpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -6,6 +6,7 @@
 #include <boost/iterator/consumer_iterator.hpp>
 
 #include <boost/unicode/pipe_def.hpp>
+#include <boost/detail/unspecified.hpp>
 
 namespace boost
 {
@@ -67,6 +68,50 @@
 
 BOOST_UNICODE_DECODER_DEF(utf)
 
+template<typename ValueType, typename Range, typename OutputIterator>
+OutputIterator utf_encode(const Range& range, OutputIterator out)
+{
+ return pipe(range, utf_encoder<ValueType>(), out);
+}
+
+#ifdef BOOST_UNICODE_DOXYGEN_INVOKED
+template<typename ValueType, typename Range>
+detail::unspecified<void> utf_encoded(Range&& range);
+#else
+template<typename ValueType, typename Range>
+iterator_range<
+ pipe_iterator<
+ typename range_iterator<const Range>::type,
+ utf_encoder<ValueType>
+ >
+> utf_encoded(const Range& range)
+{
+ return piped(range, utf_encoder<ValueType>());
+}
+
+template<typename ValueType, typename Range>
+iterator_range<
+ pipe_iterator<
+ typename range_iterator<Range>::type,
+ utf_encoder<ValueType>
+ >
+> utf_encoded(Range& range)
+{
+ return piped(range, utf_encoder<ValueType>());
+}
+#endif
+
+template<typename ValueType, typename OutputIterator>
+typename boost::detail::unspecified<
+ pipe_output_iterator<
+ OutputIterator,
+ utf_encoder<ValueType>
+ >
+>::type utf_encoded_out(OutputIterator out)
+{
+ return piped_output(out, utf_encoder<ValueType>());
+}
+
 BOOST_UNICODE_ENCODER_DEF(latin1);
 
 } // namespace unicode

Modified: sandbox/SOC/2009/unicode/boost/unicode/utf_codecs.hpp
==============================================================================
--- sandbox/SOC/2009/unicode/boost/unicode/utf_codecs.hpp (original)
+++ sandbox/SOC/2009/unicode/boost/unicode/utf_codecs.hpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -461,8 +461,8 @@
 } // namespace detail
 
 /** Model of \c \xmlonly<conceptname>OneManyPipe</conceptname>\endxmlonly,
- * either behaves like \c u16_encoder, a \c u8_encoder depending on the
- * targeted element type \c ValueType. */
+ * either behaves like \c u16_encoder, \c u8_encoder or nothing
+ * depending on the targeted element type \c ValueType. */
 template<typename ValueType>
 struct utf_encoder : detail::select_encoder<ValueType>::type
 {

Modified: sandbox/SOC/2009/unicode/libs/unicode/example/compose.cpp
==============================================================================
--- sandbox/SOC/2009/unicode/libs/unicode/example/compose.cpp (original)
+++ sandbox/SOC/2009/unicode/libs/unicode/example/compose.cpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -82,5 +82,17 @@
     std::cout << std::endl;
     
     std::cout << unicode::composed_concated(tmp, tmp2) << std::endl;
+
+ std::cout << "0xAC00: ";
+ unicode::decompose(list_of<char32>(0xAC00), std::ostream_iterator<boost::char32>(std::cout, " "));
+ std::cout << std::endl;
+
+ std::cout << "0xAC01: ";
+ unicode::decompose(list_of<char32>(0xAC01), std::ostream_iterator<boost::char32>(std::cout, " "));
+ std::cout << std::endl;
+
+ std::cout << "Composing 0x1100 0x1161 0x11a8: ";
+ unicode::compose(list_of<char32>(0x1100)(0x1161)(0x11a8), std::ostream_iterator<char32>(std::cout, " "));
+ std::cout << std::endl;
 }
 //]

Added: sandbox/SOC/2009/unicode/libs/unicode/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/unicode/libs/unicode/test/Jamfile.v2 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -0,0 +1,34 @@
+#==============================================================================
+# Copyright (c) 2009 Mathias Gaunard
+#
+# Use, modification and distribution is subject to the Boost Software
+# License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+#==============================================================================
+
+import testing ;
+
+project
+ : requirements
+ <include>../../..
+ <include>$(BOOST_ROOT)
+ <define>BOOST_ALL_NO_LIB=1
+ <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
+ <toolset>gcc:<cxxflags>-Wno-multichar
+ <library>../build//boost_unicode/
+ <link>shared:<define>BOOST_UNICODE_DYN_LINK=1
+ ;
+
+test-suite iterator :
+ [ run iterator/test_pipe.cpp ]
+ [ run iterator/test_consumer.cpp ]
+ [ run iterator/test_join.cpp ]
+;
+
+test-suite unicode :
+ [ run unicode/test_compose.cpp ]
+ [ run unicode/test_graphemes.cpp ]
+ [ run unicode/test_utf.cpp ]
+;
+
+test-suite example : ../example//unicode-examples ;

Added: sandbox/SOC/2009/unicode/libs/unicode/test/iterator/test_consumer.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/unicode/libs/unicode/test/iterator/test_consumer.cpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -0,0 +1,118 @@
+#define BOOST_TEST_MODULE Consumer
+#include <boost/test/included/unit_test.hpp>
+#include <boost/test/test_case_template.hpp>
+#include <boost/mpl/list.hpp>
+
+#include <boost/iterator/consumer_iterator.hpp>
+#include <boost/range/distance.hpp>
+
+#include <boost/assert.hpp>
+
+#include <vector>
+#include <list>
+#include <iterator>
+
+struct increasing_consumer
+{
+ typedef int input_type;
+
+ increasing_consumer() : count(1)
+ {
+ }
+
+ template<typename In>
+ In ltr(In begin, In end)
+ {
+ BOOST_ASSERT(std::distance(begin, end) >= count);
+
+ for(int i=0; i<count; i++)
+ ++begin;
+
+ if(begin != end)
+ ++count;
+ return begin;
+ }
+
+ template<typename In>
+ In rtl(In begin, In end)
+ {
+ BOOST_ASSERT(std::distance(begin, end) >= count);
+
+ for(int i=0; i<count; i++)
+ --end;
+
+ if(end != begin)
+ --count;
+ return end;
+ }
+
+ int count;
+};
+
+template<typename Range>
+void check_increasing_sequence(const Range& range, int acc)
+{
+ for(
+ typename boost::range_iterator<
+ const Range
+ >::type it = boost::begin(range);
+ it != boost::end(range);
+ ++it, ++acc
+ )
+ BOOST_CHECK_EQUAL(*it, acc);
+
+}
+
+BOOST_AUTO_TEST_CASE( increasing_test )
+{
+ using boost::consumer_iterator;
+ using boost::make_consumer_iterator;
+
+ int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+
+ consumer_iterator<int*, increasing_consumer> begin =
+ make_consumer_iterator(data, data + sizeof data / sizeof data[0], data, increasing_consumer());
+
+ consumer_iterator<int*, increasing_consumer> end =
+ make_consumer_iterator(data, data + sizeof data / sizeof data[0], data + sizeof data / sizeof data[0], increasing_consumer());
+
+ int count = 1;
+ int acc = count;
+ consumer_iterator<int*, increasing_consumer> it = begin;
+ for(; it != end; ++it, acc += count, ++count)
+ {
+ BOOST_CHECK_EQUAL(boost::distance(*it), count);
+ check_increasing_sequence(*it, acc);
+ }
+
+ --it;
+ --count;
+ acc -= count;
+ for(;;)
+ {
+ BOOST_CHECK_EQUAL(boost::distance(*it), count);
+ check_increasing_sequence(*it, acc);
+
+ if(it == begin)
+ break;
+
+ --it;
+ --count;
+ acc -= count;
+ }
+}
+
+typedef boost::mpl::list<
+ int*,
+ const int*,
+ std::vector<int>::iterator,
+ std::list<int>::iterator,
+ std::istream_iterator<char, char>
+> instantiate_types;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( instantiate, T, instantiate_types )
+{
+ boost::consumer_iterator<T, increasing_consumer>();
+}
+
+

Added: sandbox/SOC/2009/unicode/libs/unicode/test/iterator/test_join.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/unicode/libs/unicode/test/iterator/test_join.cpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -0,0 +1,43 @@
+#define BOOST_TEST_MODULE Join
+#include <boost/test/included/unit_test.hpp>
+#include <boost/test/test_case_template.hpp>
+#include <boost/mpl/list.hpp>
+
+#include <boost/iterator/join_iterator.hpp>
+#include <boost/range/as_array.hpp>
+
+#include "../unicode/range_test.hpp"
+
+BOOST_AUTO_TEST_CASE ( join )
+{
+ int one[] = {1, 2, 3, 4};
+ std::vector<int> two;
+ two.push_back(5); two.push_back(6);
+ std::list<int> three;
+ three.push_back(7); three.push_back(8); three.push_back(9);
+ int four = 10;
+
+ int sum[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+
+ CHECK_BI_EQUALS(
+ boost::joined_n(
+ boost::as_array(one),
+ two,
+ three,
+ boost::make_iterator_range(&four, &four + 1)
+ ),
+ sum
+ );
+}
+
+typedef boost::mpl::list<
+ int*,
+ const int*,
+ std::vector<int>::iterator,
+ std::list<int>::iterator,
+ std::istream_iterator<char, char>
+> instantiate_types;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( instantiate, T, instantiate_types )
+{
+}

Added: sandbox/SOC/2009/unicode/libs/unicode/test/iterator/test_pipe.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/unicode/libs/unicode/test/iterator/test_pipe.cpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -0,0 +1,97 @@
+#define BOOST_TEST_MODULE Pipe
+#include <boost/test/included/unit_test.hpp>
+#include <boost/test/test_case_template.hpp>
+#include <boost/mpl/list.hpp>
+
+#include <boost/iterator/pipe_iterator.hpp>
+#include <boost/range/distance.hpp>
+
+#include <boost/assert.hpp>
+
+#include <vector>
+#include <list>
+#include <iterator>
+
+struct increasing_pipe
+{
+ typedef int input_type;
+ typedef int output_type;
+
+ increasing_pipe() : count(1)
+ {
+ }
+
+ template<typename In, typename Out>
+ std::pair<In, Out> ltr(In begin, In end, Out out)
+ {
+ for(int i=0; i<count; i++)
+ *out++ = *begin + i;
+
+ if(++begin != end)
+ ++count;
+
+ return std::make_pair(begin, out);
+ }
+
+ template<typename In, typename Out>
+ std::pair<In, Out> rtl(In begin, In end, Out out)
+ {
+ --end;
+ for(int i=0; i<count; i++)
+ *out++ = *end + i;
+
+ if(end != begin)
+ --count;
+
+ return std::make_pair(end, out);
+ }
+
+ int count;
+};
+
+BOOST_AUTO_TEST_CASE( increasing_test )
+{
+ using boost::pipe_iterator;
+ using boost::make_pipe_iterator;
+
+ int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+
+ pipe_iterator<int*, increasing_pipe> begin =
+ make_pipe_iterator(data, data + sizeof data / sizeof data[0], data, increasing_pipe());
+
+ pipe_iterator<int*, increasing_pipe> end =
+ make_pipe_iterator(data, data + sizeof data / sizeof data[0], data + sizeof data / sizeof data[0], increasing_pipe());
+
+ pipe_iterator<int*, increasing_pipe> it = begin;
+ int count = 1;
+ for(; it != end; ++count)
+ for(int i=0; i<count; ++i, ++it)
+ BOOST_CHECK_EQUAL(*it, data[count-1]+i);
+
+
+ --it;
+ --count;
+ for(;;)
+ {
+ for(int i=count-1; i>=0; --i, --it)
+ BOOST_CHECK_EQUAL(*it, data[count-1]+i);
+
+ if(it == begin)
+ break;
+
+ --count;
+ }
+}
+
+typedef boost::mpl::list<
+ int*,
+ const int*,
+ std::vector<int>::iterator,
+ std::list<int>::iterator,
+ std::istream_iterator<char, char>
+> instantiate_types;
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( instantiate, T, instantiate_types )
+{
+ boost::pipe_iterator<T, increasing_pipe>();
+}

Added: sandbox/SOC/2009/unicode/libs/unicode/test/unicode/range_test.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/unicode/libs/unicode/test/unicode/range_test.hpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -0,0 +1,67 @@
+#ifndef BOOST_UNICODE_TEST_RANGE_TEST_HPP
+#define BOOST_UNICODE_TEST_RANGE_TEST_HPP
+
+#include <boost/range/adaptor/reversed.hpp>
+#include <boost/range/algorithm/equal.hpp>
+#include <string>
+#include <sstream>
+
+namespace detail
+{
+
+template<typename Range>
+std::string to_string(const Range& range)
+{
+ std::stringstream ss;
+ bool first = true;
+ ss << "[";
+ for(
+ typename boost::range_iterator<
+ const Range
+ >::type it = boost::begin(range);
+ it != boost::end(range);
+ ++it
+ )
+ {
+ if(first)
+ first = false;
+ else
+ ss << ", ";
+
+ ss << "0x" << std::hex << *it;
+ }
+ ss << "]";
+
+ return ss.str();
+}
+
+template<typename Range>
+boost::reverse_range<
+ const Range
+>
+reversed(const Range& range)
+{
+ return boost::make_reversed_range(range);
+}
+
+} // namespace detail
+
+#define CHECK_EQUALS(range1, range2) \
+BOOST_CHECK_MESSAGE( \
+ boost::equal(range1, range2), \
+ #range1 << " != " << #range2 << " -- (" << detail::to_string(range1) << " != " << detail::to_string(range2) << ")" \
+)
+
+/* Checking in both directions allows to make sure the right-to-left
+ * part of the pipe also works */
+#define CHECK_BI_EQUALS(range1, range2) \
+do { \
+ using detail::reversed; \
+ CHECK_EQUALS(range1, range2); \
+ CHECK_EQUALS( \
+ reversed(range1), \
+ reversed(range2) \
+ ); \
+} while(0)
+
+#endif

Added: sandbox/SOC/2009/unicode/libs/unicode/test/unicode/test_compose.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/unicode/libs/unicode/test/unicode/test_compose.cpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -0,0 +1,91 @@
+#define BOOST_TEST_MODULE Composition
+#include <boost/test/included/unit_test.hpp>
+
+#include <boost/unicode/compose.hpp>
+#include <boost/assign/list_of.hpp>
+
+#include <boost/iterator/dummy_output_iterator.hpp>
+
+#include "range_test.hpp"
+
+namespace unicode = boost::unicode;
+using boost::assign::list_of;
+using boost::char32;
+
+#define CHECK_COMP(range1, range2) \
+do { \
+ using unicode::decomposed; using unicode::composed; \
+ CHECK_BI_EQUALS(decomposed(range1), range2); \
+ CHECK_BI_EQUALS(range1, composed(range2)); \
+} while(0)
+
+BOOST_AUTO_TEST_CASE( decomposition )
+{
+ // Recursive test
+ CHECK_COMP(
+ list_of<char32>(0x1e17),
+ list_of<char32>(0x65)(0x304)(0x301)
+ );
+
+ // Canonical reordering test
+ CHECK_BI_EQUALS(
+ unicode::decomposed(list_of<char32>(0x1e17)(0x330)),
+ list_of<char32>(0x65)(0x330)(0x304)(0x301)
+ );
+
+ // Compatibility decompositions test
+ CHECK_COMP(
+ list_of<char32>(0xA8),
+ list_of<char32>(0xA8)
+ );
+
+ CHECK_BI_EQUALS(
+ unicode::decomposed(list_of<char32>(0xA8), UINT_MAX),
+ list_of<char32>(0x20)(0x308)
+ );
+}
+
+BOOST_AUTO_TEST_CASE( hangul )
+{
+ // Hangul LV
+ CHECK_COMP(
+ list_of<char32>(0xAC00),
+ list_of<char32>(0x1100)(0x1161)
+ );
+
+ // Hangul LVT
+ CHECK_COMP(
+ list_of<char32>(0xAC01),
+ list_of<char32>(0x1100)(0x1161)(0x11a8)
+ );
+}
+
+BOOST_AUTO_TEST_CASE( normalization )
+{
+ // Canonical reordering
+ CHECK_BI_EQUALS(
+ unicode::normalized(list_of<char32>(0x1e17)(0x330)),
+ list_of<char32>(0x1e1b)(0x304)(0x301)
+ );
+}
+
+BOOST_AUTO_TEST_CASE( error )
+{
+ try
+ {
+ unicode::normalize(
+ list_of<char32>(0x20)(0x330)(0x330)(0x330)(0x330)(0x330)(0x330)
+ (0x330)(0x330)(0x330)(0x330)(0x330)(0x330)(0x330)(0x330)(0x330)
+ (0x330)(0x330)(0x330)(0x330)(0x330)(0x330)(0x330)(0x330)(0x330)
+ (0x330)(0x330)(0x330)(0x330)(0x330)(0x330)(0x330),
+ boost::dummy_output_iterator()
+ );
+ }
+ catch(const std::out_of_range&)
+ {
+ return;
+ }
+
+ BOOST_CHECK(false);
+ return;
+}

Added: sandbox/SOC/2009/unicode/libs/unicode/test/unicode/test_graphemes.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/unicode/libs/unicode/test/unicode/test_graphemes.cpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -0,0 +1,26 @@
+#define BOOST_TEST_MODULE Graphemes
+#include <boost/test/included/unit_test.hpp>
+
+#include <boost/unicode/graphemes.hpp>
+
+bool is_boundary(boost::char32 lft, boost::char32 rgt)
+{
+ boost::char32 tmp[] = {lft, rgt};
+ return boost::unicode::grapheme_boundary()(tmp, tmp+2, tmp+1);
+}
+
+BOOST_AUTO_TEST_CASE( grapheme_boundary )
+{
+ BOOST_CHECK(is_boundary('a', 'b'));
+
+ BOOST_CHECK(!is_boundary('a', 0x308));
+ BOOST_CHECK(is_boundary(0x308, 'a'));
+
+ BOOST_CHECK(!is_boundary(0x308, 0x308));
+
+ BOOST_CHECK(!is_boundary('\r', '\n'));
+
+
+}
+
+

Added: sandbox/SOC/2009/unicode/libs/unicode/test/unicode/test_utf.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/unicode/libs/unicode/test/unicode/test_utf.cpp 2009-08-24 02:43:50 EDT (Mon, 24 Aug 2009)
@@ -0,0 +1,39 @@
+#define BOOST_TEST_MODULE UTF
+#include <boost/test/included/unit_test.hpp>
+
+#include <boost/unicode/utf.hpp>
+#include <boost/assign/list_of.hpp>
+
+#include "range_test.hpp"
+
+namespace unicode = boost::unicode;
+using boost::assign::list_of;
+using boost::char32;
+using boost::char16;
+
+#define CHECK_UTF(name, range1, range2) \
+do { \
+ using unicode::u##name##_encoded; using unicode::u##name##_decoded; \
+ CHECK_BI_EQUALS(u##name##_encoded(range1), range2); \
+ CHECK_BI_EQUALS(range1, u##name##_decoded(range2)); \
+} while(0)
+
+BOOST_AUTO_TEST_CASE( basic )
+{
+ char32 input[] = {'$', 0xA2, 0x20AC, 0x24B62};
+
+ CHECK_UTF(8,
+ input,
+ list_of<char>('$')(0xC2)(0xA2)(0xE2)(0x82)(0xAC)(0xF0)(0xA4)(0xAD)(0xA2)
+ );
+
+ CHECK_UTF(16,
+ input,
+ list_of<char16>('$')(0xA2)(0x20AC)(0xD852)(0xDF62)
+ );
+}
+
+BOOST_AUTO_TEST_CASE( error )
+{
+ // TODO
+}


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