Skip to content

Commit d0152e9

Browse files
authored
Merge pull request #1761 from evoskuil/master
Add ALTERNATIVE_VARIANT_ASSIGNMENT.
2 parents d24351f + 9e872db commit d0152e9

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

include/bitcoin/system/types.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,16 @@ constexpr type& operator=(Alternative&& alternative) NOEXCEPT \
294294
{ \
295295
inner.template emplace<Alternative>(std::forward<Alternative>(alternative)); \
296296
return *this; \
297-
}
297+
}
298+
299+
/// Generate operator= overloads forwarding assignment for a specific alt type.
300+
#define ALTERNATIVE_VARIANT_ASSIGNMENT(type, Alternative, inner) \
301+
FORWARD_ALTERNATIVE_VARIANT_ASSIGNMENT(type, Alternative, inner) \
302+
constexpr type& operator=(const Alternative& alternative) NOEXCEPT \
303+
{ \
304+
inner = alternative; \
305+
return *this; \
306+
}
298307

299308
/// Argument placeholders.
300309
/// ---------------------------------------------------------------------------

include/bitcoin/system/unicode/ascii.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ BC_API bool has_mixed_ascii_case(const std::string_view& text) NOEXCEPT;
4949
/// True if all characters are in the ASCII subset of UTF8 [<128].
5050
BC_API bool is_ascii(const std::string_view& text) NOEXCEPT;
5151

52+
/// True if all characters are in the ASCII subset 'a'..'z' and 'A'..'Z'.
53+
BC_API bool is_ascii_alphabet(const std::string_view& text) NOEXCEPT;
54+
5255
/// True if all characters are in the ASCII subset '0'..'9' with a leading '-'
5356
/// character if specified. Leaving zeroes allowed, including after negative.
5457
BC_API bool is_ascii_numeric(const std::string_view& text) NOEXCEPT;

src/unicode/ascii.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ bool is_ascii(const std::string_view& text) NOEXCEPT
3333
return std::all_of(text.begin(), text.end(), is_ascii_character);
3434
}
3535

36+
bool is_ascii_alphabet(const std::string_view& text) NOEXCEPT
37+
{
38+
if (text.empty())
39+
return true;
40+
41+
return std::all_of(text.begin(), text.end(), is_ascii_alpha);
42+
}
43+
3644
bool is_ascii_numeric(const std::string_view& text) NOEXCEPT
3745
{
3846
if (text.empty())

test/serial/deserialize.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ BOOST_AUTO_TEST_CASE(deserialize__uint8__uint8__base10)
7373
BOOST_REQUIRE_EQUAL(out, 0u);
7474
BOOST_REQUIRE(deserialize(out, "255"));
7575
BOOST_REQUIRE_EQUAL(out, 0xff);
76+
BOOST_REQUIRE(!deserialize(out, "256"));
7677
}
7778

7879
BOOST_AUTO_TEST_CASE(deserialize__uint8__uchar__base10)
@@ -362,6 +363,24 @@ BOOST_AUTO_TEST_CASE(deserialize__uint16__min_max__true)
362363
BOOST_REQUIRE_EQUAL(out, 0xffff);
363364
}
364365

366+
BOOST_AUTO_TEST_CASE(deserialize__uint16__min_max_leading_zeros__true)
367+
{
368+
uint16_t out;
369+
BOOST_REQUIRE(deserialize(out, "000"));
370+
BOOST_REQUIRE_EQUAL(out, 0u);
371+
BOOST_REQUIRE(deserialize(out, "0065535"));
372+
BOOST_REQUIRE_EQUAL(out, 0xffff);
373+
}
374+
375+
BOOST_AUTO_TEST_CASE(deserialize__uint16__min_max_padded__true)
376+
{
377+
uint16_t out;
378+
BOOST_REQUIRE(deserialize(out, " 0 "));
379+
BOOST_REQUIRE_EQUAL(out, 0u);
380+
BOOST_REQUIRE(deserialize(out, " 65535 "));
381+
BOOST_REQUIRE_EQUAL(out, 0xffff);
382+
}
383+
365384
BOOST_AUTO_TEST_CASE(deserialize__uint32__min_max__true)
366385
{
367386
uint32_t out;

test/unicode/ascii.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,30 @@ BOOST_AUTO_TEST_CASE(ascii__is_ascii_numeric__decimal_numeric__false)
328328
BOOST_REQUIRE(!is_ascii_numeric("-.42"));
329329
}
330330

331+
// is_ascii_alphabet
332+
333+
BOOST_AUTO_TEST_CASE(ascii__is_ascii_alphabet__empty__true)
334+
{
335+
BOOST_REQUIRE(is_ascii_alphabet(""));
336+
}
337+
338+
BOOST_AUTO_TEST_CASE(ascii__is_ascii_alphabet__numeric__false)
339+
{
340+
BOOST_REQUIRE(!is_ascii_alphabet("0123456789"));
341+
}
342+
343+
BOOST_AUTO_TEST_CASE(ascii__is_ascii_alphabet__alphabet_true)
344+
{
345+
BOOST_REQUIRE(is_ascii_alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
346+
}
347+
348+
BOOST_AUTO_TEST_CASE(ascii__is_ascii_alphabet__padded_alphabet_false)
349+
{
350+
BOOST_REQUIRE(!is_ascii_alphabet(" abc"));
351+
BOOST_REQUIRE(!is_ascii_alphabet("abc "));
352+
BOOST_REQUIRE(!is_ascii_alphabet(" abc "));
353+
}
354+
331355
// ascii_to_lower
332356

333357
BOOST_AUTO_TEST_CASE(ascii__ascii_to_lower__empty__empty)

0 commit comments

Comments
 (0)