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 <span.h>
8 : :
9 : : #include <algorithm>
10 : : #include <cstddef>
11 : : #include <string>
12 : :
13 : : namespace script {
14 : :
15 : 222589 : bool Const(const std::string& str, std::span<const char>& sp)
16 : : {
17 [ + + + + ]: 222589 : if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
18 : 34574 : sp = sp.subspan(str.size());
19 : 34574 : return true;
20 : : }
21 : : return false;
22 : : }
23 : :
24 : 132613 : bool Func(const std::string& str, std::span<const char>& sp)
25 : : {
26 [ + + + + : 132613 : if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
+ + + + ]
27 [ - + ]: 11495 : sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
28 : 11495 : return true;
29 : : }
30 : : return false;
31 : : }
32 : :
33 : 33980 : std::span<const char> Expr(std::span<const char>& sp)
34 : : {
35 : 33980 : int level = 0;
36 : 33980 : auto it = sp.begin();
37 [ + + ]: 8971432 : while (it != sp.end()) {
38 [ + + + + ]: 8957561 : if (*it == '(' || *it == '{') {
39 : 17373 : ++level;
40 [ + + + + : 8940188 : } else if (level && (*it == ')' || *it == '}')) {
+ + ]
41 : 17177 : --level;
42 [ + + + + : 8923011 : } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
+ + + + ]
43 : : break;
44 : : }
45 : 8937452 : ++it;
46 : : }
47 : 33980 : std::span<const char> ret = sp.first(it - sp.begin());
48 : 33980 : sp = sp.subspan(it - sp.begin());
49 : 33980 : return ret;
50 : : }
51 : :
52 : : } // namespace script
|