Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2018-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <script/parsing.h>7#include <algorithm>8#include <cstddef>9#include <string>11namespace script {13bool Const(const std::string& str, std::span<const char>& sp, bool skip)14{15if ((size_t)sp.size() >= str.size() && std::equal(str.begin(), str.end(), sp.begin())) {16if (skip) sp = sp.subspan(str.size());17return true;18}19return false;20}22bool Func(const std::string& str, std::span<const char>& sp)23{24if ((size_t)sp.size() >= str.size() + 2 && sp[str.size()] == '(' && sp[sp.size() - 1] == ')' && std::equal(str.begin(), str.end(), sp.begin())) {25sp = sp.subspan(str.size() + 1, sp.size() - str.size() - 2);26return true;27}28return false;29}31std::span<const char> Expr(std::span<const char>& sp)32{33int level = 0;34auto it = sp.begin();35while (it != sp.end()) {36if (*it == '(' || *it == '{') {37++level;38} else if (level && (*it == ')' || *it == '}')) {39--level;40} else if (level == 0 && (*it == ')' || *it == '}' || *it == ',')) {41break;42}43++it;44}45std::span<const char> ret = sp.first(it - sp.begin());46sp = sp.subspan(it - sp.begin());47return ret;48}50} // namespace script
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.