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