utf8rewind  1.4.1
System library for processing UTF-8 encoded text
helpers-normalization.hpp
Go to the documentation of this file.
1 #pragma once
2 
10 #include "helpers-base.hpp"
11 
12 #include "helpers-strings.hpp"
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  std::string text = ::helpers::utf8(_codepoint); \
24  a.nfd = ::helpers::isNfd(text); \
25  a.nfc = ::helpers::isNfc(text); \
26  a.nfkd = ::helpers::isNfkd(text); \
27  a.nfkc = ::helpers::isNfkc(text); \
28  EXPECT_PRED_FORMAT2(::helpers::CompareNormalizationCheck, e, a); \
29 }
30 
31 #define CHECK_NORMALIZE_CODEPOINT(_codepoint, _decomposed, _composed, _decomposedCompatibility, _composedCompatibility, _name) { \
32  ::helpers::NormalizationEntry e; \
33  e.codepoint = _codepoint; \
34  e.name = _name; \
35  e.decomposed = _decomposed; \
36  e.composed = _composed; \
37  e.decomposedCompatibility = _decomposedCompatibility; \
38  e.composedCompatibility = _composedCompatibility; \
39  ::helpers::NormalizationEntry a; \
40  std::string text = ::helpers::utf8(_codepoint); \
41  a.decomposed = helpers::nfd(text); \
42  a.composed = helpers::nfc(text); \
43  a.decomposedCompatibility = helpers::nfkd(text); \
44  a.composedCompatibility = helpers::nfkc(text); \
45  EXPECT_PRED_FORMAT2(::helpers::CompareNormalizationCodepoint, e, a); \
46 }
47 
48 #define CHECK_NORMALIZE_SEQUENCE(_sequence, _decomposed, _composed, _decomposedCompatibility, _composedCompatibility) { \
49  ::helpers::NormalizationEntry e; \
50  e.sequence = _sequence; \
51  e.decomposed = _decomposed; \
52  e.composed = _composed; \
53  e.decomposedCompatibility = _decomposedCompatibility; \
54  e.composedCompatibility = _composedCompatibility; \
55  ::helpers::NormalizationEntry a; \
56  a.decomposed = helpers::nfd(_sequence); \
57  a.composed = helpers::nfc(_sequence); \
58  a.decomposedCompatibility = helpers::nfkd(_sequence); \
59  a.composedCompatibility = helpers::nfkc(_sequence); \
60  EXPECT_PRED_FORMAT2(::helpers::CompareNormalizationSequence, e, a); \
61 }
62 
63 namespace helpers {
64 
65  std::string normalizationResult(uint8_t value);
66 
67  uint8_t isNfc(const std::string& text);
68  std::string nfc(const std::string& text);
69 
70  uint8_t isNfd(const std::string& text);
71  std::string nfd(const std::string& text);
72 
73  uint8_t isNfkc(const std::string& text);
74  std::string nfkc(const std::string& text);
75 
76  uint8_t isNfkd(const std::string& text);
77  std::string nfkd(const std::string& text);
78 
79  struct CheckEntry
80  {
81  unicode_t codepoint;
82  std::string name;
83  uint8_t nfd;
84  uint8_t nfc;
85  uint8_t nfkd;
86  uint8_t nfkc;
87  };
88 
89  ::testing::AssertionResult CompareNormalizationCheck(
90  const char* expressionExpected, const char* expressionActual,
91  const CheckEntry& entryExpected, const CheckEntry& entryActual);
92 
93  struct NormalizationEntry
94  {
95  NormalizationEntry()
96  : codepoint(0)
97  {
98  }
99 
100  unicode_t codepoint;
101  std::string sequence;
102  std::string name;
103  std::string decomposed;
104  std::string composed;
105  std::string decomposedCompatibility;
106  std::string composedCompatibility;
107  };
108 
109  ::testing::AssertionResult CompareNormalizationCodepoint(
110  const char* expressionExpected, const char* expressionActual,
111  const NormalizationEntry& entryExpected, const NormalizationEntry& entryActual);
112 
113  ::testing::AssertionResult CompareNormalizationSequence(
114  const char* expressionExpected, const char* expressionActual,
115  const NormalizationEntry& entryExpected, const NormalizationEntry& entryActual);
116 
117 };
118 
uint32_t unicode_t
UTF-32 encoded code point.
Definition: utf8rewind.h:203
Base includes for helper methods.
String helper functions.