Coverage Report

Created: 2026-04-29 19:21

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 <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
252k
{
17
252k
    if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
18
35.0k
        if (skip) sp = sp.subspan(str.size());
19
35.0k
        return true;
20
35.0k
    }
21
217k
    return false;
22
252k
}
23
24
bool Func(const std::string& str, std::span<const char>& sp)
25
153k
{
26
153k
    if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
27
19.8k
        sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
28
19.8k
        return true;
29
19.8k
    }
30
133k
    return false;
31
153k
}
32
33
std::span<const char> Expr(std::span<const char>& sp)
34
42.8k
{
35
42.8k
    int level = 0;
36
42.8k
    auto it = sp.begin();
37
9.31M
    while (it != sp.end()) {
38
9.29M
        if (*it == '(' || *it == '{') {
39
26.6k
            ++level;
40
9.26M
        } else if (level && (*it == ')' || *it == '}')) {
41
26.3k
            --level;
42
9.24M
        } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
43
27.1k
            break;
44
27.1k
        }
45
9.26M
        ++it;
46
9.26M
    }
47
42.8k
    std::span<const char> ret = sp.first(it - sp.begin());
48
42.8k
    sp = sp.subspan(it - sp.begin());
49
42.8k
    return ret;
50
42.8k
}
51
52
} // namespace script