Path: blob/main/system/lib/llvm-libc/src/wchar/wcstok.cpp
6174 views
//===-- Implementation of wcstok ------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "src/wchar/wcstok.h"910#include "hdr/types/wchar_t.h"11#include "src/__support/common.h"1213namespace LIBC_NAMESPACE_DECL {1415bool isADelimeter(wchar_t wc, const wchar_t *delimiters) {16for (const wchar_t *delim_ptr = delimiters; *delim_ptr != L'\0'; ++delim_ptr)17if (wc == *delim_ptr)18return true;19return false;20}2122LLVM_LIBC_FUNCTION(wchar_t *, wcstok,23(wchar_t *__restrict str, const wchar_t *__restrict delim,24wchar_t **__restrict context)) {25if (str == nullptr) {26if (*context == nullptr)27return nullptr;2829str = *context;30}3132wchar_t *tok_start, *tok_end;33for (tok_start = str; *tok_start != L'\0' && isADelimeter(*tok_start, delim);34++tok_start)35;3637for (tok_end = tok_start; *tok_end != L'\0' && !isADelimeter(*tok_end, delim);38++tok_end)39;4041if (*tok_end != L'\0') {42*tok_end = L'\0';43++tok_end;44}45*context = tok_end;46return *tok_start == L'\0' ? nullptr : tok_start;47}4849} // namespace LIBC_NAMESPACE_DECL505152