utf8rewind  1.2.0
Cross-platform library for UTF-8 encoded text
helpers-normalization.hpp
Go to the documentation of this file.
1 #pragma once
2 
10 #include "tests-base.hpp"
11 
12 #include "utf8rewind.h"
13 
14 #define CHECK_IS_NORMALIZED(_codepoint, _nfd, _nfc, _nfkd, _nfkc, _name) { \
15  ::helpers::CheckEntry e; \
16  e.codepoint = _codepoint; \
17  e.name = _name; \
18  e.nfd = UTF8_NORMALIZATION_RESULT_ ## _nfd; \
19  e.nfc = UTF8_NORMALIZATION_RESULT_ ## _nfc; \
20  e.nfkd = UTF8_NORMALIZATION_RESULT_ ## _nfkd; \
21  e.nfkc = UTF8_NORMALIZATION_RESULT_ ## _nfkc; \
22  ::helpers::CheckEntry a; \
23  a.nfd = ::helpers::isNfd(_codepoint); \
24  a.nfc = ::helpers::isNfc(_codepoint); \
25  a.nfkd = ::helpers::isNfkd(_codepoint); \
26  a.nfkc = ::helpers::isNfkc(_codepoint); \
27  EXPECT_PRED_FORMAT2(::helpers::CompareNormalizationCheck, e, a); \
28 }
29 
30 #define CHECK_NORMALIZE_CODEPOINT(_codepoint, _decomposed, _composed, _decomposedCompatibility, _composedCompatibility, _name) { \
31  ::helpers::NormalizationEntry e; \
32  e.codepoint = _codepoint; \
33  e.name = _name; \
34  e.decomposed = _decomposed; \
35  e.composed = _composed; \
36  e.decomposedCompatibility = _decomposedCompatibility; \
37  e.composedCompatibility = _composedCompatibility; \
38  ::helpers::NormalizationEntry a; \
39  a.decomposed = helpers::nfd(_codepoint); \
40  a.composed = helpers::nfc(_codepoint); \
41  a.decomposedCompatibility = helpers::nfkd(_codepoint); \
42  a.composedCompatibility = helpers::nfkc(_codepoint); \
43  EXPECT_PRED_FORMAT2(::helpers::CompareNormalizationCodepoint, e, a); \
44 }
45 
46 #define CHECK_NORMALIZE_SEQUENCE(_sequence, _decomposed, _composed, _decomposedCompatibility, _composedCompatibility) { \
47  ::helpers::NormalizationEntry e; \
48  e.sequence = _sequence; \
49  e.decomposed = _decomposed; \
50  e.composed = _composed; \
51  e.decomposedCompatibility = _decomposedCompatibility; \
52  e.composedCompatibility = _composedCompatibility; \
53  ::helpers::NormalizationEntry a; \
54  a.decomposed = helpers::nfd(_sequence); \
55  a.composed = helpers::nfc(_sequence); \
56  a.decomposedCompatibility = helpers::nfkd(_sequence); \
57  a.composedCompatibility = helpers::nfkc(_sequence); \
58  EXPECT_PRED_FORMAT2(::helpers::CompareNormalizationSequence, e, a); \
59 }
60 
61 namespace helpers {
62 
63  std::string normalizationResult(uint8_t result);
64 
65  uint8_t isNfc(unicode_t codepoint);
66  uint8_t isNfc(const std::string& text);
67 
68  std::string nfc(unicode_t codepoint);
69  std::string nfc(const std::string& text);
70 
71  uint8_t isNfd(unicode_t codepoint);
72  uint8_t isNfd(const std::string& text);
73 
74  std::string nfd(unicode_t codepoint);
75  std::string nfd(const std::string& text);
76 
77  uint8_t isNfkc(unicode_t codepoint);
78  uint8_t isNfkc(const std::string& text);
79 
80  std::string nfkc(unicode_t codepoint);
81  std::string nfkc(const std::string& text);
82 
83  uint8_t isNfkd(unicode_t codepoint);
84  uint8_t isNfkd(const std::string& text);
85 
86  std::string nfkd(unicode_t codepoint);
87  std::string nfkd(const std::string& text);
88 
89  struct CheckEntry
90  {
91  unicode_t codepoint;
92  std::string name;
93  uint8_t nfd;
94  uint8_t nfc;
95  uint8_t nfkd;
96  uint8_t nfkc;
97  };
98 
99  ::testing::AssertionResult CompareNormalizationCheck(
100  const char* expressionExpected, const char* expressionActual,
101  const CheckEntry& entryExpected, const CheckEntry& entryActual);
102 
103  struct NormalizationEntry
104  {
105  NormalizationEntry()
106  : codepoint(0)
107  {
108  }
109 
110  unicode_t codepoint;
111  std::string sequence;
112  std::string name;
113  std::string decomposed;
114  std::string composed;
115  std::string decomposedCompatibility;
116  std::string composedCompatibility;
117  };
118 
119  ::testing::AssertionResult CompareNormalizationCodepoint(
120  const char* expressionExpected, const char* expressionActual,
121  const NormalizationEntry& entryExpected, const NormalizationEntry& entryActual);
122 
123  ::testing::AssertionResult CompareNormalizationSequence(
124  const char* expressionExpected, const char* expressionActual,
125  const NormalizationEntry& entryExpected, const NormalizationEntry& entryActual);
126 
127 };
128 
uint32_t unicode_t
Unicode codepoint.
Definition: utf8rewind.h:178
Base includes for tests.
Public interface for UTF-8 functions.