mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-03 12:11:56 +00:00
When parsing a descriptor, it is useful to be able to check whether a
string begins with a substring without consuming that substring as
another function such as Func() will be used later which requires that
substring to be present at the beginning.
Specifically, for MuSig2, this modified Const will be used to determine
whether a an expression begins with "musig(" before a subsequent
Func("musig", ...) is used.
41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
// Copyright (c) 2018-present The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_SCRIPT_PARSING_H
|
|
#define BITCOIN_SCRIPT_PARSING_H
|
|
|
|
#include <span.h>
|
|
|
|
#include <string>
|
|
|
|
namespace script {
|
|
|
|
/** Parse a constant.
|
|
*
|
|
* If sp's initial part matches str, sp is optionally updated to skip that part, and true is returned.
|
|
* Otherwise sp is unmodified and false is returned.
|
|
*/
|
|
bool Const(const std::string& str, std::span<const char>& sp, bool skip = true);
|
|
|
|
/** Parse a function call.
|
|
*
|
|
* If sp's initial part matches str + "(", and sp ends with ")", sp is updated to be the
|
|
* section between the braces, and true is returned. Otherwise sp is unmodified and false
|
|
* is returned.
|
|
*/
|
|
bool Func(const std::string& str, std::span<const char>& sp);
|
|
|
|
/** Extract the expression that sp begins with.
|
|
*
|
|
* This function will return the initial part of sp, up to (but not including) the first
|
|
* comma or closing brace, skipping ones that are surrounded by braces. So for example,
|
|
* for "foo(bar(1),2),3" the initial part "foo(bar(1),2)" will be returned. sp will be
|
|
* updated to skip the initial part that is returned.
|
|
*/
|
|
std::span<const char> Expr(std::span<const char>& sp);
|
|
|
|
} // namespace script
|
|
|
|
#endif // BITCOIN_SCRIPT_PARSING_H
|