Coverage Report

Created: 2025-03-27 15:33

/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)
16
6.72M
{
17
6.72M
    if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
18
910k
        sp = sp.subspan(str.size());
19
910k
        return true;
20
910k
    }
21
5.81M
    return false;
22
6.72M
}
23
24
bool Func(const std::string& str, std::span<const char>& sp)
25
563k
{
26
563k
    if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
27
47.2k
        sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
28
47.2k
        return true;
29
47.2k
    }
30
515k
    return false;
31
563k
}
32
33
std::span<const char> Expr(std::span<const char>& sp)
34
215k
{
35
215k
    int level = 0;
36
215k
    auto it = sp.begin();
37
144M
    while (it != sp.end()) {
38
144M
        if (*it == '(' || *it == '{') {
39
435k
            ++level;
40
144M
        } else if (level && (*it == ')' || *it == '}')) {
41
328k
            --level;
42
143M
        } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
43
151k
            break;
44
151k
        }
45
144M
        ++it;
46
144M
    }
47
215k
    std::span<const char> ret = sp.first(it - sp.begin());
48
215k
    sp = sp.subspan(it - sp.begin());
49
215k
    return ret;
50
215k
}
51
52
} // namespace script