[last-word] minor tweaks

pull/1265/head
Tim Stack 2 months ago
parent 45fca37323
commit d54b17c7b4

@ -1,5 +1,9 @@
## lnav v0.12.2
Features:
* Added the "last-word" line-format field shortening algorithm
from @flicus.
Bug Fixes:
* With the recent xz backdoor shenanigans, it seems like a good
time to add some checks for data being hidden by escape codes:

@ -718,7 +718,8 @@
"enum": [
"abbrev",
"truncate",
"dot-dot"
"dot-dot",
"last-word"
]
},
"text-transform": {

@ -227,8 +227,9 @@ object with the following fields:
:truncate: Truncates any text past the maximum width.
:dot-dot: Cuts out the middle of the text and replaces it with two
dots (i.e. '..').
:last-word: Removes all but the last word in dotted text. For example,
"com.example.foo" would be shortened to "foo".
:last-word: Removes all but the last word in text with dot, dash,
forward-slash, or colon separators. For example, "com.example.foo"
would be shortened to "foo".
(v0.8.2+)
:timestamp-format: The timestamp format to use when displaying the time

@ -288,6 +288,7 @@ add_library(
third-party/date/src/tz.cpp
)
target_include_directories(datepp PUBLIC third-party/date/include)
target_link_libraries(datepp ${lnav_LIBS})
add_library(
cppscnlib STATIC

@ -114,3 +114,20 @@ TEST_CASE("strnatcmp")
CHECK(ipcmp == -1);
}
}
TEST_CASE("last_word_str")
{
{
std::string s = "foobar baz";
auto rc = last_word_str(&s[0], s.length(), 6);
CHECK(s.length() == rc);
}
{
std::string s = "com.example.foo";
auto rc = last_word_str(&s[0], s.length(), 6);
s.resize(rc);
CHECK(s == "foo");
}
}

@ -2282,9 +2282,13 @@ external_log_format::get_subline(const logline& ll,
}
case json_format_element::overflow_t::
LASTWORD: {
size_t new_size = last_word_str(&str[0], str.size(), jfe.jfe_max_width);
size_t new_size
= last_word_str(&str[0],
str.size(),
jfe.jfe_max_width);
str.resize(new_size);
this->json_append(jfe, vd, str.data(), str.size());
this->json_append(
jfe, vd, str.data(), str.size());
break;
}
}

Loading…
Cancel
Save