From b49b8d16b67ec6912899684b732e6367f258cfdb Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 6 Aug 2019 15:11:42 -0700 Subject: Export of internal Abseil changes -- 00c451dc81be7fe05f982b08b4ea1edc2ca2c1c5 by Abseil Team : remove a test that is currently broken on emscripten from running on emscripten. PiperOrigin-RevId: 262005667 -- 9df5f5acb65996bdb99900039a4f01a44811aa14 by CJ Johnson : Adds a layer of macro-indirection to opening up namespace absl inside a macro. This helps avoid an issue identified with the LTS inline namespaces PiperOrigin-RevId: 261990937 -- 5d40aa129cd77a1b853e5389aff7eacffe5c8204 by Gennadiy Rozental : Fix handling of new lines in flag help descriptions. If there are explicit new lines in a flag help description string, we respect it and format the usage message accordingly. PiperOrigin-RevId: 261974244 -- 4997b5a2ddb983969059470a2d2bc2416b3d785e by CJ Johnson : Import of CCTZ from GitHub. PiperOrigin-RevId: 261955031 GitOrigin-RevId: 00c451dc81be7fe05f982b08b4ea1edc2ca2c1c5 Change-Id: I5a13bfb15bba0f7b6e49c0655c57c3addfeb1c72 --- absl/flags/flag.h | 2 +- absl/flags/internal/usage.cc | 18 ++++++++++++++++-- absl/flags/internal/usage_test.cc | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) (limited to 'absl/flags') diff --git a/absl/flags/flag.h b/absl/flags/flag.h index 6c9f4876..36c771cf 100644 --- a/absl/flags/flag.h +++ b/absl/flags/flag.h @@ -217,7 +217,7 @@ void SetFlag(absl::Flag* flag, const V& v) { // global name for FLAGS_no symbol, thus preventing the possibility // of defining two flags with names foo and nofoo. #define ABSL_FLAG_IMPL(Type, name, default_value, help) \ - namespace absl {} \ + namespace absl /* block flags in namespaces */ {} \ ABSL_FLAG_IMPL_DECLARE_DEF_VAL_WRAPPER(name, Type, default_value) \ ABSL_FLAG_IMPL_DECLARE_HELP_WRAPPER(name, help) \ ABSL_CONST_INIT absl::Flag FLAGS_##name( \ diff --git a/absl/flags/internal/usage.cc b/absl/flags/internal/usage.cc index aac02db6..03048514 100644 --- a/absl/flags/internal/usage.cc +++ b/absl/flags/internal/usage.cc @@ -111,8 +111,16 @@ class FlagHelpPrettyPrinter { std::vector tokens; if (wrap_line) { - tokens = absl::StrSplit(str, absl::ByAnyChar(" \f\n\r\t\v"), - absl::SkipEmpty()); + for (auto line : absl::StrSplit(str, absl::ByAnyChar("\n\r"))) { + if (!tokens.empty()) { + // Keep line separators in the input std::string. + tokens.push_back("\n"); + } + for (auto token : + absl::StrSplit(line, absl::ByAnyChar(" \t"), absl::SkipEmpty())) { + tokens.push_back(token); + } + } } else { tokens.push_back(str); } @@ -120,6 +128,12 @@ class FlagHelpPrettyPrinter { for (auto token : tokens) { bool new_line = (line_len_ == 0); + // Respect line separators in the input std::string. + if (token == "\n") { + EndLine(); + continue; + } + // Write the token, ending the std::string first if necessary/possible. if (!new_line && (line_len_ + token.size() >= max_line_len_)) { EndLine(); diff --git a/absl/flags/internal/usage_test.cc b/absl/flags/internal/usage_test.cc index 5e5f7a84..781e1d2b 100644 --- a/absl/flags/internal/usage_test.cc +++ b/absl/flags/internal/usage_test.cc @@ -48,6 +48,14 @@ std::string AbslUnparseFlag(const UDT&) { return "UDT{}"; } ABSL_FLAG(UDT, usage_reporting_test_flag_05, {}, "usage_reporting_test_flag_05 help message"); +ABSL_FLAG( + std::string, usage_reporting_test_flag_06, {}, + "usage_reporting_test_flag_06 help message.\n" + "\n" + "Some more help.\n" + "Even more long long long long long long long long long long long long " + "help message."); + namespace { namespace flags = absl::flags_internal; @@ -173,6 +181,11 @@ TEST_F(UsageReportingTest, TestFlagsHelpHRF) { default: 1000000000000004; -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); default: UDT{}; + -usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message. + + Some more help. + Even more long long long long long long long long long long long long help + message.); default: ""; )"; std::stringstream test_buf_01; @@ -244,6 +257,11 @@ TEST_F(UsageReportingTest, TestUsageFlag_helpshort) { default: 1000000000000004; -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); default: UDT{}; + -usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message. + + Some more help. + Even more long long long long long long long long long long long long help + message.); default: ""; )"); } @@ -268,6 +286,11 @@ TEST_F(UsageReportingTest, TestUsageFlag_help) { default: 1000000000000004; -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); default: UDT{}; + -usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message. + + Some more help. + Even more long long long long long long long long long long long long help + message.); default: ""; Try --helpfull to get a list of all flags. )"); @@ -294,6 +317,11 @@ TEST_F(UsageReportingTest, TestUsageFlag_helppackage) { default: 1000000000000004; -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); default: UDT{}; + -usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message. + + Some more help. + Even more long long long long long long long long long long long long help + message.); default: ""; Try --helpfull to get a list of all flags. )"); @@ -354,6 +382,11 @@ TEST_F(UsageReportingTest, TestUsageFlag_helpon) { default: 1000000000000004; -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); default: UDT{}; + -usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message. + + Some more help. + Even more long long long long long long long long long long long long help + message.); default: ""; )"); } -- cgit v1.2.3