Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strings.format CEL extension implementation to C++. #1185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.enable_fast_builtins};
options.enable_fast_builtins,
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 @@ -196,6 +198,11 @@ struct InterpreterOptions {
//
// Currently applies to !_, @not_strictly_false, _==_, _!=_, @in
bool enable_fast_builtins = false;

// 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
57 changes: 57 additions & 0 deletions extensions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,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 @@ -578,3 +579,59 @@ 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",
"@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",
"@icu4c",
],
)

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