File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,17 @@ inline bool isPrint(char C) {
140
140
return (0x20 <= UC) && (UC <= 0x7E );
141
141
}
142
142
143
+ // / Checks whether character \p C is a punctuation character.
144
+ // /
145
+ // / Locale-independent version of the C standard library ispunct. The list of
146
+ // / punctuation characters can be found in the documentation of std::ispunct:
147
+ // / https://en.cppreference.com/w/cpp/string/byte/ispunct.
148
+ inline bool isPunct (char C) {
149
+ static constexpr StringLiteral Punctuations =
150
+ R"( !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)" ;
151
+ return Punctuations.contains (C);
152
+ }
153
+
143
154
// / Checks whether character \p C is whitespace in the "C" locale.
144
155
// /
145
156
// / Locale-independent version of the C standard library isspace.
Original file line number Diff line number Diff line change @@ -59,6 +59,18 @@ TEST(StringExtrasTest, isUpper) {
59
59
EXPECT_FALSE (isUpper (' \? ' ));
60
60
}
61
61
62
+ TEST (StringExtrasTest, isPunct) {
63
+ EXPECT_FALSE (isPunct (' a' ));
64
+ EXPECT_FALSE (isPunct (' b' ));
65
+ EXPECT_FALSE (isPunct (' z' ));
66
+ EXPECT_TRUE (isPunct (' -' ));
67
+ EXPECT_TRUE (isPunct (' ;' ));
68
+ EXPECT_TRUE (isPunct (' @' ));
69
+ EXPECT_FALSE (isPunct (' 0' ));
70
+ EXPECT_FALSE (isPunct (' 1' ));
71
+ EXPECT_FALSE (isPunct (' x' ));
72
+ }
73
+
62
74
template <class ContainerT > void testJoin () {
63
75
ContainerT Items;
64
76
EXPECT_EQ (" " , join (Items.begin (), Items.end (), " <sep> " ));
You can’t perform that action at this time.
0 commit comments