Om
code_point_sink.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Sink_CodePointSink_
16 
18 
19  #ifdef Om_Macro_Test_
20 
21  #ifndef Om_Macro_Precompilation_
22 
23  #include "boost/test/unit_test.hpp"
24 
25  #endif
26 
27 namespace Om {
28 
29  namespace Sink {
30 
31  BOOST_AUTO_TEST_SUITE(CodePointSinkTest)
32 
33  BOOST_AUTO_TEST_CASE(GeneralTest) {
34  typedef std::back_insert_iterator<std::string> Iterator;
35  std::string theString;
36  Iterator theIterator(theString);
37  CodePointSink<Iterator> theSink(theIterator);
38  theSink.Push(510U);
39  BOOST_CHECK_EQUAL(
40  "\xC7\xBE",
41  theString
42  );
43  theSink.Push(65U);
44  BOOST_CHECK_EQUAL(
45  (
46  "\xC7\xBE"
47  "A"
48  ),
49  theString
50  );
51  }
52 
53  BOOST_AUTO_TEST_SUITE_END()
54 
55  }
56 
57 }
58 
59  #endif
60 
61 #else
62 
63  #include "om/utf8.hpp"
64 
65 // MARK: - Om::Sink::CodePointSink
66 
67  #define Template_ \
68  template <typename ThisCodeUnitIterator>
69 
70  #define Type_ \
71  Om::Sink::CodePointSink<ThisCodeUnitIterator>
72 
73 // MARK: public (non-static)
74 
75 Template_
76 inline Type_::CodePointSink(ThisCodeUnitIterator theCodeUnitIterator):
77 thisCodeUnitIterator(theCodeUnitIterator) {}
78 
79 Template_
80 inline Type_ & Type_::operator =(CodePointSink theCodePointSink) {
81  this->Swap(theCodePointSink);
82  return *this;
83 }
84 
85 Template_
86 inline void Type_::Push(CodePoint const & theCodePoint) {
87  Utf8::encode(
88  theCodePoint,
89  thisCodeUnitIterator
90  );
91 }
92 
93 Template_
94 inline void Type_::Swap(CodePointSink & theCodePointSink) {
96  this->thisCodeUnitIterator,
97  theCodePointSink.thisCodeUnitIterator
98  );
99 }
100 
101  #undef Type_
102  #undef Template_
103 
104 // MARK: - boost::
105 
106 template <typename TheCodeUnitIterator>
107 inline void boost::swap(
110 ) {
111  theFirst.Swap(theSecond);
112 }
113 
114 #endif
A CodePoint Sink that pushes each code unit to the iterator.
void Swap(CodePointSink &)
Om header file.
The Om library.
Definition: code_point.hpp:26
boost::locale::utf::code_point CodePoint
A UTF-8 code point.
Definition: code_point.hpp:32
void swap(Om::Language::Expression &, Om::Language::Expression &)
Om header file.