Coverage Report

Created: 2026-05-30 09:47

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