• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 20284884426-2753

16 Dec 2025 10:23PM UTC coverage: 68.23% (-0.7%) from 68.903%
20284884426-2753

push

github

tstack
[log] show invalid utf hex dump in log view too

25 of 25 new or added lines in 2 files covered. (100.0%)

503 existing lines in 33 files now uncovered.

51170 of 74996 relevant lines covered (68.23%)

433797.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.59
/src/plain_text_source.cc
1
/**
2
 * Copyright (c) 2022, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29

30
#include "plain_text_source.hh"
31

32
#include "base/itertools.hh"
33
#include "config.h"
34
#include "document.sections.hh"
35
#include "scn/scan.h"
36

37
static std::vector<plain_text_source::text_line>
38
to_text_line(const std::vector<attr_line_t>& lines)
×
39
{
40
    file_off_t off = 0;
×
41

42
    return lines | lnav::itertools::map([&off](const auto& elem) {
×
43
               auto retval = plain_text_source::text_line{
×
44
                   off,
45
                   elem,
46
               };
47

48
               off += elem.length() + 1;
×
49
               return retval;
×
50
           });
×
51
}
52

53
plain_text_source::plain_text_source(const string_fragment& text)
×
54
{
55
    size_t start = 0;
×
56

57
    for (const auto& line : text.split_lines()) {
×
58
        this->tds_lines.emplace_back(start, attr_line_t::from_ansi_frag(line));
×
59
        start += line.length();
×
60
    }
61
    this->tds_longest_line = this->compute_longest_line();
×
62
}
63

64
plain_text_source::plain_text_source(const std::vector<std::string>& text_lines)
×
65
{
66
    this->replace_with(text_lines);
×
67
}
68

69
plain_text_source::plain_text_source(const std::vector<attr_line_t>& text_lines)
×
70
    : tds_lines(to_text_line(text_lines))
×
71
{
72
    this->tds_longest_line = this->compute_longest_line();
×
73
}
74

75
plain_text_source&
76
plain_text_source::replace_with(const attr_line_t& text_lines)
71✔
77
{
78
    this->tds_lines.clear();
71✔
79
    this->tds_doc_sections = lnav::document::discover_metadata(text_lines);
71✔
80
    file_off_t off = 0;
71✔
81
    auto lines = text_lines.split_lines();
71✔
82
    while (!lines.empty() && lines.back().empty()) {
71✔
83
        lines.pop_back();
×
84
    }
85
    for (auto& line : lines) {
20,726✔
86
        auto line_len = line.al_string.size() + 1;
20,655✔
87
        this->tds_lines.emplace_back(off, std::move(line));
20,655✔
88
        off += line_len;
20,655✔
89
    }
90
    this->tds_longest_line = this->compute_longest_line();
71✔
91
    if (this->tss_view != nullptr) {
71✔
92
        if (this->tss_view->get_selection()) {
36✔
93
            this->tss_view->set_selection(0_vl);
35✔
94
        }
95
        this->tss_view->set_needs_update();
36✔
96
    }
97
    return *this;
71✔
98
}
71✔
99

100
plain_text_source&
101
plain_text_source::replace_with_mutable(attr_line_t& text_lines,
23✔
102
                                        std::optional<text_format_t> tf)
103
{
104
    this->tds_text_format = tf;
23✔
105
    this->tds_lines.clear();
23✔
106
    if (tf) {
23✔
107
        this->tds_doc_sections = lnav::document::discover(text_lines)
23✔
108
                                     .with_text_format(tf.value())
23✔
109
                                     .perform();
23✔
110
    }
111
    file_off_t off = 0;
23✔
112
    auto lines = text_lines.split_lines();
23✔
113
    while (!lines.empty() && lines.back().empty()) {
23✔
114
        lines.pop_back();
×
115
    }
116
    for (auto& line : lines) {
8,498✔
117
        auto line_len = line.length() + 1;
8,475✔
118
        this->tds_lines.emplace_back(off, std::move(line));
8,475✔
119
        off += line_len;
8,475✔
120
    }
121
    this->tds_longest_line = this->compute_longest_line();
23✔
122
    if (this->tss_view != nullptr) {
23✔
123
        if (this->tss_view->get_selection()) {
4✔
124
            this->tss_view->set_selection(0_vl);
4✔
125
        }
126
        this->tss_view->set_needs_update();
4✔
127
    }
128
    return *this;
23✔
129
}
23✔
130

131
plain_text_source&
132
plain_text_source::replace_with(const std::vector<std::string>& text_lines)
×
133
{
134
    file_off_t off = 0;
×
135
    for (const auto& str : text_lines) {
×
136
        this->tds_lines.emplace_back(off, attr_line_t::from_ansi_str(str));
×
137
        off += str.length() + 1;
×
138
    }
139
    this->tds_longest_line = this->compute_longest_line();
×
140
    if (this->tss_view != nullptr) {
×
141
        if (this->tss_view->get_selection()) {
×
142
            this->tss_view->set_selection(0_vl);
×
143
        }
144
        this->tss_view->set_needs_update();
×
145
    }
146
    return *this;
×
147
}
148

149
plain_text_source&
150
plain_text_source::replace_with(const std::vector<attr_line_t>& text_lines)
10✔
151
{
152
    file_off_t off = 0;
10✔
153
    this->tds_lines.clear();
10✔
154
    for (const auto& al : text_lines) {
10✔
UNCOV
155
        this->tds_lines.emplace_back(off, al);
×
UNCOV
156
        off += al.length() + 1;
×
157
    }
158
    this->tds_longest_line = this->compute_longest_line();
10✔
159
    if (this->tss_view != nullptr) {
10✔
160
        if (this->tss_view->get_selection()) {
10✔
161
            this->tss_view->set_selection(0_vl);
1✔
162
        }
163
        this->tss_view->set_needs_update();
10✔
164
    }
165
    return *this;
10✔
166
}
167

168
void
169
plain_text_source::clear()
453✔
170
{
171
    this->tds_lines.clear();
453✔
172
    this->tds_longest_line = 0;
453✔
173
    this->tds_text_format = text_format_t::TF_PLAINTEXT;
453✔
174
    if (this->tss_view != nullptr) {
453✔
175
        this->tss_view->set_needs_update();
375✔
176
    }
177
}
453✔
178

179
plain_text_source&
180
plain_text_source::truncate_to(size_t max_lines)
×
181
{
182
    while (this->tds_lines.size() > max_lines) {
×
183
        this->tds_lines.pop_back();
×
184
    }
185
    if (this->tss_view != nullptr) {
×
186
        this->tss_view->set_needs_update();
×
187
    }
188
    return *this;
×
189
}
190

191
size_t
192
plain_text_source::text_line_width(textview_curses& curses)
5,344✔
193
{
194
    return this->tds_longest_line;
5,344✔
195
}
196

197
line_info
198
plain_text_source::text_value_for_line(textview_curses& tc,
7,594✔
199
                                       int row,
200
                                       std::string& value_out,
201
                                       text_sub_source::line_flags_t flags)
202
{
203
    value_out = this->tds_lines[row].tl_value.get_string();
7,594✔
204
    this->tds_line_indent_size = 0;
7,594✔
205
    for (const auto& ch : value_out) {
22,726✔
206
        if (ch == ' ') {
21,462✔
207
            this->tds_line_indent_size += 1;
15,132✔
208
        } else if (ch == '\t') {
6,330✔
209
            do {
210
                this->tds_line_indent_size += 1;
×
211
            } while (this->tds_line_indent_size % 8);
×
212
        } else {
213
            break;
6,330✔
214
        }
215
    }
216

217
    return {};
7,594✔
218
}
219

220
void
221
plain_text_source::text_attrs_for_line(textview_curses& tc,
7,594✔
222
                                       int line,
223
                                       string_attrs_t& value_out)
224
{
225
    value_out = this->tds_lines[line].tl_value.get_attrs();
7,594✔
226
    if (this->tds_reverse_selection && tc.is_selectable()
×
227
        && tc.get_selection() == line)
7,594✔
228
    {
229
        value_out.emplace_back(line_range{0, -1},
×
230
                               VC_STYLE.value(text_attrs::with_reverse()));
×
231
    }
232
    for (const auto& indent : this->tds_doc_sections.m_indents) {
10,169✔
233
        if (indent < this->tds_line_indent_size) {
2,575✔
234
            auto guide_lr = line_range{
235
                (int) indent,
465✔
236
                (int) (indent + 1),
465✔
237
                line_range::unit::codepoint,
238
            };
465✔
239
            value_out.emplace_back(guide_lr,
465✔
240
                                   VC_BLOCK_ELEM.value(block_elem_t{
930✔
241
                                       L'\u258f', role_t::VCR_INDENT_GUIDE}));
242
        }
243
    }
244
}
7,594✔
245

246
size_t
247
plain_text_source::text_size_for_line(textview_curses& tc,
×
248
                                      int row,
249
                                      text_sub_source::line_flags_t flags)
250
{
251
    return this->tds_lines[row].tl_value.length();
×
252
}
253

254
std::optional<text_format_t>
255
plain_text_source::get_text_format() const
5,436✔
256
{
257
    return this->tds_text_format;
5,436✔
258
}
259

260
size_t
261
plain_text_source::compute_longest_line()
104✔
262
{
263
    size_t retval = 0;
104✔
264
    for (auto& iter : this->tds_lines) {
29,234✔
265
        retval = std::max(retval, (size_t) iter.tl_value.length());
29,130✔
266
    }
267
    return retval;
104✔
268
}
269

270
std::optional<vis_line_t>
271
plain_text_source::line_for_offset(file_off_t off) const
6✔
272
{
273
    struct cmper {
274
        bool operator()(const file_off_t& lhs, const text_line& rhs) const
275
        {
276
            return lhs < rhs.tl_offset;
277
        }
278

279
        bool operator()(const text_line& lhs, const file_off_t& rhs) const
57✔
280
        {
281
            return lhs.tl_offset < rhs;
57✔
282
        }
283
    };
284

285
    if (this->tds_lines.empty()) {
6✔
286
        return std::nullopt;
×
287
    }
288

289
    log_trace("line_for_offset(%lld)", off);
6✔
290
    auto iter = std::lower_bound(
6✔
291
        this->tds_lines.begin(), this->tds_lines.end(), off, cmper{});
292
    if (iter == this->tds_lines.end()) {
6✔
293
        if (this->tds_lines.back().contains_offset(off)) {
×
294
            return std::make_optional(
×
295
                vis_line_t(std::distance(this->tds_lines.end() - 1, iter)));
×
296
        }
297
        return std::nullopt;
×
298
    }
299

300
    if (!iter->contains_offset(off) && iter != this->tds_lines.begin()) {
6✔
301
        log_trace("  lower_bound (%lld) does not contain offset",
2✔
302
                  iter->tl_offset);
303
        --iter;
2✔
304
    }
305

306
    auto retval = vis_line_t(std::distance(this->tds_lines.begin(), iter));
12✔
307
    log_trace("  retval=%d", (int) retval);
6✔
308
    return retval;
6✔
309
}
310

311
void
312
plain_text_source::text_crumbs_for_line(int line,
2✔
313
                                        std::vector<breadcrumb::crumb>& crumbs)
314
{
315
    const auto initial_size = crumbs.size();
2✔
316
    const auto& tl = this->tds_lines[line];
2✔
317

318
    this->tds_doc_sections.m_sections_tree.visit_overlapping(
4✔
319
        tl.tl_offset,
2✔
320
        tl.tl_offset + tl.tl_value.length(),
2✔
321
        [&crumbs, initial_size, meta = &this->tds_doc_sections, this](
2✔
322
            const auto& iv) {
323
            auto path = crumbs | lnav::itertools::skip(initial_size)
12✔
324
                | lnav::itertools::map(&breadcrumb::crumb::c_key)
8✔
325
                | lnav::itertools::append(iv.value);
4✔
326
            crumbs.emplace_back(
8✔
327
                iv.value,
4✔
328
                [meta, path]() { return meta->possibility_provider(path); },
12✔
329
                [this, meta, path](const auto& key) {
8✔
330
                    auto curr_node = lnav::document::hier_node::lookup_path(
×
331
                        meta->m_sections_root.get(), path);
×
332
                    if (!curr_node) {
×
333
                        return;
×
334
                    }
335
                    auto* parent_node = curr_node.value()->hn_parent;
×
336

337
                    if (parent_node == nullptr) {
×
338
                        return;
×
339
                    }
340
                    key.match(
×
341
                        [this, parent_node](const std::string& str) {
×
342
                            auto sib_iter
343
                                = parent_node->hn_named_children.find(str);
×
344
                            if (sib_iter
×
345
                                == parent_node->hn_named_children.end()) {
×
346
                                return;
×
347
                            }
348
                            this->line_for_offset(sib_iter->second->hn_start) |
×
349
                                [this](const auto new_top) {
×
350
                                    this->tss_view->set_selection(new_top);
×
351
                                    if (this->tss_view->is_selectable()) {
×
352
                                        this->tss_view->set_top(new_top - 2_vl,
×
353
                                                                false);
354
                                    }
355
                                };
356
                        },
357
                        [this, parent_node](size_t index) {
×
358
                            if (index >= parent_node->hn_children.size()) {
×
359
                                return;
×
360
                            }
361
                            auto sib = parent_node->hn_children[index].get();
×
362
                            this->line_for_offset(sib->hn_start) |
×
363
                                [this](const auto new_top) {
×
364
                                    this->tss_view->set_selection(new_top);
×
365
                                    if (this->tss_view->is_selectable()) {
×
366
                                        this->tss_view->set_top(new_top - 2_vl,
×
367
                                                                false);
368
                                    }
369
                                };
370
                        });
371
                });
372
        });
4✔
373

374
    auto path = crumbs | lnav::itertools::skip(initial_size)
4✔
375
        | lnav::itertools::map(&breadcrumb::crumb::c_key);
4✔
376
    auto node = lnav::document::hier_node::lookup_path(
2✔
377
        this->tds_doc_sections.m_sections_root.get(), path);
2✔
378

379
    if (node && !node.value()->hn_children.empty()) {
2✔
380
        auto poss_provider = [curr_node = node.value()]() {
1✔
381
            std::vector<breadcrumb::possibility> retval;
1✔
382
            for (const auto& child : curr_node->hn_named_children) {
2✔
383
                retval.emplace_back(child.first);
1✔
384
            }
385
            return retval;
1✔
386
        };
387
        auto path_performer = [this, curr_node = node.value()](
2✔
388
                                  const breadcrumb::crumb::key_t& value) {
389
            value.match(
×
390
                [this, curr_node](const std::string& str) {
×
391
                    auto child_iter = curr_node->hn_named_children.find(str);
×
392
                    if (child_iter != curr_node->hn_named_children.end()) {
×
393
                        this->line_for_offset(child_iter->second->hn_start) |
×
394
                            [this](const auto new_top) {
×
395
                                this->tss_view->set_selection(new_top);
×
396
                            };
397
                    }
398
                },
×
399
                [this, curr_node](size_t index) {
×
400
                    auto* child = curr_node->hn_children[index].get();
×
401
                    this->line_for_offset(child->hn_start) |
×
402
                        [this](const auto new_top) {
×
403
                            this->tss_view->set_selection(new_top);
×
404
                        };
405
                });
×
406
        };
1✔
407
        crumbs.emplace_back(
1✔
408
            "", "\u22ef", std::move(poss_provider), std::move(path_performer));
1✔
409
        crumbs.back().c_expected_input = node.value()->hn_named_children.empty()
2✔
410
            ? breadcrumb::crumb::expected_input_t::index
1✔
411
            : breadcrumb::crumb::expected_input_t::index_or_exact;
412
    }
413
}
2✔
414

415
std::optional<vis_line_t>
416
plain_text_source::row_for_anchor(const std::string& id)
5✔
417
{
418
    std::optional<vis_line_t> retval;
5✔
419

420
    if (this->tds_doc_sections.m_sections_root == nullptr) {
5✔
421
        return retval;
×
422
    }
423

424
    const auto& meta = this->tds_doc_sections;
5✔
425

426
    auto is_ptr = startswith(id, "#/");
5✔
427
    if (is_ptr) {
5✔
428
        auto hier_sf = string_fragment::from_str(id).consume_n(2).value();
×
429
        std::vector<lnav::document::section_key_t> path;
×
430

431
        while (!hier_sf.empty()) {
×
432
            auto comp_pair = hier_sf.split_when(string_fragment::tag1{'/'});
×
433
            auto scan_res
434
                = scn::scan_value<int64_t>(comp_pair.first.to_string_view());
×
435
            if (scan_res && scan_res->range().empty()) {
×
436
                path.emplace_back(scan_res->value());
×
437
            } else {
438
                stack_buf allocator;
×
439
                path.emplace_back(
×
440
                    json_ptr::decode(comp_pair.first, allocator).to_string());
×
441
            }
442
            hier_sf = comp_pair.second;
×
443
        }
444

445
        auto lookup_res = lnav::document::hier_node::lookup_path(
×
446
            meta.m_sections_root.get(), path);
×
447
        if (lookup_res) {
×
448
            retval = this->line_for_offset(lookup_res.value()->hn_start);
×
449
        }
450

451
        return retval;
×
452
    }
453

454
    lnav::document::hier_node::depth_first(
5✔
455
        meta.m_sections_root.get(),
456
        [this, &id, &retval](const lnav::document::hier_node* node) {
67✔
457
            for (const auto& child_pair : node->hn_named_children) {
114✔
458
                const auto& child_anchor = to_anchor_string(child_pair.first);
51✔
459

460
                if (child_anchor != id) {
51✔
461
                    continue;
47✔
462
                }
463

464
                retval = this->line_for_offset(child_pair.second->hn_start);
4✔
465
                break;
4✔
466
            }
51✔
467
        });
67✔
468

469
    return retval;
5✔
470
}
471

472
std::unordered_set<std::string>
473
plain_text_source::get_anchors()
×
474
{
475
    std::unordered_set<std::string> retval;
×
476

477
    lnav::document::hier_node::depth_first(
×
478
        this->tds_doc_sections.m_sections_root.get(),
479
        [&retval](const lnav::document::hier_node* node) {
×
480
            for (const auto& child_pair : node->hn_named_children) {
×
481
                retval.emplace(to_anchor_string(child_pair.first));
×
482
            }
483
        });
×
484

485
    return retval;
×
486
}
×
487

488
std::optional<std::string>
489
plain_text_source::anchor_for_row(vis_line_t vl)
4✔
490
{
491
    std::optional<std::string> retval;
4✔
492

493
    if (vl > (ssize_t) this->tds_lines.size()
4✔
494
        || this->tds_doc_sections.m_sections_root == nullptr)
4✔
495
    {
496
        return retval;
×
497
    }
498

499
    const auto& tl = this->tds_lines[vl];
4✔
500
    auto& md = this->tds_doc_sections;
4✔
501
    auto path_for_line = md.path_for_range(
502
        tl.tl_offset, tl.tl_offset + tl.tl_value.al_string.length());
4✔
503

504
    if (path_for_line.empty()) {
4✔
505
        return std::nullopt;
1✔
506
    }
507

508
    if ((path_for_line.size() == 1
3✔
509
         || this->tds_text_format == text_format_t::TF_MARKDOWN)
2✔
510
        && path_for_line.back().is<std::string>())
5✔
511
    {
512
        return to_anchor_string(path_for_line.back().get<std::string>());
2✔
513
    }
514

515
    auto comps
516
        = path_for_line | lnav::itertools::map([](const auto& elem) {
2✔
517
              return elem.match(
518
                  [](const std::string& str) {
×
519
                      stack_buf allocator;
1✔
520
                      return json_ptr::encode(str, allocator).to_string();
2✔
521
                  },
1✔
522
                  [](size_t index) { return fmt::to_string(index); });
5✔
523
          });
1✔
524

525
    return fmt::format(FMT_STRING("#/{}"),
4✔
526
                       fmt::join(comps.begin(), comps.end(), "/"));
2✔
527
}
4✔
528

529
std::optional<vis_line_t>
530
plain_text_source::adjacent_anchor(vis_line_t vl, direction dir)
2✔
531
{
532
    if (vl > (ssize_t) this->tds_lines.size()
2✔
533
        || this->tds_doc_sections.m_sections_root == nullptr)
2✔
534
    {
535
        return std::nullopt;
×
536
    }
537

538
    const auto& tl = this->tds_lines[vl];
2✔
539
    auto path_for_line = this->tds_doc_sections.path_for_range(
540
        tl.tl_offset, tl.tl_offset + tl.tl_value.al_string.length());
2✔
541

542
    log_trace("adjacent_anchor: curr path = %s",
2✔
543
              fmt::format(FMT_STRING("{}"), path_for_line).c_str());
544
    const auto& md = this->tds_doc_sections;
2✔
545
    if (path_for_line.empty()) {
2✔
546
        auto neighbors_res = md.m_sections_root->line_neighbors(vl);
1✔
547
        if (!neighbors_res) {
1✔
548
            return std::nullopt;
×
549
        }
550

551
        switch (dir) {
1✔
552
            case direction::prev: {
×
553
                if (neighbors_res->cnr_previous) {
×
554
                    return this->line_for_offset(
×
555
                        neighbors_res->cnr_previous.value()->hn_start);
×
556
                }
557
                break;
×
558
            }
559
            case direction::next: {
1✔
560
                if (neighbors_res->cnr_next) {
1✔
561
                    return this->line_for_offset(
×
562
                        neighbors_res->cnr_next.value()->hn_start);
×
563
                }
564
                if (!md.m_sections_root->hn_children.empty()) {
1✔
565
                    return this->line_for_offset(
1✔
566
                        md.m_sections_root->hn_children[0]->hn_start);
2✔
567
                }
568
                break;
×
569
            }
570
        }
571
        return std::nullopt;
×
572
    }
573

574
    auto last_key = path_for_line.back();
1✔
575
    path_for_line.pop_back();
1✔
576

577
    auto parent_opt = lnav::document::hier_node::lookup_path(
1✔
578
        md.m_sections_root.get(), path_for_line);
1✔
579
    if (!parent_opt) {
1✔
580
        log_trace("  no parent");
×
581
        return std::nullopt;
×
582
    }
583
    const auto* parent = parent_opt.value();
1✔
584

585
    auto child_hn = parent->lookup_child(last_key);
1✔
586
    if (!child_hn) {
1✔
587
        // XXX "should not happen"
588
        return std::nullopt;
×
589
    }
590

591
    auto neighbors_res = parent->child_neighbors(
3✔
592
        child_hn.value(), tl.tl_offset + tl.tl_value.al_string.length() + 1);
1✔
593
    if (!neighbors_res) {
1✔
594
        log_trace("no neighbors");
×
595
        return std::nullopt;
×
596
    }
597

598
    if (neighbors_res->cnr_previous && last_key.is<std::string>()) {
1✔
599
        auto neighbor_sub
600
            = neighbors_res->cnr_previous.value()->lookup_child(last_key);
1✔
601
        if (neighbor_sub) {
1✔
602
            log_trace("  loading previous child");
×
603
            neighbors_res->cnr_previous = neighbor_sub;
×
604
        }
605
    }
606

607
    if (neighbors_res->cnr_next && last_key.is<std::string>()) {
1✔
608
        auto neighbor_sub
609
            = neighbors_res->cnr_next.value()->lookup_child(last_key);
1✔
610
        if (neighbor_sub) {
1✔
611
            log_trace("  loading next child");
×
612
            neighbors_res->cnr_next = neighbor_sub;
×
613
        }
614
    }
615

616
    switch (dir) {
1✔
617
        case direction::prev: {
×
618
            if (neighbors_res->cnr_previous) {
×
619
                return this->line_for_offset(
×
620
                    neighbors_res->cnr_previous.value()->hn_start);
×
621
            }
622
            break;
×
623
        }
624
        case direction::next: {
1✔
625
            if (neighbors_res->cnr_next) {
1✔
626
                log_trace("  next offset %lld",
1✔
627
                          neighbors_res->cnr_next.value()->hn_start);
628
                return this->line_for_offset(
1✔
629
                    neighbors_res->cnr_next.value()->hn_start);
1✔
630
            }
631
            break;
×
632
        }
633
    }
634

635
    return std::nullopt;
×
636
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc