Skip to content

Commit 266fe34

Browse files
committed
#60 - Implement method is_punctuation
Completed.
1 parent afa1687 commit 266fe34

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

cpp-strings/cppstrings.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
int main()
2828
{
29-
CppString s;
29+
CppString s;
30+
CppWString ws;
31+
3032
return 0;
3133
}

cpp-strings/cppstrings.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
//=============================================================
2424
#include <string>
25+
#include <vector>
2526
//#include <initializer_list>
2627

2728

@@ -31,7 +32,7 @@ template<
3132
class CharT,
3233
class TraitsT = std::char_traits<CharT>,
3334
class AllocatorT = std::allocator<CharT>
34-
> class CppStringT; //!< The templated base class. Use its specializations instead!
35+
> class CppStringT; //!< The templated base class. Use its belowing specializations instead!
3536

3637
using CppString = CppStringT<char>; //!< Specialization of basic class with template argument 'char'
3738
using CppWString = CppStringT<wchar_t>; //!< Specialization of basic class with template argument 'wchar_t'
@@ -62,7 +63,7 @@ template<class CharT, class TraitsT, class AllocatorT>
6263
class CppStringT : public std::basic_string<CharT>
6364
{
6465
public:
65-
//--- Wrappers ----------------------------------------
66+
//=== Wrappers ========================================
6667
using MyBaseClass = std::basic_string<CharT>;
6768

6869
using traits_type = MyBaseClass::traits_type;
@@ -80,7 +81,7 @@ class CppStringT : public std::basic_string<CharT>
8081
using const_reverse_iterator = MyBaseClass::const_reverse_iterator;
8182

8283

83-
//--- Constructors ------------------------------------
84+
//=== Constructors ====================================
8485
inline CppStringT() : MyBaseClass() {}
8586
inline CppStringT(const CppStringT& other) : MyBaseClass(other) {}
8687
inline CppStringT(const CppStringT& other, const AllocatorT& alloc) : MyBaseClass(other, alloc){}
@@ -103,12 +104,21 @@ class CppStringT : public std::basic_string<CharT>
103104
CppStringT(const StringViewLike& svl, size_type pos, size_type n) : MyBaseClass(svl, pos, n) {}
104105

105106

106-
//--- Methods -----------------------------------------
107+
//=== Methods =========================================
108+
109+
//--- is_punctuation ----------------------------------
110+
/** \brief Returns true if a character belongs to ASCII punctuation set. */
111+
inline const bool is_punctuation(const value_type ch) noexcept
112+
{
113+
return _ASCII_PUNCT_DATA.contains(ch);
114+
}
107115

108116

109117
protected:
110118

111119

112120
private:
121+
//=== DATA ============================================
122+
static inline constexpr std::vector<value_type> _ASCII_PUNCT_DATA{ '!', ',', '.', ':', ';', '?' };
113123

114124
};

0 commit comments

Comments
 (0)