Skip to content

Commit e5b590e

Browse files
authored
Introduce absl, not using protobuf strutil (#22)
* Introduce absl, not using protobuf strutil Signed-off-by: Lizan Zhou <[email protected]>
1 parent 4625ac6 commit e5b590e

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed

WORKSPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717

1818
load(
1919
"//:repositories.bzl",
20+
"absl_repositories",
2021
"protobuf_repositories",
2122
"googletest_repositories",
2223
"googleapis_repositories",
2324
)
2425

26+
absl_repositories()
27+
2528
protobuf_repositories()
2629

2730
googletest_repositories()

repositories.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
#
1515
################################################################################
1616
#
17+
def absl_repositories(bind=True):
18+
native.git_repository(
19+
name = "com_google_absl",
20+
commit = "99477fa9f1e89a7d8253c8aeee331864710d080c",
21+
remote = "https://github.com/abseil/abseil-cpp",
22+
)
23+
1724
def protobuf_repositories(bind=True):
1825
native.git_repository(
1926
name = "protobuf_git",

src/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ cc_library(
4242
],
4343
deps = [
4444
":protobuf",
45+
"@com_google_absl//absl/strings",
4546
],
4647
)
4748

@@ -255,5 +256,6 @@ cc_library(
255256
],
256257
deps = [
257258
"//external:protobuf",
259+
"@com_google_absl//absl/strings",
258260
],
259261
)

src/prefix_writer.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
#include <string>
2020

21-
#include "google/protobuf/stubs/stringpiece.h"
22-
#include "google/protobuf/stubs/strutil.h"
21+
#include "absl/strings/str_split.h"
2322
#include "google/protobuf/util/internal/object_writer.h"
2423

2524
namespace google {
@@ -29,7 +28,7 @@ namespace transcoding {
2928

3029
PrefixWriter::PrefixWriter(const std::string& prefix,
3130
google::protobuf::util::converter::ObjectWriter* ow)
32-
: prefix_(google::protobuf::Split(prefix, ".")),
31+
: prefix_(absl::StrSplit(prefix, ".", absl::SkipEmpty())),
3332
non_actionable_depth_(0),
3433
writer_(ow) {}
3534

src/type_helper.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
//
1717
#include "grpc_transcoding/type_helper.h"
1818

19-
#include "google/protobuf/stubs/strutil.h"
19+
#include "absl/strings/str_split.h"
20+
2021
#include "google/protobuf/type.pb.h"
2122
#include "google/protobuf/util/internal/type_info.h"
2223
#include "google/protobuf/util/type_resolver.h"
@@ -54,7 +55,7 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
5455
// TypeResolver implementation
5556
// Resolves a type url for a message type.
5657
virtual pbutil::Status ResolveMessageType(const std::string& type_url,
57-
pb::Type* type) {
58+
pb::Type* type) override {
5859
auto i = type_map_.find(type_url);
5960
if (end(type_map_) != i) {
6061
if (nullptr != type) {
@@ -137,7 +138,8 @@ pbutil::Status TypeHelper::ResolveFieldPath(
137138
const pb::Type& type, const std::string& field_path_str,
138139
std::vector<const pb::Field*>* field_path_out) const {
139140
// Split the field names & call ResolveFieldPath()
140-
const std::vector<std::string> field_names = pb::Split(field_path_str, ".");
141+
const std::vector<std::string> field_names =
142+
absl::StrSplit(field_path_str, ".", absl::SkipEmpty());
141143
return ResolveFieldPath(type, field_names, field_path_out);
142144
}
143145

test/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ cc_test(
7878
deps = [
7979
"//external:googletest_main",
8080
"//src:request_weaver",
81+
"@com_google_absl//absl/strings",
8182
],
8283
)
8384

test/request_translator_test_base.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#include <string>
2323
#include <vector>
2424

25+
#include "absl/strings/str_split.h"
26+
2527
#include "google/api/service.pb.h"
26-
#include "google/protobuf/stubs/strutil.h"
2728
#include "google/protobuf/text_format.h"
2829
#include "google/protobuf/type.pb.h"
2930
#include "google/protobuf/util/internal/type_info.h"
@@ -45,7 +46,8 @@ std::vector<const google::protobuf::Field*> ParseFieldPath(
4546
google::protobuf::util::converter::TypeInfo& type_info,
4647
const std::string& field_path_str) {
4748
// First, split the field names
48-
auto field_names = google::protobuf::Split(field_path_str, ".");
49+
std::vector<std::string> field_names =
50+
absl::StrSplit(field_path_str, ".", absl::SkipEmpty());
4951

5052
auto current_type = &type;
5153
std::vector<const google::protobuf::Field*> field_path;

test/request_weaver_test.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#include <string>
2121
#include <vector>
2222

23-
#include "google/protobuf/stubs/strutil.h"
23+
#include "absl/strings/match.h"
24+
#include "absl/strings/str_split.h"
25+
#include "absl/strings/string_view.h"
26+
2427
#include "google/protobuf/type.pb.h"
2528
#include "google/protobuf/util/internal/expecting_objectwriter.h"
2629
#include "gtest/gtest.h"
@@ -40,7 +43,8 @@ class RequestWeaverTest : public ::testing::Test {
4043
RequestWeaverTest() : mock_(), expect_(&mock_) {}
4144

4245
void Bind(std::string field_path_str, std::string value) {
43-
auto field_names = google::protobuf::Split(field_path_str, ".");
46+
std::vector<std::string> field_names =
47+
absl::StrSplit(field_path_str, ".", absl::SkipEmpty());
4448
std::vector<const Field*> field_path;
4549
for (const auto& n : field_names) {
4650
fields_.emplace_back(CreateField(n));
@@ -63,12 +67,12 @@ class RequestWeaverTest : public ::testing::Test {
6367
std::vector<RequestWeaver::BindingInfo> bindings_;
6468
std::list<Field> fields_;
6569

66-
Field CreateField(internal::string_view name) {
70+
Field CreateField(std::string name) {
6771
Field::Cardinality card;
68-
if (name.ends_with("*")) {
72+
if (absl::EndsWith(name, "*")) {
6973
// we use "*" at the end of the field name to denote a repeated field.
7074
card = Field::CARDINALITY_REPEATED;
71-
name.remove_suffix(1);
75+
name.pop_back();
7276
} else {
7377
card = Field::CARDINALITY_OPTIONAL;
7478
}

0 commit comments

Comments
 (0)