Skip to content

Commit

Permalink
Add strings.format CEL extension implementation to C++.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 710751468
  • Loading branch information
CEL Dev Team authored and copybara-github committed Jan 8, 2025
1 parent d393dd0 commit 5bb581f
Show file tree
Hide file tree
Showing 9 changed files with 1,607 additions and 1 deletion.
3 changes: 2 additions & 1 deletion eval/public/cel_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ cel::RuntimeOptions ConvertToRuntimeOptions(const InterpreterOptions& options) {
options.enable_lazy_bind_initialization,
options.max_recursion_depth,
options.enable_recursive_tracing,
options.use_legacy_container_builders};
options.use_legacy_container_builders,
options.locale};
}

} // namespace google::api::expr::runtime
7 changes: 7 additions & 0 deletions eval/public/cel_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_OPTIONS_H_
#define THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_OPTIONS_H_

#include <string>

#include "absl/base/attributes.h"
#include "runtime/runtime_options.h"
#include "google/protobuf/arena.h"
Expand Down Expand Up @@ -192,6 +194,11 @@ struct InterpreterOptions {
//
// Default is true for the legacy options type.
bool use_legacy_container_builders = true;

// The locale to use for string formatting.
//
// Default is en_US.
std::string locale = "en_US";
};
// LINT.ThenChange(//depot/google3/runtime/runtime_options.h)

Expand Down
58 changes: 58 additions & 0 deletions extensions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ cc_library(
srcs = ["strings.cc"],
hdrs = ["strings.h"],
deps = [
":formatting",
"//checker:type_checker_builder",
"//checker/internal:builtins_arena",
"//common:casting",
Expand Down Expand Up @@ -521,3 +522,60 @@ cc_test(
"@com_google_absl//absl/status:status_matchers",
],
)

cc_library(
name = "formatting",
srcs = ["formatting.cc"],
hdrs = ["formatting.h"],
deps = [
"//common:value",
"//common:value_kind",
"//internal:status_macros",
"//runtime:function_adapter",
"//runtime:function_registry",
"//runtime:runtime_options",
"//third_party/icu:headers",
"//third_party/icu:numbers",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/numeric:bits",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/time",
],
)

cc_test(
name = "formatting_test",
srcs = ["formatting_test.cc"],
deps = [
":formatting",
"//common:allocator",
"//common:value",
"//extensions/protobuf:runtime_adapter",
"//internal:parse_text_proto",
"//internal:testing",
"//internal:testing_descriptor_pool",
"//internal:testing_message_factory",
"//parser",
"//parser:options",
"//runtime",
"//runtime:activation",
"//runtime:runtime_builder",
"//runtime:runtime_options",
"//runtime:standard_runtime_builder_factory",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/status:status_matchers",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/time",
"@com_google_cel_spec//proto/cel/expr:syntax_cc_proto",
"@com_google_cel_spec//proto/cel/expr/conformance/proto3:test_all_types_cc_proto",
"@com_google_protobuf//:protobuf",
],
)
Loading

0 comments on commit 5bb581f

Please sign in to comment.