utf8rewind  1.4.1
System library for processing UTF-8 encoded text
helpers-casemapping.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 EXPECT_CASEMAPPING_CODEPOINT_NUL_EQ(_codepoint, _name) { \
15  ::helpers::CaseMappingEntry e; \
16  e.codepoint = _codepoint; \
17  e.lowercase = std::string(1, '\0'); \
18  e.uppercase = std::string(1, '\0'); \
19  e.titlecase = std::string(1, '\0'); \
20  e.name = _name; \
21  ::helpers::CaseMappingEntry a; \
22  std::string text = ::helpers::utf8(_codepoint); \
23  a.lowercase = ::helpers::lowercase(text); \
24  a.uppercase = ::helpers::uppercase(text); \
25  a.titlecase = ::helpers::titlecase(text); \
26  EXPECT_PRED_FORMAT2(::helpers::CompareCodepoint, e, a); \
27 }
28 
29 #define EXPECT_CASEMAPPING_CODEPOINT_EQ(_codepoint, _lowercase, _uppercase, _titlecase, _name) { \
30  ::helpers::CaseMappingEntry e; \
31  e.codepoint = _codepoint; \
32  e.lowercase = _lowercase; \
33  e.uppercase = _uppercase; \
34  e.titlecase = _titlecase; \
35  e.name = _name; \
36  ::helpers::CaseMappingEntry a; \
37  std::string text = ::helpers::utf8(_codepoint); \
38  a.lowercase = ::helpers::lowercase(text); \
39  a.uppercase = ::helpers::uppercase(text); \
40  a.titlecase = ::helpers::titlecase(text); \
41  EXPECT_PRED_FORMAT2(::helpers::CompareCodepoint, e, a); \
42 }
43 
44 #define EXPECT_CASEMAPPING_EQ(_input, _lowercase, _uppercase, _titlecase) { \
45  ::helpers::CaseMappingEntry e; \
46  e.lowercase = _lowercase; \
47  e.uppercase = _uppercase; \
48  e.titlecase = _titlecase; \
49  ::helpers::CaseMappingEntry a; \
50  a.input = _input; \
51  a.lowercase = ::helpers::lowercase(_input); \
52  a.uppercase = ::helpers::uppercase(_input); \
53  a.titlecase = ::helpers::titlecase(_input); \
54  EXPECT_PRED_FORMAT2(::helpers::CompareCaseMapping, e, a); \
55 }
56 
57 #if UTF8_VERSION_GUARD(1, 4, 0)
58  #define EXPECT_CASEFOLDING_EQ(_codepoint, _folded, _name) { \
59  ::helpers::CaseFoldingEntry e; \
60  e.codePoint = _codepoint; \
61  e.folded = _folded; \
62  e.name = _name; \
63  ::helpers::CaseFoldingEntry a; \
64  a.folded = ::helpers::casefold(::helpers::utf8(_codepoint)); \
65  EXPECT_PRED_FORMAT2(::helpers::CompareCaseFolding, e, a); \
66  }
67 #endif
68 
69 namespace helpers {
70 
71  std::string uppercase(const std::string& text);
72 
73  std::string lowercase(const std::string& text);
74 
75  std::string titlecase(const std::string& text);
76 
77 #if UTF8_VERSION_GUARD(1, 4, 0)
78  std::string casefold(const std::string& text);
79 #endif
80 
81  struct CaseMappingEntry
82  {
83  CaseMappingEntry()
84  : codepoint(0)
85  {
86  }
87 
88  unicode_t codepoint;
89  std::string name;
90  std::string input;
91  std::string lowercase;
92  std::string uppercase;
93  std::string titlecase;
94  };
95 
96  ::testing::AssertionResult CompareCodepoint(
97  const char* expressionExpected, const char* expressionActual,
98  const CaseMappingEntry& entryExpected, const CaseMappingEntry& entryActual);
99 
100  ::testing::AssertionResult CompareCaseMapping(
101  const char* expressionExpected, const char* expressionActual,
102  const CaseMappingEntry& entryExpected, const CaseMappingEntry& entryActual);
103 
104 #if UTF8_VERSION_GUARD(1, 4, 0)
105  struct CaseFoldingEntry
106  {
107  unicode_t codePoint;
108  std::string folded;
109  std::string name;
110  };
111 
112  ::testing::AssertionResult CompareCaseFolding(
113  const char* expressionExpected, const char* expressionActual,
114  const CaseFoldingEntry& entryExpected, const CaseFoldingEntry& entryActual);
115 #endif
116 
117 };
118 
uint32_t unicode_t
UTF-32 encoded code point.
Definition: utf8rewind.h:203
Base includes for helper methods.
String helper functions.