Simplify usage of Span in several places
This commit is contained in:
parent
ab303a16d1
commit
2676aeadfa
5 changed files with 18 additions and 18 deletions
|
@ -139,7 +139,7 @@ std::string DescriptorChecksum(const Span<const char>& span)
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::string AddChecksum(const std::string& str) { return str + "#" + DescriptorChecksum(MakeSpan(str)); }
|
||||
std::string AddChecksum(const std::string& str) { return str + "#" + DescriptorChecksum(str); }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Internal representation //
|
||||
|
@ -1087,7 +1087,7 @@ bool CheckChecksum(Span<const char>& sp, bool require_checksum, std::string& err
|
|||
|
||||
std::unique_ptr<Descriptor> Parse(const std::string& descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum)
|
||||
{
|
||||
Span<const char> sp(descriptor.data(), descriptor.size());
|
||||
Span<const char> sp{descriptor};
|
||||
if (!CheckChecksum(sp, require_checksum, error)) return nullptr;
|
||||
auto ret = ParseScript(0, sp, ParseScriptContext::TOP, out, error);
|
||||
if (sp.size() == 0 && ret) return std::unique_ptr<Descriptor>(std::move(ret));
|
||||
|
@ -1098,7 +1098,7 @@ std::string GetDescriptorChecksum(const std::string& descriptor)
|
|||
{
|
||||
std::string ret;
|
||||
std::string error;
|
||||
Span<const char> sp(descriptor.data(), descriptor.size());
|
||||
Span<const char> sp{descriptor};
|
||||
if (!CheckChecksum(sp, false, error, &ret)) return "";
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1522,7 +1522,7 @@ static bool ExecuteWitnessScript(const Span<const valtype>& stack_span, const CS
|
|||
static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion, const std::vector<unsigned char>& program, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
|
||||
{
|
||||
CScript scriptPubKey;
|
||||
Span<const valtype> stack = MakeSpan(witness.stack);
|
||||
Span<const valtype> stack{witness.stack};
|
||||
|
||||
if (witversion == 0) {
|
||||
if (program.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
|
||||
|
|
|
@ -18,7 +18,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
|||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
std::string str = fuzzed_data_provider.ConsumeBytesAsString(32);
|
||||
const Span<const char> span = MakeSpan(str);
|
||||
const Span<const char> span{str};
|
||||
(void)span.data();
|
||||
(void)span.begin();
|
||||
(void)span.end();
|
||||
|
@ -32,7 +32,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
|||
}
|
||||
|
||||
std::string another_str = fuzzed_data_provider.ConsumeBytesAsString(32);
|
||||
const Span<const char> another_span = MakeSpan(another_str);
|
||||
const Span<const char> another_span{another_str};
|
||||
assert((span <= another_span) != (span > another_span));
|
||||
assert((span == another_span) != (span != another_span));
|
||||
assert((span >= another_span) != (span < another_span));
|
||||
|
|
|
@ -12,7 +12,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
|||
const size_t query_size = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
||||
const std::string query = fuzzed_data_provider.ConsumeBytesAsString(std::min<size_t>(query_size, 1024 * 1024));
|
||||
const std::string span_str = fuzzed_data_provider.ConsumeRemainingBytesAsString();
|
||||
const Span<const char> const_span = MakeSpan(span_str);
|
||||
const Span<const char> const_span{span_str};
|
||||
|
||||
Span<const char> mut_span = const_span;
|
||||
(void)spanparsing::Const(query, mut_span);
|
||||
|
|
|
@ -1829,7 +1829,7 @@ BOOST_AUTO_TEST_CASE(test_spanparsing)
|
|||
|
||||
// Const(...): parse a constant, update span to skip it if successful
|
||||
input = "MilkToastHoney";
|
||||
sp = MakeSpan(input);
|
||||
sp = input;
|
||||
success = Const("", sp); // empty
|
||||
BOOST_CHECK(success);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(sp), "MilkToastHoney");
|
||||
|
@ -1854,7 +1854,7 @@ BOOST_AUTO_TEST_CASE(test_spanparsing)
|
|||
|
||||
// Func(...): parse a function call, update span to argument if successful
|
||||
input = "Foo(Bar(xy,z()))";
|
||||
sp = MakeSpan(input);
|
||||
sp = input;
|
||||
|
||||
success = Func("FooBar", sp);
|
||||
BOOST_CHECK(!success);
|
||||
|
@ -1877,31 +1877,31 @@ BOOST_AUTO_TEST_CASE(test_spanparsing)
|
|||
Span<const char> result;
|
||||
|
||||
input = "(n*(n-1))/2";
|
||||
sp = MakeSpan(input);
|
||||
sp = input;
|
||||
result = Expr(sp);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(result), "(n*(n-1))/2");
|
||||
BOOST_CHECK_EQUAL(SpanToStr(sp), "");
|
||||
|
||||
input = "foo,bar";
|
||||
sp = MakeSpan(input);
|
||||
sp = input;
|
||||
result = Expr(sp);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(result), "foo");
|
||||
BOOST_CHECK_EQUAL(SpanToStr(sp), ",bar");
|
||||
|
||||
input = "(aaaaa,bbbbb()),c";
|
||||
sp = MakeSpan(input);
|
||||
sp = input;
|
||||
result = Expr(sp);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(result), "(aaaaa,bbbbb())");
|
||||
BOOST_CHECK_EQUAL(SpanToStr(sp), ",c");
|
||||
|
||||
input = "xyz)foo";
|
||||
sp = MakeSpan(input);
|
||||
sp = input;
|
||||
result = Expr(sp);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(result), "xyz");
|
||||
BOOST_CHECK_EQUAL(SpanToStr(sp), ")foo");
|
||||
|
||||
input = "((a),(b),(c)),xxx";
|
||||
sp = MakeSpan(input);
|
||||
sp = input;
|
||||
result = Expr(sp);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(result), "((a),(b),(c))");
|
||||
BOOST_CHECK_EQUAL(SpanToStr(sp), ",xxx");
|
||||
|
@ -1910,7 +1910,7 @@ BOOST_AUTO_TEST_CASE(test_spanparsing)
|
|||
std::vector<Span<const char>> results;
|
||||
|
||||
input = "xxx";
|
||||
results = Split(MakeSpan(input), 'x');
|
||||
results = Split(input, 'x');
|
||||
BOOST_CHECK_EQUAL(results.size(), 4U);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(results[0]), "");
|
||||
BOOST_CHECK_EQUAL(SpanToStr(results[1]), "");
|
||||
|
@ -1918,19 +1918,19 @@ BOOST_AUTO_TEST_CASE(test_spanparsing)
|
|||
BOOST_CHECK_EQUAL(SpanToStr(results[3]), "");
|
||||
|
||||
input = "one#two#three";
|
||||
results = Split(MakeSpan(input), '-');
|
||||
results = Split(input, '-');
|
||||
BOOST_CHECK_EQUAL(results.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(results[0]), "one#two#three");
|
||||
|
||||
input = "one#two#three";
|
||||
results = Split(MakeSpan(input), '#');
|
||||
results = Split(input, '#');
|
||||
BOOST_CHECK_EQUAL(results.size(), 3U);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(results[0]), "one");
|
||||
BOOST_CHECK_EQUAL(SpanToStr(results[1]), "two");
|
||||
BOOST_CHECK_EQUAL(SpanToStr(results[2]), "three");
|
||||
|
||||
input = "*foo*bar*";
|
||||
results = Split(MakeSpan(input), '*');
|
||||
results = Split(input, '*');
|
||||
BOOST_CHECK_EQUAL(results.size(), 4U);
|
||||
BOOST_CHECK_EQUAL(SpanToStr(results[0]), "");
|
||||
BOOST_CHECK_EQUAL(SpanToStr(results[1]), "foo");
|
||||
|
|
Loading…
Reference in a new issue