Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55615 - in sandbox/SOC/2009/unicode: boost/unicode libs/unicode/example
From: loufoque_at_[hidden]
Date: 2009-08-16 15:26:31


Author: mgaunard
Date: 2009-08-16 15:26:30 EDT (Sun, 16 Aug 2009)
New Revision: 55615
URL: http://svn.boost.org/trac/boost/changeset/55615

Log:
hangul composer
Text files modified:
   sandbox/SOC/2009/unicode/boost/unicode/hangul.hpp | 139 +++++++++++++++++++++++++++++----------
   sandbox/SOC/2009/unicode/libs/unicode/example/compose.cpp | 23 +-----
   sandbox/SOC/2009/unicode/libs/unicode/example/search.cpp | 10 +-
   3 files changed, 111 insertions(+), 61 deletions(-)

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-16 15:26:30 EDT (Sun, 16 Aug 2009)
@@ -76,7 +76,6 @@
     
 };
 
-/* TODO: implement it */
 /** \c \xmlonly<conceptname>Pipe</conceptname>\endxmlonly that
  * transforms <L, V>, <L, V, T> and <LV, T> Hangul code points sequences into the
  * LV and LVT Hangul syllables, since those compositions are not part
@@ -90,59 +89,125 @@
     
     template<typename In, typename Out>
     std::pair<In, Out> ltr(In begin, In end, Out out)
- {/*
- using namespace detail;
-
- char32 last = *begin; // copy first char
- result.append(last);
-
- for(int i=1; i<len; i++)
+ {
+ char32 ch = *begin++;
+
+ if(is_l(ch) && begin != end)
         {
- char32 ch = source.charAt(i);
-
- // 1. check to see if two current characters are L and V
- char32 LIndex = last - LBase;
- if(0 <= LIndex && LIndex < LCount)
+ char32 v = *begin;
+ if(is_v(v))
             {
- char32 VIndex = ch - VBase;
- if(0 <= VIndex && VIndex < VCount)
+ ++begin;
+ if(begin == end)
                 {
- // make syllable of form LV
- last = SBase + (LIndex * VCount + VIndex) * TCount;
- result.setCharAt(result.length()-1, last); // reset last
- continue; // discard ch
+ *out++ = combine_l_v(ch, v);
+ return std::make_pair(begin, out);
                 }
- }
-
 
- // 2. check to see if two current characters are LV and T
- char32 SIndex = last - SBase;
- if(0 <= SIndex && SIndex < SCount && (SIndex % TCount) == 0)
- {
- char32 TIndex = ch - TBase;
- if(0 < TIndex && TIndex < TCount)
+ char32 t = *begin;
+ if(is_t(t))
                 {
- // make syllable of form LVT
- last += TIndex;
- result.setCharAt(result.length()-1, last); // reset last
- continue; // discard ch
+ ++begin;
+ *out++ = combine_lv_t(combine_l_v(ch, v), t);
+ return std::make_pair(begin, out);
                 }
+
+ *out++ = combine_l_v(ch, v);
+ return std::make_pair(begin, out);
+ }
+ }
+ else if(is_lv(ch) && begin != end)
+ {
+ char32 t = *begin;
+ if(is_t(t))
+ {
+ ++begin;
+ *out++ = combine_lv_t(ch, t);
+ return std::make_pair(begin, out);
             }
- // if neither case was true, just add the character
- last = ch;
- result.append(ch);
         }
- */
- *out++ = *begin++;
+
+ *out++ = ch;
         return std::make_pair(begin, out);
     }
     
     template<typename In, typename Out>
     std::pair<In, Out> rtl(In begin, In end, Out out)
     {
- *out++ = *--end;
+ char32 ch = *--end;
+
+ if(is_t(ch) && end != begin)
+ {
+ char32 v = *--end;
+ if(is_v(v) && end != begin)
+ {
+ char32 l = *--end;
+ if(is_l(l))
+ {
+ *out++ = combine_lv_t(combine_l_v(l, v), ch);
+ return std::make_pair(end, out);
+ }
+ ++end;
+ }
+ else if(is_lv(v))
+ {
+ *out++ = combine_lv_t(v, ch);
+ return std::make_pair(end, out);
+ }
+ ++end;
+ }
+ else if(is_v(ch) && end != begin)
+ {
+ char32 l = *--end;
+ if(is_l(l))
+ {
+ *out++ = combine_l_v(l, ch);
+ return std::make_pair(end, out);
+ }
+ ++end;
+ }
+
+ *out++ = ch;
         return std::make_pair(end, out);
     }
