Skip to content

Commit 863ef3c

Browse files
committed
Add/test is_ascii_alphabet.
1 parent d24351f commit 863ef3c

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

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/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)