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

tstack / lnav / 11872214087-1756

16 Nov 2024 06:12PM UTC coverage: 70.243% (+0.5%) from 69.712%
11872214087-1756

push

github

tstack
[build] disable regex101

46266 of 65866 relevant lines covered (70.24%)

467515.63 hits per line

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

44.44
/src/document.sections.hh
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
#ifndef lnav_attr_line_breadcrumbs_hh
31
#define lnav_attr_line_breadcrumbs_hh
32

33
#include <map>
34
#include <set>
35
#include <string>
36
#include <vector>
37

38
#include "base/attr_line.hh"
39
#include "base/file_range.hh"
40
#include "breadcrumb.hh"
41
#include "intervaltree/IntervalTree.h"
42
#include "mapbox/variant.hpp"
43
#include "text_format.hh"
44

45
namespace lnav {
46
namespace document {
47

48
using section_key_t = mapbox::util::variant<std::string, size_t>;
49
using section_interval_t = interval_tree::Interval<file_off_t, section_key_t>;
50
using sections_tree_t = interval_tree::IntervalTree<file_off_t, section_key_t>;
51

52
enum class section_types_t {
53
    comment,
54
    multiline_string,
55
};
56

57
using section_type_interval_t
58
    = interval_tree::Interval<file_off_t, section_types_t>;
59
using section_types_tree_t
60
    = interval_tree::IntervalTree<file_off_t, section_types_t>;
61

62
struct hier_node {
63
    hier_node* hn_parent{nullptr};
64
    file_off_t hn_start{0};
65
    size_t hn_line_number{0};
66
    std::multimap<std::string, hier_node*> hn_named_children;
67
    std::vector<std::unique_ptr<hier_node>> hn_children;
68

69
    std::optional<hier_node*> lookup_child(section_key_t key) const;
70

71
    std::optional<size_t> child_index(const hier_node* hn) const;
72

73
    struct child_neighbors_result {
74
        std::optional<const hier_node*> cnr_previous;
75
        std::optional<const hier_node*> cnr_next;
76
    };
77

78
    std::optional<child_neighbors_result> child_neighbors(
79
        const hier_node* hn, file_off_t offset) const;
80

81
    std::optional<child_neighbors_result> line_neighbors(size_t ln) const;
82

83
    std::optional<size_t> find_line_number(const std::string& str) const
×
84
    {
85
        auto iter = this->hn_named_children.find(str);
×
86
        if (iter != this->hn_named_children.end()) {
×
87
            return std::make_optional(iter->second->hn_line_number);
×
88
        }
89

90
        return std::nullopt;
×
91
    }
92

93
    std::optional<size_t> find_line_number(size_t index) const
×
94
    {
95
        if (index < this->hn_children.size()) {
×
96
            return std::make_optional(
×
97
                this->hn_children[index]->hn_line_number);
×
98
        }
99
        return std::nullopt;
×
100
    }
101

102
    bool is_named_only() const
2✔
103
    {
104
        return this->hn_children.size() == this->hn_named_children.size();
2✔
105
    }
106

107
    static std::optional<const hier_node*> lookup_path(
108
        const hier_node* root, const std::vector<section_key_t>& path);
109

110
    template<typename F>
111
    static void depth_first(hier_node* root, F func)
7,720✔
112
    {
113
        if (root == nullptr) {
7,720✔
114
            return;
138✔
115
        }
116

117
        for (auto& child : root->hn_children) {
14,593✔
118
            depth_first(child.get(), func);
7,011✔
119
        }
120
        func(root);
7,582✔
121
    }
122
};
123

124
struct metadata {
125
    sections_tree_t m_sections_tree;
126
    std::unique_ptr<hier_node> m_sections_root;
127
    section_types_tree_t m_section_types_tree;
128
    std::set<size_t> m_indents;
129
    text_format_t m_text_format{text_format_t::TF_UNKNOWN};
130

131
    std::vector<section_key_t> path_for_range(size_t start, size_t stop);
132

133
    std::vector<breadcrumb::possibility> possibility_provider(
134
        const std::vector<section_key_t>& path);
135
};
136

137
metadata discover_metadata(const attr_line_t& al);
138

139
metadata discover_structure(attr_line_t& al,
140
                            struct line_range lr,
141
                            text_format_t tf = text_format_t::TF_UNKNOWN);
142

143
}  // namespace document
144
}  // namespace lnav
145

146
namespace fmt {
147
template<>
148
struct formatter<lnav::document::section_key_t> : formatter<string_view> {
149
    auto format(const lnav::document::section_key_t& p, format_context& ctx)
150
        -> decltype(ctx.out()) const;
151
};
152

153
template<>
154
struct formatter<std::vector<lnav::document::section_key_t>>
155
    : formatter<string_view> {
156
    auto format(const std::vector<lnav::document::section_key_t>& p,
157
                format_context& ctx) -> decltype(ctx.out()) const;
158
};
159
}  // namespace fmt
160

161
#endif
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