我用clang-format它来自动格式化代码,在大多数情况下它可以应对爆炸,但有一段代码没有按照我们的意愿进行格式化。
从示例到库的一段代码(github 上的文件):
int main(int argc, char* argv[])
{
options.add_options()
("a,apple", "an apple", cxxopts::value<bool>(apple))
("b,bob", "Bob")
("f,file", "File", cxxopts::value<std::vector<std::string>>(), "FILE")
("i,input", "Input", cxxopts::value<std::string>())
("o,output", "Output file", cxxopts::value<std::string>()
->default_value("a.out")->implicit_value("b.def"), "BIN")
("positional",
"Positional arguments: these are the arguments that are entered "
"without an option", cxxopts::value<std::vector<std::string>>())
("long-description",
"thisisareallylongwordthattakesupthewholelineandcannotbebrokenataspace")
("help", "Print help")
("int", "An integer", cxxopts::value<int>(), "N")
("option_that_is_too_long_for_the_help", "A very long option")
;
}
变成不可读的东西:
int main(int argc, char *argv[]) {
options.add_options()("a,apple", "an apple",
cxxopts::value<bool>(apple))("b,bob", "Bob")(
"f,file", "File", cxxopts::value<std::vector<std::string>>(),
"FILE")("i,input", "Input", cxxopts::value<std::string>())(
"o,output", "Output file",
cxxopts::value<std::string>()->default_value("a.out")->implicit_value(
"b.def"),
"BIN")("positional",
"Positional arguments: these are the arguments that are entered "
"without an option",
cxxopts::value<std::vector<std::string>>())(
"long-description",
"thisisareallylongwordthattakesupthewholelineandcannotbebrokenataspace")(
"help", "Print help")("int", "An integer", cxxopts::value<int>(), "N")(
"option_that_is_too_long_for_the_help", "A very long option");
}
.clang-format:
BasedOnStyle: LLVM
IndentWidth: 2
---
Language: Cpp
Standard: Cpp11
这可以以某种方式解决吗?
一切都变得非常简单:
借助评论
您可以禁用所需代码段的格式化。