#include <catch_xmlwriter.h>
Definition at line 18 of file catch_xmlwriter.h.
◆ ForWhat
◆ XmlEncode()
◆ encodeTo()
void Catch::XmlEncode::encodeTo |
( |
std::ostream & | os | ) |
const |
Definition at line 61 of file catch_xmlwriter.cpp.
61 {
62
63
64
65 for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) {
67 switch (c) {
68 case '<':
os <<
"<";
break;
69 case '&':
os <<
"&";
break;
70
71 case '>':
72
73 if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']')
75 else
77 break;
78
79 case '\"':
82 else
84 break;
85
86 default:
87
88
89
90
91 if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) {
93 break;
94 }
95
96
97 if (c < 0x7F) {
99 break;
100 }
101
102
103
104
105
106
107
108 if (c < 0xC0 ||
109 c >= 0xF8) {
110 hexEscapeChar(
os, c);
111 break;
112 }
113
114 auto encBytes = trailingBytes(c);
115
116 if (idx + encBytes - 1 >= m_str.size()) {
117 hexEscapeChar(
os, c);
118 break;
119 }
120
121
122
123 bool valid = true;
125 for (std::size_t n = 1; n < encBytes; ++n) {
126 uchar nc = m_str[idx + n];
127 valid &= ((nc & 0xC0) == 0x80);
129 }
130
131 if (
132
133 (!valid) ||
134
138
140 ) {
141 hexEscapeChar(
os, c);
142 break;
143 }
144
145
146 for (std::size_t n = 0; n < encBytes; ++n) {
147 os << m_str[idx + n];
148 }
149 idx += encBytes - 1;
150 break;
151 }
152 }
153 }
◆ operator<<
std::ostream & operator<< |
( |
std::ostream & | os, |
|
|
XmlEncode const & | xmlEncode ) |
|
friend |
The documentation for this class was generated from the following files: