From 193d63c81becdfdec217a160afc714fc3d3a4bc2 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 12 Apr 2023 18:42:25 +0200 Subject: [PATCH] libluna+libc: Add strpbrk() --- libc/include/string.h | 3 +++ libluna/include/luna/CString.h | 2 ++ libluna/src/CString.cpp | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/libc/include/string.h b/libc/include/string.h index 613c187d..cf66fbe4 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -65,6 +65,9 @@ extern "C" /* Return the length of the initial segment of str which consists only of bytes not in reject. */ size_t strcspn(const char* str, const char* reject); + /* Return a pointer to the first occurrence of any of the characters in accept in s. */ + char* strpbrk(const char* s, const char* delim); + /* Separate a string into several tokens. */ char* strtok(char* str, const char* delim); diff --git a/libluna/include/luna/CString.h b/libluna/include/luna/CString.h index d5a13b16..fb2598d9 100644 --- a/libluna/include/luna/CString.h +++ b/libluna/include/luna/CString.h @@ -34,4 +34,6 @@ extern "C" char* strchr(const char* str, int c); char* strrchr(const char* str, int c); + + char* strpbrk(const char* s, const char* accept); } diff --git a/libluna/src/CString.cpp b/libluna/src/CString.cpp index caf5d59a..7dc32ac6 100644 --- a/libluna/src/CString.cpp +++ b/libluna/src/CString.cpp @@ -237,4 +237,15 @@ extern "C" return nullptr; } + + char* strpbrk(const char* s, const char* accept) + { + usize index = strcspn(s, accept); + + const char* ptr = s + index; + + if (*ptr) return const_cast(ptr); + + return nullptr; + } }