[llvm] [ADT] Add `isPunct` to StringExtras (PR #105461)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 20:41:18 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));
----------------
jurahul wrote:

What's the alternative? (I'm unfamiliar with locale and related issues). Call setlocale(LC_CTYPE, "C") at the start of this function? Or just have a curated list of punct and non punct characters?

https://github.com/llvm/llvm-project/pull/105461


More information about the llvm-commits mailing list