utf8rewind  1.4.0
System library for processing UTF-8 encoded text
helpers-strings.hpp
Go to the documentation of this file.
1 #pragma once
2 
10 #include "helpers-base.hpp"
11 
12 extern "C" {
13  #include "../internal/codepoint.h"
14 };
15 
16 #define EXPECT_UTF8EQ(_expected, _actual) EXPECT_PRED_FORMAT2(::helpers::CompareUtf8Strings, _expected, _actual)
17 #define EXPECT_UTF8LENGTHEQ(_expected, _actual, _length) EXPECT_PRED_FORMAT3(::helpers::CompareUtf8LengthStrings, _expected, _actual, _length)
18 #define EXPECT_OFFSETEQ(_expected, _actual, _start) EXPECT_PRED_FORMAT3(::helpers::CompareOffsets, _expected, _actual, _start)
19 #define EXPECT_MEMEQ(_expected, _actual, _size) EXPECT_PRED_FORMAT3(::helpers::CompareMemory, _expected, _actual, _size)
20 #define EXPECT_CPEQ(_expected, _actual) EXPECT_PRED_FORMAT2(::helpers::CompareCodepoints, _expected, _actual)
21 
22 #if UTF8_VERSION_GUARD(1, 4, 0)
23  #define EXPECT_GCEQ(_expectedOffset, _input, _inputSize, _flags) { \
24  ::helpers::GeneralCategoryEntry e; \
25  e.flags = _flags; \
26  e.offset = _expectedOffset; \
27  e.standard = -1; \
28  ::helpers::GeneralCategoryEntry a; \
29  a.input = _input; \
30  a.inputSize = _inputSize; \
31  a.flags = _flags; \
32  a.offset = utf8iscategory(_input, _inputSize, _flags); \
33  EXPECT_PRED_FORMAT2(::helpers::CompareGeneralCategory, e, a); \
34  }
35 
36  #define EXPECT_GC_INTEGRATION_EQ(_expectedOffset, _input, _inputSize, _flags, _function) { \
37  ::helpers::GeneralCategoryEntry e; \
38  e.flags = _flags; \
39  e.offset = _expectedOffset; \
40  unicode_t code_point; \
41  codepoint_read(_input, _inputSize, &code_point); \
42  e.standard = _function((int)code_point); \
43  e.standardName = # _function; \
44  ::helpers::GeneralCategoryEntry a; \
45  a.input = _input; \
46  a.inputSize = _inputSize; \
47  a.flags = _flags; \
48  a.offset = utf8iscategory(_input, _inputSize, _flags); \
49  EXPECT_PRED_FORMAT2(::helpers::CompareGeneralCategory, e, a); \
50  }
51 #endif
52 
53 namespace helpers {
54 
55  std::string identifiable(unicode_t codepoint);
56  std::string identifiable(unicode_t* codepoint, size_t codepointsSize);
57  std::string identifiable(const std::string& text);
58 
59  std::string utf8(unicode_t codepoint);
60  std::string utf8(unicode_t* codepoints, size_t codepointsSize);
61  std::string utf8(const std::vector<unicode_t>& codepoints);
62  std::string utf8(const std::wstring& text);
63 
64  std::vector<utf16_t> utf16(const std::string& text);
65 
66  std::vector<unicode_t> utf32(const std::string& text);
67 
68  std::wstring wide(const std::string& text);
69 
70  std::string hex(unicode_t codepoint);
71  std::string hex(unicode_t* codepoints, size_t codepointsSize);
72  std::string hex(const std::string& text);
73 
74  std::string printable(unicode_t codepoint);
75  std::string printable(unicode_t* codepoints, size_t codepointsSize);
76  std::string printable(const std::string& text);
77 
78  std::string canonicalCombiningClass(unicode_t codepoint);
79  std::string canonicalCombiningClass(unicode_t* codepoint, size_t codepointsSize);
80  std::string canonicalCombiningClass(const std::string& text);
81 
82  enum class QuickCheck
83  {
84  NFC,
85  NFD,
86  NFKC,
87  NFKD,
88  Any
89  };
90 
91  std::string quickCheck(unicode_t codepoint, QuickCheck type);
92  std::string quickCheck(unicode_t* codepoint, size_t codepointsSize, QuickCheck type);
93  std::string quickCheck(const std::string& text, QuickCheck type);
94 
95 #if UTF8_VERSION_GUARD(1, 4, 0)
96  std::string generalCategory(size_t flags);
97 #endif
98 
99  ::testing::AssertionResult CompareUtf8Strings(
100  const char* expressionExpected, const char* expressionActual,
101  const char* textExpected, const char* textActual);
102 
103  ::testing::AssertionResult CompareUtf8LengthStrings(
104  const char* expressionExpected, const char* expressionActual, const char* expressionLength,
105  const char* textExpected, const char* textActual, size_t length);
106 
107  ::testing::AssertionResult CompareOffsets(
108  const char* expressionExpected, const char* expressionActual, const char* expressionCount,
109  const char* offsetExpected, const char* offsetActual, const char* offsetStart);
110 
111  ::testing::AssertionResult CompareMemory(
112  const char* expressionExpected, const char* expressionActual, const char* expressionCount,
113  const char* memoryExpected, const char* memoryActual, size_t memorySize);
114 
115  ::testing::AssertionResult CompareCodepoints(
116  const char* expressionExpected, const char* expressionActual,
117  unicode_t codepointExpected, unicode_t codepointActual);
118 
119 #if UTF8_VERSION_GUARD(1, 4, 0)
120  struct GeneralCategoryEntry
121  {
122  const char* input;
123  size_t inputSize;
124  size_t flags;
125  size_t offset;
126  int standard;
127  std::string standardName;
128  };
129 
130  ::testing::AssertionResult CompareGeneralCategory(
131  const char* expressionExpected, const char* expressionActual,
132  const GeneralCategoryEntry& entryExpected, const GeneralCategoryEntry& entryActual);
133 #endif
134 
135 };
136 
uint32_t unicode_t
UTF-32 encoded code point.
Definition: utf8rewind.h:203
Base includes for helper methods.