Coverage Report

Created: 2025-06-10 13:21

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)
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
        sp = sp.subspan(str.size());
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
1.04M
{
26
1.04M
    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: 1.04M, False: 0]
  Branch (26:48): [True: 221k, False: 820k]
  Branch (26:73): [True: 221k, False: 0]
  Branch (26:101): [True: 110k, False: 110k]
27
110k
        sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
28
110k
        return true;
29
110k
    }
30
931k
    return false;
31
1.04M
}
32
33
std::span<const char> Expr(std::span<const char>& sp)
34
133k
{
35
133k
    int level = 0;
36
133k
    auto it = sp.begin();
37
17.4M
    while (it != sp.end()) {
  Branch (37:12): [True: 17.3M, False: 133k]
38
17.3M
        if (*it == '(' || *it == '{') {
  Branch (38:13): [True: 133k, False: 17.1M]
  Branch (38:27): [True: 0, False: 17.1M]
39
133k
            ++level;
40
17.1M
        } else if (level && (*it == ')' || *it == '}')) {
  Branch (40:20): [True: 14.0M, False: 3.10M]
  Branch (40:30): [True: 133k, False: 13.9M]
  Branch (40:44): [True: 0, False: 13.9M]
41
133k
            --level;
42
17.0M
        } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
  Branch (42:20): [True: 3.10M, False: 13.9M]
  Branch (42:35): [True: 0, False: 3.10M]
  Branch (42:49): [True: 0, False: 3.10M]
  Branch (42:63): [True: 0, False: 3.10M]
43
0
            break;
44
0
        }
45
17.3M
        ++it;
46
17.3M
    }
47
133k
    std::span<const char> ret = sp.first(it - sp.begin());
48
133k
    sp = sp.subspan(it - sp.begin());
49
133k
    return ret;
50
133k
}
51
52
} // namespace script