@@ -64,7 +64,10 @@ namespace pcs // i.e. "pythonic c++ strings"
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
6666 template <class CharT >
67- inline const bool is_lower (const CharT ch) noexcept ; // !< Returns true if character is lowercase, or false otherwise.
67+ inline const bool is_lower (const CharT ch) noexcept ; // !< Returns true if character is lowercase, or false otherwise.
68+
69+ template <class CharT >
70+ inline const bool is_printable (const CharT ch) noexcept ; // !< Returns true if character ch is printable, or false otherwise.
6871
6972 template <class CharT >
7073 inline const bool is_punctuation (const CharT ch) noexcept ; // !< Returns true if character ch is punctuation, or false otherwise.
@@ -490,6 +493,19 @@ namespace pcs // i.e. "pythonic c++ strings"
490493 }
491494
492495
496+ // --- isprintable() -----------------------------------
497+ /* * \brief Returns true if all characters in the string are printable or if the string is empty, or false otherwise.
498+ *
499+ * Nonprintable characters are those characters defined in the Unicode
500+ * character database as Other or Separator, excepting the ASCII
501+ * space (0x20) which is considered printable.
502+ */
503+ inline const bool isprintable () const noexcept
504+ {
505+ return this ->empty () || std::all_of (this ->cbegin (), this ->cend (), pcs::is_printable<CharT>);
506+ }
507+
508+
493509 // --- ispunctuation() ---------------------------------
494510 /* * \brief Returns true if the string contains only one character and if this character belongs to the ASCII punctuation set. */
495511 inline const bool ispunctuation () const noexcept
@@ -788,6 +804,27 @@ namespace pcs // i.e. "pythonic c++ strings"
788804 }
789805
790806
807+ // --- is_printable() --------------------------------------
808+ /* * \brief SHOULD NEVER BE USED. Use next specializations instead. */
809+ template <class CharT >
810+ inline const bool is_printable (const CharT ch) noexcept
811+ { return false ; }
812+
813+ /* * \brief Returns true if character ch is printable, or false otherwise. */
814+ template <>
815+ inline const bool is_printable<char >(const char ch) noexcept
816+ {
817+ return std::isprint (static_cast <unsigned char >(ch));
818+ }
819+
820+ /* * \brief Returns true if character ch is punctuation, or false otherwise. Conforms to the current locale settings. */
821+ template <>
822+ inline const bool is_printable<wchar_t >(const wchar_t ch) noexcept
823+ {
824+ return std::iswprint (ch);
825+ }
826+
827+
791828 // --- is_punctuation() ------------------------------------
792829 /* * \brief SHOULD NEVER BE USED. Use next specializations instead. */
793830 template <class CharT >
0 commit comments