Jens-G commented on code in PR #3388:
URL: https://github.com/apache/thrift/pull/3388#discussion_r3075915220


##########
compiler/cpp/src/thrift/generate/t_rb_generator.cc:
##########
@@ -1211,10 +1241,42 @@ string 
t_rb_generator::rb_namespace_to_path_prefix(string rb_namespace) {
   return path_prefix;
 }
 
+bool& t_rb_generator::top_level_separator_state(t_rb_ofstream& out) {
+  if (&out == &f_types_) {
+    return types_need_separator_;
+  }
+  if (&out == &f_consts_) {
+    return consts_need_separator_;
+  }
+  if (&out == &f_service_) {
+    return service_need_separator_;
+  }
+  throw "internal error: unknown ruby output stream";
+}
+
+void t_rb_generator::maybe_separate_top_level(t_rb_ofstream& out) {
+  if (top_level_separator_state(out)) {
+    out << '\n';
+  }
+}
+
+void t_rb_generator::mark_top_level_written(t_rb_ofstream& out) {
+  top_level_separator_state(out) = true;
+}
+
 void t_rb_generator::generate_rdoc(t_rb_ofstream& out, t_doc* tdoc) {
-  if (tdoc->has_doc()) {
-    out.indent();
-    generate_docstring_comment(out, "", "# ", tdoc->get_doc(), "");
+  if (!tdoc->has_doc()) {
+    return;
+  }
+
+  stringstream docs(tdoc->get_doc(), std::ios_base::in);
+  string line;
+  while (std::getline(docs, line)) {
+    out.indent() << "#";

Review Comment:
   `std::getline()` only strips `\n`, so a CRLF-terminated blank line leaves 
`line == "\r"` -> `line.empty()` is `false` -> output becomes `# \r` —> 
reintroducing trailing whitespace.
   
   Reference: https://en.cppreference.com/w/cpp/string/basic_string/getline
   
   See also: 
   - https://cplusplus.com/forum/general/51349/
   - https://gist.github.com/josephwb/df09e3a71679461fc104
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to