[libc] [llvm] [libc] Cleaned up wcsspn and wcscspn (PR #147408)

Michael Jones via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 7 14:59:22 PDT 2025


================
@@ -12,23 +12,25 @@
 #include "hdr/types/wchar_t.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
+#include "wchar_utils.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-bool check(wchar_t c, const wchar_t *s2) {
-  for (int n = 0; s2[n]; ++n) {
-    if (s2[n] == c)
-      return false;
+struct CheckCSpan {
+  const wchar_t *str;
+  CheckCSpan(const wchar_t *w) { str = w; }
+  bool operator()(wchar_t c) {
+    for (int n = 0; str[n]; ++n) {
+      if (str[n] == c)
+        return false;
+    }
+    return true;
   }
-  return true;
-}
+};
----------------
michaelrj-google wrote:

this is almost identical to `CheckSpan`, so it should probably be merged with it. You could call the same function and just invert the result. Since you need to do that inside of `inline_wcsspn` you could template that function in a similar manner to `string_token` in string_utils.h.

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


More information about the llvm-commits mailing list