summaryrefslogtreecommitdiffstats
path: root/src/base/attr_line.builder.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
commit207df6fc406e81bfeebdff7f404bd242ff3f099f (patch)
treea1a796b056909dd0a04ffec163db9363a8757808 /src/base/attr_line.builder.cc
parentReleasing progress-linux version 0.11.2-1~progress7.99u1. (diff)
downloadlnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.tar.xz
lnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.zip
Merging upstream version 0.12.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/base/attr_line.builder.cc')
-rw-r--r--src/base/attr_line.builder.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/base/attr_line.builder.cc b/src/base/attr_line.builder.cc
index 95416dc..a6071a4 100644
--- a/src/base/attr_line.builder.cc
+++ b/src/base/attr_line.builder.cc
@@ -28,3 +28,57 @@
*/
#include "attr_line.builder.hh"
+
+attr_line_builder&
+attr_line_builder::append_as_hexdump(const string_fragment& sf)
+{
+ auto byte_off = size_t{0};
+ for (auto ch : sf) {
+ if (byte_off == 8) {
+ this->append(" ");
+ }
+ nonstd::optional<role_t> ro;
+ if (ch == '\0') {
+ ro = role_t::VCR_NULL;
+ } else if (isspace(ch) || iscntrl(ch)) {
+ ro = role_t::VCR_ASCII_CTRL;
+ } else if (!isprint(ch)) {
+ ro = role_t::VCR_NON_ASCII;
+ }
+ auto ag = ro.has_value() ? this->with_attr(VC_ROLE.value(ro.value()))
+ : this->with_default();
+ this->appendf(FMT_STRING(" {:0>2x}"), ch);
+ byte_off += 1;
+ }
+ for (; byte_off < 16; byte_off++) {
+ if (byte_off == 8) {
+ this->append(" ");
+ }
+ this->append(" ");
+ }
+ this->append(" ");
+ byte_off = 0;
+ for (auto ch : sf) {
+ if (byte_off == 8) {
+ this->append(" ");
+ }
+ if (ch == '\0') {
+ auto ag = this->with_attr(VC_ROLE.value(role_t::VCR_NULL));
+ this->append("\u22c4");
+ } else if (isspace(ch)) {
+ auto ag = this->with_attr(VC_ROLE.value(role_t::VCR_ASCII_CTRL));
+ this->append("_");
+ } else if (iscntrl(ch)) {
+ auto ag = this->with_attr(VC_ROLE.value(role_t::VCR_ASCII_CTRL));
+ this->append("\u2022");
+ } else if (isprint(ch)) {
+ this->alb_line.get_string().push_back(ch);
+ } else {
+ auto ag = this->with_attr(VC_ROLE.value(role_t::VCR_NON_ASCII));
+ this->append("\u00d7");
+ }
+ byte_off += 1;
+ }
+
+ return *this;
+}