diff options
author | yang-g <yangg@google.com> | 2016-04-21 09:58:23 -0700 |
---|---|---|
committer | yang-g <yangg@google.com> | 2016-04-21 09:58:23 -0700 |
commit | 6ba96de4fdfeb6db6cdec1e9532462ac7658ea09 (patch) | |
tree | 75ca5a2ef71306ee90ebb22513349dfa9d97cdcb | |
parent | d8887c061c90cf055a25cc80fc134da6e9f436ae (diff) |
make prefix configurable
-rw-r--r-- | src/compiler/generator_helpers.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/compiler/generator_helpers.h b/src/compiler/generator_helpers.h index 8aa875f959..b8cf5c1e14 100644 --- a/src/compiler/generator_helpers.h +++ b/src/compiler/generator_helpers.h @@ -237,16 +237,18 @@ inline void GetComment(const grpc::protobuf::FileDescriptor *desc, } } -// Prefix comment line with "// " and concatenate them into a string. -inline grpc::string GenerateComments(const std::vector<grpc::string> &in) { +// Add prefix and newline to each comment line and concatenate them together. +// Make sure there is a space after the prefix unless the line is empty. +inline grpc::string GenerateCommentsWithPrefix( + const std::vector<grpc::string> &in, const grpc::string &prefix) { std::ostringstream oss; for (const grpc::string &elem : in) { if (elem.empty()) { - oss << "//\n"; + oss << prefix << "\n"; } else if (elem[0] == ' ') { - oss << "//" << elem << "\n"; + oss << prefix << elem << "\n"; } else { - oss << "// " << elem << "\n"; + oss << prefix << " " << elem << "\n"; } } return oss.str(); @@ -268,7 +270,7 @@ inline grpc::string GetComments(const DescriptorType *desc, bool leading) { grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_TRAILING, &out); } - return GenerateComments(out); + return GenerateCommentsWithPrefix(out, "//"); } } // namespace grpc_generator |