File tree Expand file tree Collapse file tree
include/bitcoin/system/unicode Expand file tree Collapse file tree Original file line number Diff line number Diff 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].
5050BC_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.
5457BC_API bool is_ascii_numeric(const std::string_view& text) NOEXCEPT;
Original file line number Diff line number Diff 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+
3644bool is_ascii_numeric(const std::string_view& text) NOEXCEPT
3745{
3846 if (text.empty())
Original file line number Diff line number Diff 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
333357BOOST_AUTO_TEST_CASE(ascii__ascii_to_lower__empty__empty)
You can’t perform that action at this time.
0 commit comments