summaryrefslogtreecommitdiff
path: root/tools/streaming_proto/string_utils.cpp
diff options
context:
space:
mode:
authorYi Jin <jinyithu@google.com>2017-10-09 11:21:40 -0700
committerYi Jin <jinyithu@google.com>2017-10-11 11:04:39 -0700
commit0473f88b9f4edcef441f1a4af278146d680b076b (patch)
treed00d45b37aae3a5213ec6057ef37ead0e12efa00 /tools/streaming_proto/string_utils.cpp
parentf1dd657edf87946d98f7f9f95f464e4082306163 (diff)
Create protoc-gen-cppstream tool to auto-generate cpp proto field Ids.
It is very similiar to protoc-gen-javastream, which generates field Ids used by ProtoOutputStream.cpp to dump protobuf data. Bug: 65641021 Test: compile the streaming_proto: $ mmm -j frameworks/base/tools/streaming_proto/ and run: $ PATH=$PATH:out/host/linux-x86/bin/protoc-gen-cppstream aprotoc --cppstream_out=tmp/ frameworks/base/core/proto/android/service/procstats.proto frameworks/base/core/proto/android/util/common.proto Change-Id: I68becc80b5166455455c5df28cd698601b4a1c1d
Diffstat (limited to 'tools/streaming_proto/string_utils.cpp')
-rw-r--r--tools/streaming_proto/string_utils.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/tools/streaming_proto/string_utils.cpp b/tools/streaming_proto/string_utils.cpp
index cc738c4c108e..bd34ab7aa44d 100644
--- a/tools/streaming_proto/string_utils.cpp
+++ b/tools/streaming_proto/string_utils.cpp
@@ -3,7 +3,7 @@
#include <iostream>
namespace android {
-namespace javastream_proto {
+namespace stream_proto {
using namespace std;
@@ -89,7 +89,26 @@ replace_string(const string& str, const char replace, const char with)
return result;
}
-} // namespace javastream_proto
+vector<string>
+split(const string& str, const char delimiter)
+{
+ vector<string> result;
+ size_t base = 0, found = 0;
+ while (true) {
+ found = str.find_first_of(delimiter, base);
+ if (found != base) {
+ string part = str.substr(base, found - base);
+ if (!part.empty()) {
+ result.push_back(part);
+ }
+ }
+ if (found == str.npos) break;
+ base = found + 1;
+ }
+ return result;
+}
+
+} // namespace stream_proto
} // namespace android