brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 55a3cee Raw
43 lines · c
1//===-- wchar utils ---------------------------------------------*- 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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC_WCHAR_WCHAR_UTILS_H10#define LLVM_LIBC_SRC_WCHAR_WCHAR_UTILS_H11 12#include "hdr/types/size_t.h"13#include "hdr/types/wchar_t.h"14#include "src/__support/common.h"15#include "src/__support/macros/attributes.h" // LIBC_INLINE16 17namespace LIBC_NAMESPACE_DECL {18namespace internal {19 20LIBC_INLINE static const wchar_t *wcschr(const wchar_t *s, wchar_t c) {21  for (; *s && *s != c; ++s)22    ;23  return (*s == c) ? s : nullptr;24}25 26// bool should be true for wcscspn for complimentary span27// should be false for wcsspn since we want it to span28LIBC_INLINE static size_t wcsspn(const wchar_t *s1, const wchar_t *s2,29                                 bool not_match_set) {30  size_t i = 0;31  for (; s1[i]; ++i) {32    bool in_set = internal::wcschr(s2, s1[i]);33    if (in_set == not_match_set)34      return i;35  }36  return i;37}38 39} // namespace internal40} // namespace LIBC_NAMESPACE_DECL41 42#endif //  LLVM_LIBC_SRC_WCHAR_WCHAR_UTILS_H43