Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
spanparsing.h
Go to the documentation of this file.
1// Copyright (c) 2018 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#ifndef BITCOIN_UTIL_SPANPARSING_H
6#define BITCOIN_UTIL_SPANPARSING_H
7
8#include <span.h>
9
10#include <string>
11#include <vector>
12
13namespace spanparsing {
14
21bool Const(const std::string &str, Span<const char> &sp);
22
30bool Func(const std::string &str, Span<const char> &sp);
31
42
51template <typename T = Span<const char>>
52std::vector<T> Split(const Span<const char> &sp, char sep) {
53 std::vector<T> ret;
54 auto it = sp.begin();
55 auto start = it;
56 while (it != sp.end()) {
57 if (*it == sep) {
58 ret.emplace_back(start, it);
59 start = it + 1;
60 }
61 ++it;
62 }
63 ret.emplace_back(start, it);
64 return ret;
65}
66
67} // namespace spanparsing
68
69#endif // BITCOIN_UTIL_SPANPARSING_H
A Span is an object that can refer to a contiguous sequence of objects.
Definition span.h:93
Span< const char > Expr(Span< const char > &sp)
Extract the expression that sp begins with.
bool Const(const std::string &str, Span< const char > &sp)
Parse a constant.
std::vector< T > Split(const Span< const char > &sp, char sep)
Split a string on every instance of sep, returning a vector.
Definition spanparsing.h:52
bool Func(const std::string &str, Span< const char > &sp)
Parse a function call.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85