diff --git a/src/google/protobuf/io/printer.cc b/src/google/protobuf/io/printer.cc index d46c009c7e..1320b71cdc 100644 --- a/src/google/protobuf/io/printer.cc +++ b/src/google/protobuf/io/printer.cc @@ -132,27 +132,22 @@ Printer::Format Printer::TokenizeFormat(absl::string_view format_string, } // We now split the remaining format string into lines and discard: - // 1. A trailing Printer-discarded comment. - // - // 2. All leading spaces to compute that line's indent. + // 1. All leading spaces to compute that line's indent. // We do not do this for the first line, so that Emit(" ") works // correctly. We do this *regardless* of whether we are processing // a raw string, because existing non-raw-string calls to cpp::Formatter // rely on this. There is a test that validates this behavior. // - // 3. Set the indent for that line to max(0, line_indent - + // 2. Set the indent for that line to max(0, line_indent - // raw_string_indent), if this is not a raw string. // - // 4. Trailing empty lines, if we know this is a raw string, except for + // 3. Trailing empty lines, if we know this is a raw string, except for // a single extra newline at the end. // // Each line is itself split into chunks along the variable delimiters, e.g. // $...$. bool is_first = true; for (absl::string_view line_text : absl::StrSplit(format_string, '\n')) { - size_t comment_index = line_text.find(options_.ignored_comment_start); - line_text = line_text.substr(0, comment_index); - size_t line_indent = 0; while (!is_first && absl::ConsumePrefix(&line_text, " ")) { ++line_indent; diff --git a/src/google/protobuf/io/printer.h b/src/google/protobuf/io/printer.h index 45698c27da..31deaa5339 100644 --- a/src/google/protobuf/io/printer.h +++ b/src/google/protobuf/io/printer.h @@ -224,17 +224,6 @@ class AnnotationProtoCollector : public AnnotationCollector { // } // }; // -// # Comments -// -// It may be desirable to place comments in a raw string that are stripped out -// before printing. The prefix for Printer-ignored comments can be configured -// in Options. By default, this is `//~`. -// -// p.Emit(R"cc( -// // Will be printed in the output. -// //~ Won't be. -// )cc"); -// // # Lookup Frames // // If many calls to Emit() use the same set of variables, they can be stored @@ -643,9 +632,6 @@ class PROTOBUF_EXPORT Printer { // to allow the Printer to emit debugging annotations in the source code // output. absl::string_view comment_start = "//"; - // The token for beginning comments that are discarded by Printer's internal - // formatter. - absl::string_view ignored_comment_start = "//~"; // The number of spaces that a single level of indentation adds by default; // this is the amount that WithIndent() increases indentation by. size_t spaces_per_indent = 2; diff --git a/src/google/protobuf/io/printer_unittest.cc b/src/google/protobuf/io/printer_unittest.cc index 754426dded..3a8fa22b09 100644 --- a/src/google/protobuf/io/printer_unittest.cc +++ b/src/google/protobuf/io/printer_unittest.cc @@ -41,12 +41,14 @@ #include "google/protobuf/descriptor.pb.h" #include +#include "google/protobuf/testing/googletest.h" #include #include "absl/container/flat_hash_map.h" #include "google/protobuf/stubs/logging.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" #include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/io/zero_copy_stream_impl_lite.h" namespace google { @@ -563,18 +565,6 @@ TEST_F(PrinterTest, EmitWithSubs) { "};\n"); } -TEST_F(PrinterTest, EmitComments) { - { - Printer printer(output()); - printer.Emit(R"cc( - // Yes. - //~ No. - )cc"); - } - - EXPECT_EQ(written(), "// Yes.\n"); -} - TEST_F(PrinterTest, EmitWithVars) { { Printer printer(output());