Skip to content

Commit f029e3e

Browse files
committed
OSS export.
PiperOrigin-RevId: 354438896
1 parent e53c05c commit f029e3e

File tree

10 files changed

+73
-9
lines changed

10 files changed

+73
-9
lines changed

base/BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@ cc_library(
1010
"status_macros.h",
1111
],
1212
)
13+
14+
cc_library(
15+
name = "unilib",
16+
srcs = [
17+
"unilib.cc",
18+
],
19+
hdrs = [
20+
"unilib.h",
21+
],
22+
deps = [
23+
"@com_github_google_flatbuffers//:flatbuffers",
24+
"@com_google_absl//absl/strings",
25+
],
26+
)

base/unilib.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "base/unilib.h"
2+
3+
#include "flatbuffers/util.h"
4+
5+
namespace UniLib {
6+
7+
// Detects whether a string is valid UTF-8.
8+
bool IsStructurallyValid(absl::string_view str) {
9+
const char *s = &str[0];
10+
const char *const sEnd = s + str.length();
11+
while (s < sEnd) {
12+
if (flatbuffers::FromUTF8(&s) < 0) {
13+
return false;
14+
}
15+
}
16+
return true;
17+
}
18+
19+
} // namespace UniLib

base/unilib.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef THIRD_PARTY_CEL_CPP_BASE_UNILIB_H_
18+
#define THIRD_PARTY_CEL_CPP_BASE_UNILIB_H_
19+
20+
#include "absl/strings/string_view.h"
21+
22+
namespace UniLib {
23+
24+
// Detects whether a string is valid UTF-8.
25+
bool IsStructurallyValid(absl::string_view str);
26+
27+
} // namespace UniLib
28+
29+
#endif // THIRD_PARTY_CEL_CPP_BASE_UNILIB_H_

common/type.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ UnrecognizedType::UnrecognizedType(absl::string_view full_name)
7272
: string_rep_(absl::StrCat("type(\"", full_name, "\")")),
7373
hash_code_(internal::Hash(full_name)) {
7474
assert(google::protobuf::DescriptorPool::generated_pool()->FindMessageTypeByName(
75-
std.data()::string(full_name)) == nullptr);
75+
full_name.data()) == nullptr);
7676
}
7777

7878
absl::string_view UnrecognizedType::full_name() const {

eval/compiler/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ cc_test(
229229
srcs = ["resolver_test.cc"],
230230
deps = [
231231
":resolver",
232+
"//base:status_macros",
232233
"//eval/public:cel_function",
233234
"//eval/public:cel_function_registry",
234235
"//eval/public:cel_type_registry",

eval/compiler/flat_expr_builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class FlatExprVisitor : public AstVisitor {
256256
// - id: 'google.type.Expr'
257257
// - id: 'google.type', field: 'Expr'
258258
// - id: 'google', field: 'type', field: 'Expr'
259-
for (int i = 0; i < namespace_stack_.size(); i++) {
259+
for (size_t i = 0; i < namespace_stack_.size(); i++) {
260260
auto ns = namespace_stack_[i];
261261
namespace_stack_[i] = {
262262
ns.first, absl::StrCat(select_expr->field(), ".", ns.second)};

eval/compiler/resolver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ absl::optional<CelValue> Resolver::FindConstant(absl::string_view name,
9797
// Conditionally resolve fully qualified names as type values if the option
9898
// to do so is configured in the expression builder. If the type name is
9999
// not qualified, then it too may be returned as a constant value.
100-
if (resolve_qualified_type_identifiers_ || !absl::StrContains(name, '.')) {
100+
if (resolve_qualified_type_identifiers_ || !absl::StrContains(name, ".")) {
101101
auto type_value = type_registry_->FindType(name);
102102
if (type_value.has_value()) {
103103
return type_value.value();

eval/compiler/resolver_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "eval/public/cel_function_registry.h"
1010
#include "eval/public/cel_type_registry.h"
1111
#include "eval/testutil/test_message.pb.h"
12+
#include "base/status_macros.h"
1213

1314
namespace google {
1415
namespace api {

eval/public/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ cc_test(
473473
":cel_type_registry",
474474
"//eval/testutil:test_message_cc_proto",
475475
"@com_google_absl//absl/container:flat_hash_map",
476-
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto",
477476
"@com_google_googletest//:gtest_main",
477+
"@com_google_protobuf//:protobuf",
478478
],
479479
)
480480

eval/public/cel_type_registry_test.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "eval/public/cel_type_registry.h"
22

3-
#include "google/api/expr/v1alpha1/syntax.pb.h"
3+
#include "google/protobuf/any.pb.h"
44
#include "gmock/gmock.h"
55
#include "gtest/gtest.h"
66
#include "absl/container/flat_hash_map.h"
@@ -45,9 +45,9 @@ TEST(CelTypeRegistryTest, TestRegisterTypeName) {
4545

4646
TEST(CelTypeRegistryTest, TestFindDescriptorFound) {
4747
CelTypeRegistry registry;
48-
auto desc = registry.FindDescriptor("google.api.expr.Expr");
48+
auto desc = registry.FindDescriptor("google.protobuf.Any");
4949
ASSERT_TRUE(desc != nullptr);
50-
EXPECT_THAT(desc->full_name(), Eq("google.api.expr.Expr"));
50+
EXPECT_THAT(desc->full_name(), Eq("google.protobuf.Any"));
5151
}
5252

5353
TEST(CelTypeRegistryTest, TestFindDescriptorNotFound) {
@@ -66,10 +66,10 @@ TEST(CelTypeRegistryTest, TestFindTypeCoreTypeFound) {
6666

6767
TEST(CelTypeRegistryTest, TestFindTypeProtobufTypeFound) {
6868
CelTypeRegistry registry;
69-
auto type = registry.FindType("google.api.expr.Expr");
69+
auto type = registry.FindType("google.protobuf.Any");
7070
ASSERT_TRUE(type.has_value());
7171
EXPECT_TRUE(type.value().IsCelType());
72-
EXPECT_THAT(type.value().CelTypeOrDie().value(), Eq("google.api.expr.Expr"));
72+
EXPECT_THAT(type.value().CelTypeOrDie().value(), Eq("google.protobuf.Any"));
7373
}
7474

7575
TEST(CelTypeRegistryTest, TestFindTypeNotRegisteredTypeNotFound) {

0 commit comments

Comments
 (0)