MCPcopy Create free account
hub / github.com/apache/trafficserver / IsValidPlainScalar

Function IsValidPlainScalar

lib/yamlcpp/src/emitterutils.cpp:155–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155bool IsValidPlainScalar(const std::string& str, FlowType::value flowType,
156 bool allowOnlyAscii) {
157 // check against null
158 if (IsNullString(str)) {
159 return false;
160 }
161
162 // check the start
163 const RegEx& start = (flowType == FlowType::Flow ? Exp::PlainScalarInFlow()
164 : Exp::PlainScalar());
165 if (!start.Matches(str)) {
166 return false;
167 }
168
169 // and check the end for plain whitespace (which can't be faithfully kept in a
170 // plain scalar)
171 if (!str.empty() && *str.rbegin() == ' ') {
172 return false;
173 }
174
175 // then check until something is disallowed
176 static const RegEx& disallowed_flow =
177 Exp::EndScalarInFlow() | (Exp::BlankOrBreak() + Exp::Comment()) |
178 Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() |
179 Exp::Tab() | Exp::Ampersand();
180 static const RegEx& disallowed_block =
181 Exp::EndScalar() | (Exp::BlankOrBreak() + Exp::Comment()) |
182 Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() |
183 Exp::Tab() | Exp::Ampersand();
184 const RegEx& disallowed =
185 flowType == FlowType::Flow ? disallowed_flow : disallowed_block;
186
187 StringCharSource buffer(str.c_str(), str.size());
188 while (buffer) {
189 if (disallowed.Matches(buffer)) {
190 return false;
191 }
192 if (allowOnlyAscii && (0x80 <= static_cast<unsigned char>(buffer[0]))) {
193 return false;
194 }
195 ++buffer;
196 }
197
198 return true;
199}
200
201bool IsValidSingleQuotedScalar(const std::string& str, bool escapeNonAscii) {
202 // TODO: check for non-printable characters?

Callers 1

ComputeStringFormatFunction · 0.85

Calls 6

IsNullStringFunction · 0.85
MatchesMethod · 0.80
CommentFunction · 0.70
emptyMethod · 0.45
c_strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected