[pretty] include linefeeds in the pretty output

Defect Number:
    Reviewed By:
   Testing Done:
This commit is contained in:
Timothy Stack 2020-05-19 22:13:52 -07:00
parent 7a0cb4359c
commit ebd1038057
5 changed files with 26561 additions and 26519 deletions

View File

@ -229,12 +229,9 @@ bool data_scanner::tokenize(pcre_context &pc, data_token_t &token_out)
for (lpc = 0; lpc < DT_TERMINAL_MAX; lpc++) {
switch (lpc) {
case DT_QUOTED_STRING: {
pcre_input &pi = this->ds_pcre_input;
const char *str = pi.get_string();
size_t str_start, str_end;
bool found = false;
pi.pi_offset = pi.pi_next_offset;
str_end = str_start = pi.pi_offset + 1;
switch (str[pi.pi_offset]) {

File diff suppressed because it is too large Load Diff

View File

@ -174,15 +174,15 @@ bool data_scanner::tokenize2(pcre_context &pc, data_token_t &token_out)
}
IPV6ADDR/[^:a-zA-Z0-9] { RET(DT_IPV6_ADDRESS); }
"<""?"?[a-zA-Z0-9_:]+SPACE*([a-zA-Z0-9_:]+(SPACE*'='SPACE*('"'(('\\'.|[^\x00"])+)'"'|"'"(('\\'.|[^\x00'])+)"'"|[^\x00>]+)))*SPACE*("/"|"?")">" {
"<""?"?[a-zA-Z0-9_:\-]+SPACE*([a-zA-Z0-9_:\-]+(SPACE*'='SPACE*('"'(('\\'.|[^\x00"])+)'"'|"'"(('\\'.|[^\x00'])+)"'"|[^\x00>]+)))*SPACE*("/"|"?")">" {
RET(DT_XML_EMPTY_TAG);
}
"<"[a-zA-Z0-9_:]+SPACE*([a-zA-Z0-9_:]+(SPACE*"="SPACE*('"'(('\\'.|[^\x00"])+)'"'|"'"(('\\'.|[^\x00'])+)"'"|[^\x00>]+)))*SPACE*">" {
"<"[a-zA-Z0-9_:\-]+SPACE*([a-zA-Z0-9_:\-]+(SPACE*"="SPACE*('"'(('\\'.|[^\x00"])+)'"'|"'"(('\\'.|[^\x00'])+)"'"|[^\x00>]+)))*SPACE*">" {
RET(DT_XML_OPEN_TAG);
}
"</"[a-zA-Z0-9:]+SPACE*">" {
"</"[a-zA-Z0-9:\-]+SPACE*">" {
RET(DT_XML_CLOSE_TAG);
}
@ -227,7 +227,7 @@ bool data_scanner::tokenize2(pcre_context &pc, data_token_t &token_out)
RET(DT_SYMBOL);
}
("\r"?"\n"|"\n") { RET(DT_LINE); }
("\r"?"\n"|"\\n") { RET(DT_LINE); }
SPACE+ { RET(DT_WHITE); }
"." { RET(DT_DOT); }
. { RET(DT_GARBAGE); }

View File

@ -46,7 +46,7 @@ void pretty_printer::append_to(attr_line_t &al)
if (this->pp_is_xml && this->pp_line_length > 0) {
this->start_new_line();
}
this->pp_values.push_back(el);
this->pp_values.emplace_back(el);
if (this->pp_is_xml) {
this->start_new_line();
}
@ -57,7 +57,7 @@ void pretty_printer::append_to(attr_line_t &al)
this->write_element(el);
this->descend();
} else {
this->pp_values.push_back(el);
this->pp_values.emplace_back(el);
}
continue;
case DT_XML_CLOSE_TAG:
@ -70,7 +70,7 @@ void pretty_printer::append_to(attr_line_t &al)
case DT_LSQUARE:
case DT_LPAREN:
this->flush_values(true);
this->pp_values.push_back(el);
this->pp_values.emplace_back(el);
this->descend();
continue;
case DT_RCURLY:
@ -101,7 +101,7 @@ void pretty_printer::append_to(attr_line_t &al)
default:
break;
}
this->pp_values.push_back(el);
this->pp_values.emplace_back(el);
}
while (this->pp_depth > 0) {
this->ascend();
@ -128,8 +128,15 @@ void pretty_printer::write_element(const pretty_printer::element &el)
}
return;
}
if (this->pp_line_length <= this->pp_leading_indent && el.e_token == DT_LINE) {
if (((this->pp_leading_indent == 0) ||
(this->pp_line_length <= this->pp_leading_indent)) &&
el.e_token == DT_LINE) {
this->pp_soft_indent = 0;
if (this->pp_line_length > 0) {
this->pp_line_length = 0;
this->pp_stream << std::endl;
this->pp_body_lines.top() += 1;
}
return;
}
pcre_input &pi = this->pp_scanner->get_input();

View File

@ -34,9 +34,11 @@ check_output "pretty print not able to properly grok ipv4?" <<EOF
9 8.8.8.8<1054 198.51.100.1546 544.9.8.7 98.542.241.99 19143.2.5.6
EOF
cat <<EOF
cat > test_pretty_in.1 <<EOF
2015-04-18T13:16:30.003 {"wrapper": {"msg": r"Hello,\nWorld!\n"}}
EOF | run_test ${lnav_test} -n -c ":switch-to-view pretty"
EOF
run_test ${lnav_test} -n -c ":switch-to-view pretty" -d /tmp/lnav.err test_pretty_in.1
check_output "pretty print is not interpreting quoted strings correctly?" <<EOF
2015-04-18T13:16:30.003 {
@ -46,9 +48,11 @@ check_output "pretty print is not interpreting quoted strings correctly?" <<EOF
""}}
EOF
cat <<EOF
{"wrapper": [{"message":"\nselect Id from Account where id = $sfid\n ^\nERROR at Row:1:Column:34\nline 1:34 no viable alternative at character '$'"}]}
EOF | run_test ${lnav_test} -n -c ":switch-to-view pretty"
cat > test_pretty_in.2 <<EOF
{"wrapper": [{"message":"\nselect Id from Account where id = \$sfid\n ^\nERROR at Row:1:Column:34\nline 1:34 no viable alternative at character '$'"}]}
EOF
run_test ${lnav_test} -n -c ":switch-to-view pretty" test_pretty_in.2
check_output "pretty print is not including leading white space?" <<EOF
{
@ -60,3 +64,15 @@ check_output "pretty print is not including leading white space?" <<EOF
line 1:34 no viable alternative at character '\$'
""}]}
EOF
cat > test_pretty_in.3 <<EOF
Hello\\nWorld\\n
EOF
run_test ${lnav_test} -d /tmp/lnav.err -n -c ":switch-to-view pretty" test_pretty_in.3
check_output "pretty print is not including leading white space?" <<EOF
Hello
World
EOF