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 : 13128970 : bool Const(const std::string& str, std::span<const char>& sp, bool skip)
14 : : {
15 [ - + + + : 13128970 : if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {
+ + ]
16 [ + + ]: 1763497 : if (skip) sp = sp.subspan(str.size());
17 : 1763497 : return true;
18 : : }
19 : : return false;
20 : : }
21 : :
22 : 1034741 : bool Func(const std::string& str, std::span<const char>& sp)
23 : : {
24 [ - + + + : 1034741 : if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {
+ + + + +
+ ]
25 [ - + ]: 286879 : sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);
26 : 286879 : return true;
27 : : }
28 : : return false;
29 : : }
30 : :
31 : 622679 : std::span<const char> Expr(std::span<const char>& sp)
32 : : {
33 : 622679 : int level = 0;
34 : 622679 : auto it = sp.begin();
35 [ + + ]: 138422567 : while (it != sp.end()) {
36 [ + + + + ]: 138312352 : if (*it == '(' || *it == '{') {
37 : 1418799 : ++level;
38 [ + + + + : 136893553 : } else if (level && (*it == ')' || *it == '}')) {
+ + ]
39 : 994846 : --level;
40 [ + + + + : 135898707 : } else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {
+ + + + ]
41 : : break;
42 : : }
43 : 137799888 : ++it;
44 : : }
45 : 622679 : std::span<const char> ret = sp.first(it - sp.begin());
46 : 622679 : sp = sp.subspan(it - sp.begin());
47 : 622679 : return ret;
48 : : }
49 : :
50 : : } // namespace script
|