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

mbits-os / quick_dra / 22038263728

15 Feb 2026 03:31PM UTC coverage: 93.378% (+6.4%) from 87.008%
22038263728

Pull #39

github

web-flow
Merge 74a89bbd4 into 7d773e4d9
Pull Request #39: testing

58 of 67 new or added lines in 23 files covered. (86.57%)

75 existing lines in 12 files now uncovered.

4033 of 4319 relevant lines covered (93.38%)

1107.01 hits per line

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

91.23
/libs/libpersist/src/parser.cpp
1
// Copyright (c) 2026 midnightBITS
2
// This code is licensed under MIT license (see LICENSE for details)
3

4
#include <fmt/format.h>
5
#include <fmt/std.h>
6
#include <fstream>
7
#include <optional>
8
#include <string>
9
#include <yaml/parser.hpp>
10

11
using namespace std::literals;
12

13
namespace yaml {
14
        namespace {
15
                template <typename ErrorCallback>
16
                std::optional<std::string> open_with(std::filesystem::path const& path,
156✔
17
                                                     ErrorCallback&& on_error) {
1✔
18
                        std::optional<std::string> result{};
469✔
19
                        std::ifstream in{path, std::ios::in | std::ios::binary};
469✔
20
                        if (!in) {
157✔
21
                                on_error();
×
22
                                return result;
×
23
                        }
24

312✔
25
                        std::ostringstream contents;
157✔
26
                        contents << in.rdbuf();
469✔
27
                        result = std::move(contents).str();
469✔
28

312✔
29
                        return result;
469✔
30
                }
469✔
31

32
                std::optional<std::string> open(std::filesystem::path const& path,
63✔
33
                                                std::string_view app_name) {
1✔
34
                        return open_with(path, [app_name, &path] {
85✔
35
                                fmt::print("{}: error: cannot find {}\n", app_name, path);
×
36
                        });
127✔
37
                }
127✔
38
        }  // namespace
39

40
        base_ctx parser::context(base_ctx const& parent) const {
178✔
41
                auto result = parent;
532✔
42
                result.parser = &rapid_parser;
532✔
43
                return result;
532✔
44
        }
355✔
45

46
        ryml::Parser parser::build_rapid_parser() noexcept {
178✔
47
                ryml::Parser p{&evt_handler, ryml::ParserOptions{}.locations(true)};
532✔
48
                p.reserve_locations(300);
532✔
49
                return p;
532✔
50
        }
355✔
51

52
        std::optional<ryml::Tree> parser::load(std::filesystem::path const& path,
63✔
53
                                               std::string_view app_name) & {
1✔
54
                auto maybe_contents = open(path, app_name);
190✔
55
                if (!maybe_contents) {
64✔
56
                        return std::nullopt;
×
57
                }
58

126✔
59
                return load_contents(std::move(*maybe_contents), path.string());
64✔
60
        }
190✔
61

62
        std::optional<ryml::Tree> parser::load(
93✔
63
            std::filesystem::path const& path,
64
            std::function<void()> const& on_error) & {
1✔
65
                auto maybe_contents = open_with(path, on_error);
280✔
66
                if (!maybe_contents) {
94✔
NEW
67
                        return std::nullopt;
×
68
                }
69

186✔
70
                return load_contents(std::move(*maybe_contents), path.string());
94✔
71
        }
280✔
72

73
        std::optional<ryml::Tree> parser::load_contents(std::string text,
177✔
74
                                                        std::string const& path) & {
1✔
75
                contents = std::move(text);
532✔
76
                path_str = path;
532✔
77
                rapid_parser.reserve_locations(300);
532✔
78
                auto tree =
414✔
79
                    ryml::parse_in_place(&rapid_parser, ryml::to_csubstr(path_str),
531✔
80
                                         ryml::to_substr(contents));
708✔
81
                tree.resolve();
532✔
82
                return std::optional{std::move(tree)};
709✔
83
        }
532✔
84
}  // namespace yaml
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