[llvm] [ADT] Add `isPunct` to StringExtras (PR #105461)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 20:48:17 PDT 2024
================
@@ -380,3 +382,14 @@ TEST(StringExtrasTest, arrayToStringRef) {
roundTripTestString("\0\n");
roundTripTestString("\xFF\xFE");
}
+
+TEST(StringExtrasTest, isPunct) {
+ // Loop over all valid char values and verify that llvm::isPunct matched
+ // std::ispunct(). Limit to first 256 characters in case CHAR_BIT > 8.
+ int Count = 0;
+ for (char C = std::numeric_limits<char>::min(); Count < 256; ++C) {
+ EXPECT_EQ(static_cast<bool>(std::ispunct(C)), isPunct(C));
----------------
s-barannikov wrote:
> Or just have a curated list of punct and non punct characters?
Maybe just check a few? There are tests at the beginning of this file that test similar interfaces, they don't check all possible values.
I'm not very familiar with locales either, and it is possible that calling `std::ispunct` is totally safe here (or can be made safe by setting C locale).
https://github.com/llvm/llvm-project/pull/105461
More information about the llvm-commits
mailing list