Skip to content

Commit b41823b

Browse files
committed
#27 - Implement method CppStringT::islower()
Completed.
1 parent 27edefc commit b41823b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

cpp-strings/cppstrings.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ namespace pcs // i.e. "pythonic c++ strings"
6363
template<class CharT>
6464
inline const bool is_id_start(const CharT ch) noexcept; //!< Returns true if character is a starting char for identifiers, or false otherwise.
6565

66+
template<class CharT>
67+
inline const bool is_lower(const CharT ch) noexcept; //!< Returns true if character is lowercase, or false otherwise.
68+
6669
template<class CharT>
6770
inline const bool is_punctuation(const CharT ch) noexcept; //!< Returns true if character ch is punctuation, or false otherwise.
6871

@@ -463,6 +466,14 @@ namespace pcs // i.e. "pythonic c++ strings"
463466
}
464467

465468

469+
//--- islower() ---------------------------------------
470+
/** \brief Returns true if all cased characters in the string are lowercase and there is at least one cased character, or false otherwise. */
471+
inline const bool islower() const noexcept
472+
{
473+
return !this->empty() && std::all_of(this->cbegin(), this->cend(), pcs::is_lower<CharT>);
474+
}
475+
476+
466477
//--- isnumeric() -------------------------------------
467478
inline const bool isnumeric() const noexcept
468479
{
@@ -745,6 +756,29 @@ namespace pcs // i.e. "pythonic c++ strings"
745756
{ return pcs::is_alpha(ch) || ch == CharT('_'); }
746757

747758

759+
//--- is_lower() ------------------------------------------
760+
/** \brief SHOULD NEVER BE USED. Use next specializations instead. */
761+
template<class CharT>
762+
inline const bool is_lower(const CharT ch) noexcept
763+
{
764+
return false;
765+
}
766+
767+
/** \brief Returns true if character ch is lowercase, or false otherwise. Conforms to the current locale settings. */
768+
template<>
769+
inline const bool is_lower<char>(const char ch) noexcept
770+
{
771+
return std::islower(static_cast<unsigned char>(ch));
772+
}
773+
774+
/** \brief Returns true if character ch is lowercase, or false otherwise. Conforms to the current locale settings. */
775+
template<>
776+
inline const bool is_lower<wchar_t>(const wchar_t ch) noexcept
777+
{
778+
return std::iswlower(ch);
779+
}
780+
781+
748782
//--- is_punctuation() ------------------------------------
749783
/** \brief SHOULD NEVER BE USED. Use next specializations instead. */
750784
template<class CharT>

0 commit comments

Comments
 (0)