Coverage Report

Created: 2026-09-14 20:36

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
255k
{
15
255k
    if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
16
35.9k
        if (skip) sp = sp.subspan(str.size());
17
35.9k
        return true;
18
35.9k
    }
19
219k
    return false;
20
255k
}
21
22
bool Func(const std::string& str, std::span<const char>& sp)
23
181k
{
24
181k
    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.9k
        sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
26
21.9k
        return true;
27
21.9k
    }
28
159k
    return false;
29
181k
}
30
31
std::span<const char> Expr(std::span<const char>& sp)
32
45.4k
{
33
45.4k
    int level = 0;
34
45.4k
    auto it = sp.begin();
35
9.61M
    while (it != sp.end()) {
36
9.59M
        if (*it == '(' || *it == '{') {
37
29.8k
            ++level;
38
9.56M
        } else if (level && (*it == ')' || *it == '}')) {
39
29.3k
            --level;
40
9.53M
        } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
41
27.4k
            break;
42
27.4k
        }
43
9.56M
        ++it;
44
9.56M
    }
45
45.4k
    std::span<const char> ret = sp.first(it - sp.begin());
46
45.4k
    sp = sp.subspan(it - sp.begin());
47
45.4k
    return ret;
48
45.4k
}
49
50
} // namespace script