Coverage Report

Created: 2025-09-08 17:06

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
7.91M
{
17
7.91M
    if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
18
1.11M
        if (skip) sp = sp.subspan(str.size());
19
1.11M
        return true;
20
1.11M
    }
21
6.79M
    return false;
22
7.91M
}
23
24
bool Func(const std::string& str, std::span<const char>& sp)
25
425k
{
26
425k
    if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
27
31.4k
        sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
28
31.4k
        return true;
29
31.4k
    }
30
393k
    return false;
31
425k
}
32
33
std::span<const char> Expr(std::span<const char>& sp)
34
279k
{
35
279k
    int level = 0;
36
279k
    auto it = sp.begin();
37
358M
    while (it != sp.end()) {
38
358M
        if (*it == '(' || *it == '{') {
39
424k
            ++level;
40
358M
        } else if (level && (*it == ')' || *it == '}')) {
41
331k
            --level;
42
358M
        } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
43
232k
            break;
44
232k
        }
45
358M
        ++it;
46
358M
    }
47
279k
    std::span<const char> ret = sp.first(it - sp.begin());
48
279k
    sp = sp.subspan(it - sp.begin());
49
279k
    return ret;
50
279k
}
51
52
} // namespace script