utf8rewind  1.5.1
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 utf8(unicode_t codepoint);
56  std::string utf8(unicode_t* codepoints, size_t codepointsSize);
57  std::string utf8(const std::vector<unicode_t>& codepoints);
58  std::string utf8(const std::wstring& text);
59 
60  std::vector<utf16_t> utf16(const std::string& text);
61 
62  std::vector<unicode_t> utf32(unicode_t codepoint);
63  std::vector<unicode_t> utf32(const std::string& text);
64 
65  std::wstring wide(const std::string& text);
66 
67  std::string identifiable(const std::vector<unicode_t>& codepoints);
68 
69  std::string hex(const std::string& text);
70  std::string hex(const std::wstring& text);
71 
72  std::string printable(const std::string& text);
73  std::string printable(const std::wstring& text);
74 
75  std::string canonicalCombiningClass(const std::vector<unicode_t>& codepoints);
76  std::string canonicalCombiningClassToString(uint8_t value);
77 
78  enum class QuickCheck
79  {
80  NFC,
81  NFD,
82  NFKC,
83  NFKD,
84  Any
85  };
86 
87  std::string quickCheck(const std::vector<unicode_t>& codepoints, QuickCheck type);
88  std::string quickCheckToString(uint8_t value);
89 
90 #if UTF8_VERSION_GUARD(1, 4, 0)
91  std::string generalCategory(size_t flags);
92 #endif
93 
94  ::testing::AssertionResult CompareUtf8Strings(
95  const char* expressionExpected, const char* expressionActual,
96  const char* textExpected, const char* textActual);
97 
98  ::testing::AssertionResult CompareUtf8LengthStrings(
99  const char* expressionExpected, const char* expressionActual, const char* expressionLength,
100  const char* textExpected, const char* textActual, size_t length);
101 
102  ::testing::AssertionResult CompareOffsets(
103  const char* expressionExpected, const char* expressionActual, const char* expressionCount,
104  const char* offsetExpected, const char* offsetActual, const char* offsetStart);
105 
106  ::testing::AssertionResult CompareMemory(
107  const char* expressionExpected, const char* expressionActual, const char* expressionCount,
108  const char* memoryExpected, const char* memoryActual, size_t memorySize);
109 
110  ::testing::AssertionResult CompareCodepoints(
111  const char* expressionExpected, const char* expressionActual,
112  unicode_t codepointExpected, unicode_t codepointActual);
113 
114 #if UTF8_VERSION_GUARD(1, 4, 0)
115  struct GeneralCategoryEntry
116  {
117  const char* input;
118  size_t inputSize;
119  size_t flags;
120  size_t offset;
121  int standard;
122  std::string standardName;
123  };
124 
125  ::testing::AssertionResult CompareGeneralCategory(
126  const char* expressionExpected, const char* expressionActual,
127  const GeneralCategoryEntry& entryExpected, const GeneralCategoryEntry& entryActual);
128 #endif
129 
130 };
131 
Base includes for helper methods.
uint32_t unicode_t
UTF-32 encoded code point.
Definition: utf8rewind.h:698