Coverage Report

Created: 2026-08-14 20:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/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 <algorithm>
8
#include <cstddef>
9
#include <string>
10
11
namespace script {
12
13
bool Const(const std::string& str, std::span<const char>& sp, bool skip)
14
253k
{
15
253k
    if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
16
35.1k
        if (skip) sp = sp.subspan(str.size());
17
35.1k
        return true;
18
35.1k
    }
19
217k
    return false;
20
253k
}
21
22
bool Func(const std::string& str, std::span<const char>& sp)
23
174k
{
24
174k
    if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
25
21.0k
        sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
26
21.0k
        return true;
27
21.0k
    }
28
153k
    return false;
29
174k
}
30
31
std::span<const char> Expr(std::span<const char>& sp)
32
44.2k
{
33
44.2k
    int level = 0;
34
44.2k
    auto it = sp.begin();
35
9.45M
    while (it != sp.end()) {
36
9.44M
        if (*it == '(' || *it == '{') {
37
28.0k
            ++level;
38
9.41M
        } else if (level && (*it == ')' || *it == '}')) {
39
27.7k
            --level;
40
9.38M
        } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
41
27.1k
            break;
42
27.1k
        }
43
9.41M
        ++it;
44
9.41M
    }
45
44.2k
    std::span<const char> ret = sp.first(it - sp.begin());
46
44.2k
    sp = sp.subspan(it - sp.begin());
47
44.2k
    return ret;
48
44.2k
}
49
50
} // namespace script