Coverage Report

Created: 2026-06-01 18:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/script/parsing.cpp
Line
Count
Source
1
// Copyright (c) 2018-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <script/parsing.h>
6
7
#include <span.h>
8
9
#include <algorithm>
10
#include <cstddef>
11
#include <string>
12
13
namespace script {
14
15
bool Const(const std::string& str, std::span<const char>& sp, bool skip)
16
0
{
17
0
    if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
  Branch (17:9): [True: 0, False: 0]
  Branch (17:44): [True: 0, False: 0]
18
0
        if (skip) sp = sp.subspan(str.size());
  Branch (18:13): [True: 0, False: 0]
19
0
        return true;
20
0
    }
21
0
    return false;
22
0
}
23
24
bool Func(const std::string& str, std::span<const char>& sp)
25
0
{
26
0
    if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
  Branch (26:9): [True: 0, False: 0]
  Branch (26:48): [True: 0, False: 0]
  Branch (26:73): [True: 0, False: 0]
  Branch (26:101): [True: 0, False: 0]
27
0
        sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
28
0
        return true;
29
0
    }
30
0
    return false;
31
0
}
32
33
std::span<const char> Expr(std::span<const char>& sp)
34
0
{
35
0
    int level = 0;
36
0
    auto it = sp.begin();
37
0
    while (it != sp.end()) {
  Branch (37:12): [True: 0, False: 0]
38
0
        if (*it == '(' || *it == '{') {
  Branch (38:13): [True: 0, False: 0]
  Branch (38:27): [True: 0, False: 0]
39
0
            ++level;
40
0
        } else if (level && (*it == ')' || *it == '}')) {
  Branch (40:20): [True: 0, False: 0]
  Branch (40:30): [True: 0, False: 0]
  Branch (40:44): [True: 0, False: 0]
41
0
            --level;
42
0
        } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
  Branch (42:20): [True: 0, False: 0]
  Branch (42:35): [True: 0, False: 0]
  Branch (42:49): [True: 0, False: 0]
  Branch (42:63): [True: 0, False: 0]
43
0
            break;
44
0
        }
45
0
        ++it;
46
0
    }
47
0
    std::span<const char> ret = sp.first(it - sp.begin());
48
0
    sp = sp.subspan(it - sp.begin());
49
0
    return ret;
50
0
}
51
52
} // namespace script