MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / FormatString

Function FormatString

extensions/formatting.cc:211–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211absl::StatusOr<absl::string_view> FormatString(
212 const Value& value,
213 const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
214 google::protobuf::MessageFactory* absl_nonnull message_factory,
215 google::protobuf::Arena* absl_nonnull arena,
216 std::string& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) {
217 switch (value.kind()) {
218 case ValueKind::kList:
219 return FormatList(value, descriptor_pool, message_factory, arena,
220 scratch);
221 case ValueKind::kMap:
222 return FormatMap(value, descriptor_pool, message_factory, arena, scratch);
223 case ValueKind::kString:
224 return value.GetString().NativeString(scratch);
225 case ValueKind::kBytes:
226 return value.GetBytes().NativeString(scratch);
227 case ValueKind::kNull:
228 return "null";
229 case ValueKind::kInt:
230 absl::StrAppend(&scratch, value.GetInt().NativeValue());
231 return scratch;
232 case ValueKind::kUint:
233 absl::StrAppend(&scratch, value.GetUint().NativeValue());
234 return scratch;
235 case ValueKind::kDouble: {
236 auto number = value.GetDouble().NativeValue();
237 if (std::isnan(number)) {
238 return "NaN";
239 }
240 if (number == std::numeric_limits<double>::infinity()) {
241 return "Infinity";
242 }
243 if (number == -std::numeric_limits<double>::infinity()) {
244 return "-Infinity";
245 }
246 absl::StrAppend(&scratch, number);
247 return scratch;
248 }
249 case ValueKind::kTimestamp:
250 absl::StrAppend(&scratch, value.DebugString());
251 return scratch;
252 case ValueKind::kDuration:
253 return FormatDuration(value, scratch);
254 case ValueKind::kBool:
255 if (value.GetBool().NativeValue()) {
256 return "true";
257 }
258 return "false";
259 case ValueKind::kType:
260 return value.GetType().name();
261 default:
262 return absl::InvalidArgumentError(absl::StrFormat(
263 "could not convert argument %s to string", value.GetTypeName()));
264 }
265}
266
267absl::StatusOr<absl::string_view> FormatDecimal(
268 const Value& value, std::string& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) {

Callers 1

FormatListFunction · 0.85

Calls 15

FormatListFunction · 0.85
FormatMapFunction · 0.85
FormatDurationFunction · 0.70
kindMethod · 0.45
GetStringMethod · 0.45
GetBytesMethod · 0.45
NativeValueMethod · 0.45
GetIntMethod · 0.45
GetUintMethod · 0.45
GetDoubleMethod · 0.45
DebugStringMethod · 0.45
GetBoolMethod · 0.45

Tested by

no test coverage detected