@@ -44,18 +44,21 @@ namespace pcs // i.e. "pythonic c++ strings"
4444 > class CppStringT ;
4545
4646 // specializations of the base class -- these are the ones that should be instantiated by user.
47- using CppString = CppStringT<char >; // !< Specialization of basic class with template argument 'char'
48- using CppWString = CppStringT<wchar_t >; // !< Specialization of basic class with template argument 'wchar_t'
47+ using CppString = CppStringT<char >; // !< Specialization of basic class with template argument 'char'
48+ using CppWString = CppStringT<wchar_t >; // !< Specialization of basic class with template argument 'wchar_t'
4949
5050 // chars classifications -- not to be directly called, see respective specializations at the very end of this module.
5151 template <class CharT >
52- inline const bool is_alpha (const CharT ch); // !< Returns true if character ch is alphabetic, or false otherwise. */
52+ inline const bool is_alpha (const CharT ch) noexcept ; // !< Returns true if character ch is alphabetic, or false otherwise.
5353
5454 template <class CharT >
55- inline const bool is_punctuation (const CharT ch); // !< Returns true if character ch is punctuation , or false otherwise. */
55+ inline const bool is_ascii (const CharT ch) noexcept ; // !< Returns true if character ch gets ASCII code , or false otherwise.
5656
5757 template <class CharT >
58- inline const bool is_space (const CharT ch); // !< Returns true if character ch is white space, or false otherwise. */
58+ inline const bool is_punctuation (const CharT ch) noexcept ; // !< Returns true if character ch is punctuation, or false otherwise.
59+
60+ template <class CharT >
61+ inline const bool is_space (const CharT ch) noexcept ; // !< Returns true if character ch is white space, or false otherwise.
5962
6063
6164
@@ -384,6 +387,17 @@ namespace pcs // i.e. "pythonic c++ strings"
384387 }
385388
386389
390+ // --- isascii() ---------------------------------------
391+ /* * \brief Returns true if the string is empty or all characters in the string are ASCII, or false otherwise. */
392+ #if defined(isascii) // may be already defined in header file <ctype>
393+ #undef isascii
394+ #endif
395+ inline const bool isascii () const noexcept
396+ {
397+ return this ->size () == 0 || std::all_of (this ->cbegin (), this ->cend (), pcs::is_ascii<CharT>);
398+ }
399+
400+
387401 // --- isdecimal() -------------------------------------
388402 inline const bool isdecimal () const noexcept
389403 {
@@ -413,7 +427,8 @@ namespace pcs // i.e. "pythonic c++ strings"
413427 }
414428
415429
416- // --- is_Returns true if there are only whitespace characters in the string and there is at least one character, or false otherwise. */-
430+ // --- isspace() ---------------------------------------
431+ /* * \brief Returns true if there are only whitespace characters in the string and there is at least one character, or false otherwise. */
417432 inline const bool isspace () const noexcept
418433 {
419434 if (this ->size () == 0 )
@@ -630,39 +645,52 @@ namespace pcs // i.e. "pythonic c++ strings"
630645 // --- is_alpha() ------------------------------------------
631646 /* * \brief SHOULD NEVER BE USED. Use next specializations instead. */
632647 template <class CharT >
633- inline const bool is_alpha (const CharT ch) { return false ; }
648+ inline const bool is_alpha (const CharT ch) noexcept
649+ { return false ; }
634650
635651 /* * \brief Returns true if character ch is alphabetic, or false otherwise. Conforms to the current locale settings. */
636652 template <>
637- inline const bool is_alpha<char >(const char ch) { return std::isalpha (static_cast <unsigned char >(ch)); }
653+ inline const bool is_alpha<char >(const char ch) noexcept
654+ { return std::isalpha (static_cast <unsigned char >(ch)); }
638655
639656 /* * \brief Returns true if character ch is alphabetic, or false otherwise. Conforms to the current locale settings. */
640657 template <>
641- inline const bool is_alpha<wchar_t >(const wchar_t ch) { return std::iswalpha (ch); }
658+ inline const bool is_alpha<wchar_t >(const wchar_t ch) noexcept
659+ { return std::iswalpha (ch); }
660+
661+
662+ // --- is_ascii() ------------------------------------------
663+ /* * \brief Returns true if character has code point in the range U+0000-U+007F. */
664+ template <class CharT >
665+ inline const bool is_ascii (const CharT ch) noexcept
666+ { return CharT (0x00 ) <= ch && ch <= CharT (0x7f ); }
642667
643668
644- // --- is_punctuation ----------------------------------
669+ // --- is_punctuation() -- ----------------------------------
645670 /* * \brief Returns true if character ch is punctuation, or false otherwise. Conforms to the current locale settings. */
646671 template <class CharT >
647- inline const bool is_punctuation (const CharT ch)
672+ inline const bool is_punctuation (const CharT ch) noexcept
648673 {
649674 static const std::vector<CharT> punct_chars{ ' !' , ' ,' , ' .' , ' :' , ' ;' , ' ?' };
650675 return std::find (punct_chars.cbegin (), punct_chars.cend (), (ch)) != punct_chars.cend ();
651676 }
652677
653678
654- // --- is_space() --------------------------------------
679+ // --- is_space() ------------------------------------------
655680 /* * \brief SHOULD NEVER BE USED. Use next specializations instead. */
656681 template <class CharT >
657- inline const bool is_space (const CharT ch) { return false ; }
682+ inline const bool is_space (const CharT ch) noexcept
683+ { return false ; }
658684
659685 /* * \brief Returns true if character ch is alphabetic, or false otherwise. Conforms to the current locale settings. */
660686 template <>
661- inline const bool is_space<char >(const char ch) { return std::isspace (static_cast <unsigned char >(ch)); }
687+ inline const bool is_space<char >(const char ch) noexcept
688+ { return std::isspace (static_cast <unsigned char >(ch)); }
662689
663690 /* * \brief Returns true if character ch is alphabetic, or false otherwise. Conforms to the current locale settings. */
664691 template <>
665- inline const bool is_space<wchar_t >(const wchar_t ch) { return std::iswspace (ch); }
692+ inline const bool is_space<wchar_t >(const wchar_t ch) noexcept
693+ { return std::iswspace (ch); }
666694
667695
668696} // end of namespace pcs // (pythonic c++ strings)
0 commit comments