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