Branch data Line data Source code
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 : 252283 : bool Const(const std::string& str, std::span<const char>& sp, bool skip)
14 : : {
15 [ - + + + : 252283 : if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
+ + ]
16 [ + + ]: 35070 : if (skip) sp = sp.subspan(str.size());
17 : 35070 : return true;
18 : : }
19 : : return false;
20 : : }
21 : :
22 : 159519 : bool Func(const std::string& str, std::span<const char>& sp)
23 : : {
24 [ - + + + : 159519 : if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
+ + + + +
+ ]
25 [ - + ]: 20025 : sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
26 : 20025 : return true;
27 : : }
28 : : return false;
29 : : }
30 : :
31 : 43011 : std::span<const char> Expr(std::span<const char>& sp)
32 : : {
33 : 43011 : int level = 0;
34 : 43011 : auto it = sp.begin();
35 [ + + ]: 9462728 : while (it != sp.end()) {
36 [ + + + + ]: 9446841 : if (*it == '(' || *it == '{') {
37 : 26790 : ++level;
38 [ + + + + : 9420051 : } else if (level && (*it == ')' || *it == '}')) {
+ + ]
39 : 26499 : --level;
40 [ + + + + : 9393552 : } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
+ + + + ]
41 : : break;
42 : : }
43 : 9419717 : ++it;
44 : : }
45 : 43011 : std::span<const char> ret = sp.first(it - sp.begin());
46 : 43011 : sp = sp.subspan(it - sp.begin());
47 : 43011 : return ret;
48 : : }
49 : :
50 : : } // namespace script
|