Skip to content

Commit 0f1e18f

Browse files
committed
#71 - Modify method is_punctuation()
Completed.
1 parent 6ca96ba commit 0f1e18f

File tree

1 file changed

+46
-14
lines changed

1 file changed

+46
-14
lines changed

cpp-strings/cppstrings.h

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,26 @@ namespace pcs // i.e. "pythonic c++ strings"
4141
class CharT,
4242
class TraitsT = std::char_traits<CharT>,
4343
class AllocatorT = std::allocator<CharT>
44-
> class CppStringT; //!< The templated base class. Use its belowing specializations instead!
44+
> 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);
52+
inline const bool is_alpha(const CharT ch); //!< Returns true if character ch is alphabetic, or false otherwise. */
53+
54+
template<class CharT>
55+
inline const bool is_punctuation(const CharT ch); //!< Returns true if character ch is punctuation, or false otherwise. */
56+
57+
template<class CharT>
58+
inline const bool is_space(const CharT ch); //!< Returns true if character ch is white space, or false otherwise. */
5359

5460

5561

5662
//===== CppStringT<> ======================================
57-
/**
58-
* \brief This is the templated base class for all CppString
59-
* classes.
63+
/** \brief This is the templated base class for all CppString classes.
6064
*
6165
* Users should instantiate any specialization of this base class
6266
* rather than this base class itself:
@@ -405,13 +409,7 @@ namespace pcs // i.e. "pythonic c++ strings"
405409
/** \brief Returns true if the string contains only one character and if this character belongs to the ASCII punctuation set. */
406410
inline const bool is_punctuation() const noexcept
407411
{
408-
return this->size() == 1 && is_punctuation((*this)[0]);
409-
}
410-
411-
/** \brief Returns true if character belongs to the ASCII punctuation set. */
412-
static inline const bool is_punctuation(const value_type& ch) noexcept
413-
{
414-
return _ASCII_PUNCT_DATA.contains(ch);
412+
return this->size() == 1 && pcs::is_punctuation((*this)[0]);
415413
}
416414

417415

@@ -665,4 +663,38 @@ namespace pcs // i.e. "pythonic c++ strings"
665663
template<>
666664
inline const bool is_alpha<wchar_t>(const wchar_t ch) { return std::iswalpha(ch); }
667665

666+
667+
//--- is_punctuation ----------------------------------
668+
/** \brief SHOULD NEVER BE USED. Use next specializations instead. */
669+
template<class CharT>
670+
inline const bool is_punctuation(const CharT ch)
671+
{
672+
static const std::vector<CharT> punct_chars{ '!', ',', '.', ':', ';', '?' };
673+
return std::find(punct_chars.cbegin(), punct_chars.cend(), (ch)) != punct_chars.cend();
674+
}
675+
676+
/** \brief Returns true if character ch is punctuation, or false otherwise. Conforms to the current locale settings. */
677+
/*
678+
template<>
679+
inline const bool is_punctuation<char>(const char ch)
680+
{
681+
static const std::vector<char> punct_chars { '!', ',', '.', ':', ';', '?' };
682+
return std::find(punct_chars.cbegin(), punct_chars.cend(), (ch)) != punct_chars.cend();
683+
}
684+
*/
685+
686+
/** \brief Returns true if character ch is punctuation, or false otherwise. Conforms to the current locale settings. */
687+
/*
688+
template<>
689+
inline const bool is_punctuation<wchar_t>(const wchar_t ch)
690+
{
691+
static const std::vector<wchar_t> punct_chars{ '!', ',', '.', ':', ';', '?' };
692+
return std::find(punct_chars.cbegin(), punct_chars.cend(), (ch)) != punct_chars.cend();
693+
}
694+
*/
695+
696+
//--- is_space() --------------------------------------
697+
template<class CharT>
698+
inline const bool is_space(const CharT ch); //!< Returns true if character ch is white space, or false otherwise. */
699+
668700
} // end of namespace pcs // (pythonic c++ strings)

0 commit comments

Comments
 (0)