Commit 86aaa72a by Gennadiy Rozental Committed by Copybara-Service

Update XML output to properly print special characters. Non printable characters…

Update XML output to properly print special characters. Non printable characters are skipped in output. All the "whitespace-like" (including \t, \r, \n) characters printed as plain space ' '.

PiperOrigin-RevId: 538479923
Change-Id: I62dff39bb21f376d00a7b9480f8f1d31d7015e45
parent 1285ca4b
......@@ -92,8 +92,16 @@ class XMLElement {
case '>':
out << "&gt;";
break;
case '\n':
case '\v':
case '\f':
case '\t':
out << " ";
break;
default:
if (IsValidXmlCharacter(static_cast<unsigned char>(c))) {
out << c;
}
break;
}
}
......@@ -102,6 +110,7 @@ class XMLElement {
}
private:
static bool IsValidXmlCharacter(unsigned char c) { return c >= 0x20; }
absl::string_view tag_;
absl::string_view txt_;
};
......
......@@ -39,6 +39,8 @@ ABSL_FLAG(double, usage_reporting_test_flag_03, 1.03,
"usage_reporting_test_flag_03 help message");
ABSL_FLAG(int64_t, usage_reporting_test_flag_04, 1000000000000004L,
"usage_reporting_test_flag_04 help message");
ABSL_FLAG(std::string, usage_reporting_test_flag_07, "\r\n\f\v\a\b\t ",
"usage_reporting_test_flag_07 help \r\n\f\v\a\b\t ");
static const char kTestUsageMessage[] = "Custom usage message";
......@@ -203,8 +205,12 @@ TEST_F(UsageReportingTest, TestFlagsHelpHRF) {
Some more help.
Even more long long long long long long long long long long long long help
message.); default: "";
message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or
path.
......@@ -267,7 +273,8 @@ TEST_F(UsageReportingTest, TestUsageFlag_helpshort) {
std::stringstream test_buf;
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
flags::HelpMode::kShort);
EXPECT_EQ(test_buf.str(),
EXPECT_EQ(
test_buf.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc:
......@@ -285,8 +292,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_helpshort) {
Some more help.
Even more long long long long long long long long long long long long help
message.); default: "";
message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or
path.
......@@ -301,7 +312,8 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_simple) {
std::stringstream test_buf;
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
flags::HelpMode::kImportant);
EXPECT_EQ(test_buf.str(),
EXPECT_EQ(
test_buf.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc:
......@@ -319,8 +331,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_simple) {
Some more help.
Even more long long long long long long long long long long long long help
message.); default: "";
message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or
path.
......@@ -361,7 +377,8 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_multiple_flag) {
std::stringstream test_buf;
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
flags::HelpMode::kMatch);
EXPECT_EQ(test_buf.str(),
EXPECT_EQ(
test_buf.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc:
......@@ -379,8 +396,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_multiple_flag) {
Some more help.
Even more long long long long long long long long long long long long help
message.); default: "";
message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or
path.
......@@ -395,7 +416,8 @@ TEST_F(UsageReportingTest, TestUsageFlag_helppackage) {
std::stringstream test_buf;
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
flags::HelpMode::kPackage);
EXPECT_EQ(test_buf.str(),
EXPECT_EQ(
test_buf.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc:
......@@ -413,8 +435,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_helppackage) {
Some more help.
Even more long long long long long long long long long long long long help
message.); default: "";
message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or
path.
......@@ -471,7 +497,8 @@ path.
std::stringstream test_buf_02;
EXPECT_EQ(flags::HandleUsageFlags(test_buf_02, kTestUsageMessage),
flags::HelpMode::kMatch);
EXPECT_EQ(test_buf_02.str(),
EXPECT_EQ(
test_buf_02.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc:
......@@ -489,8 +516,12 @@ path.
Some more help.
Even more long long long long long long long long long long long long help
message.); default: "";
message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or
path.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment