Skip to content

Commit 4ee68e3

Browse files
committed
#32 - Implement method CppStringT::isupper()
Completed.
1 parent bee370f commit 4ee68e3

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

cpp-strings/cppstrings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int main()
3232
CppString s;
3333
CppWString ws;
3434

35-
//std::cout << ws.isspace() << std::endl;
35+
std::cout << ws.isupper() << std::endl;
3636

3737
return 0;
3838
}

cpp-strings/cppstrings.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ namespace pcs // i.e. "pythonic c++ strings"
7575
template<class CharT>
7676
inline const bool is_space(const CharT ch) noexcept; //!< Returns true if character ch is white space, or false otherwise.
7777

78+
template<class CharT>
79+
inline const bool is_upper(const CharT ch) noexcept; //!< Returns true if character is uppercase, or false otherwise.
80+
7881

7982

8083
//===== CppStringT<> ======================================
@@ -534,6 +537,14 @@ namespace pcs // i.e. "pythonic c++ strings"
534537
}
535538

536539

540+
//--- isupper() ---------------------------------------
541+
/** \brief Returns true if all cased characters in the string are uppercase and there is at least one cased character, or false otherwise. */
542+
inline const bool isupper() const noexcept
543+
{
544+
return !this->empty() && std::all_of(this->cbegin(), this->cend(), pcs::is_upper<CharT>);
545+
}
546+
547+
537548
//--- is_words_sep() ----------------------------------
538549
/** \brief Returns true if there are only whitespace and punctuation characters in the string and there is at least one character, or false otherwise. */
539550
inline const bool is_words_sep() const noexcept
@@ -879,4 +890,26 @@ namespace pcs // i.e. "pythonic c++ strings"
879890
{ return std::iswspace(ch); }
880891

881892

893+
//--- is_upper() ------------------------------------------
894+
/** \brief SHOULD NEVER BE USED. Use next specializations instead. */
895+
template<class CharT>
896+
inline const bool is_upper(const CharT ch) noexcept
897+
{
898+
return false;
899+
}
900+
901+
/** \brief Returns true if character ch is uppercase, or false otherwise. Conforms to the current locale settings. */
902+
template<>
903+
inline const bool is_upper<char>(const char ch) noexcept
904+
{
905+
return std::isupper(static_cast<unsigned char>(ch));
906+
}
907+
908+
/** \brief Returns true if character ch is uppercase, or false otherwise. Conforms to the current locale settings. */
909+
template<>
910+
inline const bool is_upper<wchar_t>(const wchar_t ch) noexcept
911+
{
912+
return std::iswupper(ch);
913+
}
914+
882915
} // end of namespace pcs // (pythonic c++ strings)

0 commit comments

Comments
 (0)