Coverage Report

Created: 2026-04-20 22:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/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
13.0M
{
17
13.0M
    if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
18
1.71M
        if (skip) sp = sp.subspan(str.size());
19
1.71M
        return true;
20
1.71M
    }
21
11.3M
    return false;
22
13.0M
}
23
24
bool Func(const std::string& str, std::span<const char>& sp)
25
899k
{
26
899k
    if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
27
272k
        sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
28
272k
        return true;
29
272k
    }
30
627k
    return false;
31
899k
}
32
33
std::span<const char> Expr(std::span<const char>& sp)
34
558k
{
35
558k
    int level = 0;
36
558k
    auto it = sp.begin();
37
128M
    while (it != sp.end()) {
38
128M
        if (*it == '(' || *it == '{') {
39
1.39M
            ++level;
40
127M
        } else if (level && (*it == ')' || *it == '}')) {
41
974k
            --level;
42
126M
        } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
43
468k
            break;
44
468k
        }
45
128M
        ++it;
46
128M
    }
47
558k
    std::span<const char> ret = sp.first(it - sp.begin());
48
558k
    sp = sp.subspan(it - sp.begin());
49
558k
    return ret;
50
558k
}
51
52
} // namespace script