brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 85513a6 Raw
49 lines · cpp
1//===-- Implementation of wcstok ------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/wchar/wcstok.h"10 11#include "hdr/types/wchar_t.h"12#include "src/__support/common.h"13#include "wchar_utils.h"14 15namespace LIBC_NAMESPACE_DECL {16 17LLVM_LIBC_FUNCTION(wchar_t *, wcstok,18                   (wchar_t *__restrict str, const wchar_t *__restrict delims,19                    wchar_t **__restrict context)) {20  if (str == nullptr) {21    if (*context == nullptr)22      return nullptr;23 24    str = *context;25  }26 27  wchar_t *tok_start = str;28  while (*tok_start != L'\0' && internal::wcschr(delims, *tok_start))29    ++tok_start;30  if (*tok_start == L'\0') {31    *context = nullptr;32    return nullptr;33  }34 35  wchar_t *tok_end = tok_start;36  while (*tok_end != L'\0' && !internal::wcschr(delims, *tok_end))37    ++tok_end;38 39  if (*tok_end == L'\0') {40    *context = nullptr;41  } else {42    *tok_end = L'\0';43    *context = tok_end + 1;44  }45  return tok_start;46}47 48} // namespace LIBC_NAMESPACE_DECL49