Fix codesmell "or with 0" in generated flags

Signed-off-by: Daniel Egger <daniel@eggers-club.de>

[edmonds: From https://github.com/protobuf-c/protobuf-c/pull/523.]

[edmonds: Adjust find string from "0 |" to "0 | ", test against `== 0`
rather than `!= std::string::npos` so that the find/erase calls are
anchored to the same portion of the string.]
This commit is contained in:
Daniel Egger 2022-09-20 10:13:35 +02:00 committed by Robert Edmonds
parent 5312647592
commit d465ae9d44

View File

@ -159,6 +159,11 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
if (oneof != NULL)
variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_ONEOF";
// Eliminate codesmell "or with 0"
if (variables["flags"].find("0 | ") == 0) {
variables["flags"].erase(0, 4);
}
printer->Print("{\n");
if (descriptor_->file()->options().has_optimize_for() &&
descriptor_->file()->options().optimize_for() ==