Skip to content

Commit 4fe47b1

Browse files
[libc] add wcspbrk
1 parent 9dd063a commit 4fe47b1

File tree

8 files changed

+80
-0
lines changed

8 files changed

+80
-0
lines changed

libc/config/gpu/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ set(TARGET_LIBC_ENTRYPOINTS
261261
libc.src.time.nanosleep
262262

263263
# wchar.h entrypoints
264+
libc.src.wchar.wcspbrk
264265
libc.src.wchar.wcsrchr
265266
libc.src.wchar.wcschr
266267
libc.src.wchar.wcslen

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ set(TARGET_LIBC_ENTRYPOINTS
349349
libc.src.unistd.write
350350

351351
# wchar.h entrypoints
352+
libc.src.wchar.wcspbrk
352353
libc.src.wchar.wcsrchr
353354
libc.src.wchar.wcschr
354355
libc.src.wchar.wcslen

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ set(TARGET_LIBC_ENTRYPOINTS
346346
libc.src.unistd.write
347347

348348
# wchar.h entrypoints
349+
libc.src.wchar.wcspbrk
349350
libc.src.wchar.wcsrchr
350351
libc.src.wchar.wcschr
351352
libc.src.wchar.wcslen

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ set(TARGET_LIBC_ENTRYPOINTS
348348
libc.src.unistd.write
349349

350350
# wchar.h entrypoints
351+
libc.src.wchar.wcspbrk
351352
libc.src.wchar.wcsrchr
352353
libc.src.wchar.wcschr
353354
libc.src.wchar.wcslen

libc/hdrgen/yaml/wchar.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@ functions:
4242
arguments:
4343
- type: const wchar_t *
4444
- type: wchar_t
45+
- name: wcspbrk
46+
standards:
47+
- stdc
48+
return_type: const wchar_t *
49+
arguments:
50+
- type: const wchar_t *
51+
- type: const wchar_t *

libc/src/wchar/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,14 @@ add_entrypoint_object(
6969
.wcslen
7070
libc.hdr.types.wchar_t
7171
)
72+
73+
add_entrypoint_object(
74+
wcspbrk
75+
SRCS
76+
wcspbrk.cpp
77+
HDRS
78+
wcspbrk.h
79+
DEPENDS
80+
.wcslen
81+
libc.hdr.types.wchar_t
82+
)

libc/src/wchar/wcspbrk.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===-- Implementation of wcspbrk -----------------------------------------===//
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+
#include "src/wchar/wcspbrk.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/macros/config.h"
12+
#include "wcslen.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(const wchar_t *, wcspbrk,
17+
(const wchar_t *wcs, const wchar_t *accept)) {
18+
size_t n_accept = wcslen(accept);
19+
20+
for (size_t i = 0; i < wcslen(wcs); i++) {
21+
bool accepted = true;
22+
23+
for (size_t x = 0; x < n_accept; i++) {
24+
if (wcs[i] != accept[x]) {
25+
accepted = false;
26+
break;
27+
}
28+
}
29+
30+
if (!accepted)
31+
continue;
32+
return &wcs[i];
33+
}
34+
return nullptr;
35+
}
36+
37+
} // namespace LIBC_NAMESPACE_DECL

libc/src/wchar/wcspbrk.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for wcspbrk -----------------------*- 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 LLVM_LIBC_SRC_WCHAR_WCSPBRK_H
10+
#define LLVM_LIBC_SRC_WCHAR_WCSPBRK_H
11+
12+
#include "hdr/types/wchar_t.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
const wchar_t *wcspbrk(const wchar_t *wcs, const wchar_t *accept);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_WCHAR_WCSPBRK_H

0 commit comments

Comments
 (0)