+
+private:
+ static bool is_l(char32 ch)
+ {
+ char32 LIndex = ch - detail::LBase;
+ return 0 <= LIndex && LIndex < detail::LCount;
+ }
+
+ static bool is_v(char32 ch)
+ {
+ char32 VIndex = ch - detail::VBase;
+ return 0 <= VIndex && VIndex < detail::VCount;
+ }
+
+ static char32 combine_l_v(char32 l, char32 v)
+ {
+ char32 LIndex = l - detail::LBase;
+ char32 VIndex = v - detail::VBase;
+ return detail::SBase + (LIndex * detail::VCount + VIndex) * detail::TCount;
+ }
+
+ static bool is_lv(char32 ch)
+ {
+ char32 SIndex = ch - detail::SBase;
+ return 0 <= SIndex && SIndex < detail::SCount && (SIndex % detail::TCount) == 0;
+ }
+
+ static bool is_t(char32 ch)
+ {
+ char32 TIndex = ch - detail::TBase;
+ return 0 < TIndex && TIndex < detail::TCount;
+ }
+
+ static char32 combine_lv_t(char32 lv, char32 t)
+ {
+ char32 TIndex = lv - detail::TBase;
+ return lv + TIndex;
+ }
 };
 
 } // namespace unicode

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-16 15:26:30 EDT (Sun, 16 Aug 2009)
@@ -10,26 +10,11 @@
 #include <iterator>
 
 #include <boost/range/adaptor/reversed.hpp>
+#include <boost/assign/list_of.hpp>
 
 namespace unicode = boost::unicode;
 namespace ucd = unicode::ucd;
-
-namespace boost
-{
-
-template<typename T>
-iterator_range<T*> list_of(T& t)
-{
- return make_iterator_range(&t, &t+1);
-}
-
-template<typename T>
-iterator_range<const T*> list_of(const T& t)
-{
- return make_iterator_range(&t, &t+1);
-}
-
-}
+using boost::assign::list_of;
 
 int main()
 {
@@ -50,10 +35,10 @@
     std::cout << std::endl << std::endl;
     
     std::cout << "Canonical decomposition of U+00A8: ";
- unicode::decompose(boost::list_of(0xA8), std::ostream_iterator<boost::char32>(std::cout, " "));
+ unicode::decompose(list_of(0xA8), std::ostream_iterator<boost::char32>(std::cout, " "));
     std::cout << std::endl;
     std::cout << "Compatibility decomposition of U+00A8: ";
- unicode::decompose(boost::list_of(0xA8), std::ostream_iterator<boost::char32>(std::cout, " "), UINT_MAX);
+ unicode::decompose(list_of(0xA8), std::ostream_iterator<boost::char32>(std::cout, " "), UINT_MAX);
     std::cout << std::endl;
     std::cout << std::endl;
     

Modified: sandbox/SOC/2009/unicode/libs/unicode/example/search.cpp
==============================================================================
--- sandbox/SOC/2009/unicode/libs/unicode/example/search.cpp (original)
+++ sandbox/SOC/2009/unicode/libs/unicode/example/search.cpp 2009-08-16 15:26:30 EDT (Sun, 16 Aug 2009)
@@ -27,10 +27,10 @@
     
     // Boost.StringAlgo
     BOOST_AUTO(finder,
- /*boost::algorithm::make_boundary_finder(*/
- boost::algorithm::first_finder(s)/*,
+ boost::algorithm::make_boundary_finder(
+ boost::algorithm::first_finder(s),
             unicode::utf_grapheme_boundary()
- )*/
+ )
     );
     
     BOOST_AUTO(f, unicode::make_boundary_finder(
@@ -38,8 +38,8 @@
         unicode::utf_grapheme_boundary()
     ));
     
- BOOST_AUTO(range, f.ltr(boost::begin(foo), boost::end(foo)));
- //BOOST_AUTO(range, boost::algorithm::find(foo, finder));
+ //BOOST_AUTO(range, f.ltr(boost::begin(foo), boost::end(foo)));
+ BOOST_AUTO(range, boost::algorithm::find(foo, finder));
     
     std::cout << "[" << std::distance(boost::begin(foo), range.begin()) << ", " << std::distance(boost::begin(foo), range.end()) << "] ";
         


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