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 "src/string/memory_utils/utils.h"
13 
14 #include "utils/CPP/Bitset.h"
15 #include <stddef.h> // size_t
16 
17 namespace __llvm_libc {
18 namespace internal {
19 
20 // Returns the maximum length span that contains only characters not found in
21 // 'segment'. If no characters are found, returns the length of 'src'.
22 static inline size_t complementary_span(const char *src, const char *segment) {
23   const char *initial = src;
24   cpp::Bitset<256> bitset;
25 
26   for (; *segment; ++segment)
27     bitset.set(*segment);
28   for (; *src && !bitset.test(*src); ++src)
29     ;
30   return src - initial;
31 }
32 
33 } // namespace internal
34 } // namespace __llvm_libc
35 
36 #endif //  LIBC_SRC_STRING_STRING_UTILS_H
37