1f3b41502Scgyurgyik //===-- Implementation of strspn ------------------------------------------===// 2f3b41502Scgyurgyik // 3f3b41502Scgyurgyik // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4f3b41502Scgyurgyik // See https://llvm.org/LICENSE.txt for license information. 5f3b41502Scgyurgyik // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6f3b41502Scgyurgyik // 7f3b41502Scgyurgyik //===----------------------------------------------------------------------===// 8f3b41502Scgyurgyik 9f3b41502Scgyurgyik #include "src/string/strspn.h" 10f3b41502Scgyurgyik 11e2d79758SGuillaume Chatelet #include "src/__support/CPP/bitset.h" 12f3b41502Scgyurgyik #include "src/__support/common.h" 13*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 14f3b41502Scgyurgyik #include <stddef.h> 15f3b41502Scgyurgyik 16*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 17f3b41502Scgyurgyik 18a0b65a7bSMichael Jones LLVM_LIBC_FUNCTION(size_t, strspn, (const char *src, const char *segment)) { 19f3b41502Scgyurgyik const char *initial = src; 20e2d79758SGuillaume Chatelet cpp::bitset<256> bitset; 21f3b41502Scgyurgyik 22f3b41502Scgyurgyik for (; *segment; ++segment) 2396ff2124SAlex Brachet bitset.set(*reinterpret_cast<const unsigned char *>(segment)); 2496ff2124SAlex Brachet for (; *src && bitset.test(*reinterpret_cast<const unsigned char *>(src)); 2596ff2124SAlex Brachet ++src) 26f3b41502Scgyurgyik ; 27f3b41502Scgyurgyik return src - initial; 28f3b41502Scgyurgyik } 29f3b41502Scgyurgyik 30*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 31