u5e
UnicodeTextC++Library
canonical_composition.hpp
1 #ifndef INCLUDED_U5E_CANONICAL_COMPOSITION
2 #define INCLUDED_U5E_CANONICAL_COMPOSITION
3 
4 #include <u5e/props/canonical_composition_mapping.hpp>
5 
6 namespace u5e {
7  /**
8  * \brief performs in-place canonical composition.
9  *
10  * This will return the iterator in the end position after the
11  * composition.
12  *
13  * \tparam StorageType the storage type where to apply it.
14  *
15  * Must support codepoint_begin, codepont_cbegin, codepoint_end,
16  * codepoint_cend, as well as the member types iterator and
17  * const_iterator. It is also a requirement that you should be able
18  * to write to it as you read it, which means that this must only be
19  * used in utf32 iterators, otherwise the output may race ahead of
20  * the input.
21  *
22  * \param data the object where the canonical composition will be
23  * performed.
24  *
25  * \param count return pointer for how many compositions were performed
26  */
27  template <typename StorageType>
28  typename StorageType::iterator
29  inline canonical_composition(StorageType& data, int* count) {
30  typename StorageType::iterator oi(data.codepoint_begin());
31  typename StorageType::iterator in = oi;
32  typename StorageType::iterator end(data.codepoint_end());
33 
34  int a, b, c;
35  while (in != end) {
36  //
37  // grab the codepoint in the current input iterator
38  //
39  a = *in;
40  if ((in + 1) == end) {
41  //
42  // If this is the last codepoint, it can't be composed, so we
43  // just push it to the output as-is.
44  //
45  *(oi++) = a;
46  in++;
47  } else {
48  //
49  // look ahead for the next codepoint
50  //
51  b = *(in + 1);
53  //
54  // If this is a composition, we set it as the current input
55  // iterator after advancing, because it may still be
56  // composed more.
57  //
58  *(++in) = c;
59  *count = *count + 1;
60  } else {
61  //
62  // If there is no composition, we set it in the output iterator
63  //
64  *(oi++) = a;
65  //
66  // And finally advance the input iterator.
67  //
68  in++;
69  }
70  }
71  }
72 
73  return oi;
74  };
75 }
76 
77 #endif
main u5e namespace
static bool resolve(int a, int b, int *r_composed)
StorageType::iterator canonical_composition(StorageType &data, int *count)
performs in-place canonical composition.
Derived property for canonical composition.
codepoint property handling