1 //===-- String utils --------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LIBC_SRC_STRING_STRING_UTILS_H 10 #define LIBC_SRC_STRING_STRING_UTILS_H 11 12 #include "utils/CPP/Bitset.h" 13 #include <stddef.h> // size_t 14 15 namespace __llvm_libc { 16 namespace internal { 17 18 // Returns the maximum length span that contains only characters not found in 19 // 'segment'. If no characters are found, returns the length of 'src'. 20 static inline size_t complementary_span(const char *src, const char *segment) { 21 const char *initial = src; 22 cpp::Bitset<256> bitset; 23 24 for (; *segment; ++segment) 25 bitset.set(*segment); 26 for (; *src && !bitset.test(*src); ++src) 27 ; 28 return src - initial; 29 } 30 31 } // namespace internal 32 } // namespace __llvm_libc 33 34 #endif // LIBC_SRC_STRING_STRING_UTILS_H 35