brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · ebdd51b Raw
94 lines · c
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___FILESYSTEM_U8PATH_H11#define _LIBCPP___FILESYSTEM_U8PATH_H12 13#include <__algorithm/unwrap_iter.h>14#include <__config>15#include <__filesystem/path.h>16#include <__locale>17#include <string>18 19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)20#  pragma GCC system_header21#endif22 23#if _LIBCPP_STD_VER >= 1724 25_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM26 27#  if !defined(_LIBCPP_WIN32API) || _LIBCPP_HAS_LOCALIZATION28template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>29_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _InputIt __l) {30  static_assert(31#    if _LIBCPP_HAS_CHAR8_T32      is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||33#    endif34          is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,35      "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"36      " or 'char8_t'");37#    if defined(_LIBCPP_WIN32API)38  string __tmp(__f, __l);39  using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;40  std::wstring __w;41  __w.reserve(__tmp.size());42  _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());43  return path(__w);44#    else45  return path(__f, __l);46#    endif // defined(_LIBCPP_WIN32API)47}48#  endif // !defined(_LIBCPP_WIN32API) || _LIBCPP_HAS_LOCALIZATION49 50#  if defined(_LIBCPP_WIN32API) && _LIBCPP_HAS_LOCALIZATION51template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>52_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _NullSentinel) {53  static_assert(54#    if _LIBCPP_HAS_CHAR8_T55      is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||56#    endif57          is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,58      "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"59      " or 'char8_t'");60  string __tmp;61  const char __sentinel = char{};62  for (; *__f != __sentinel; ++__f)63    __tmp.push_back(*__f);64  using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;65  std::wstring __w;66  __w.reserve(__tmp.size());67  _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());68  return path(__w);69}70#  endif // defined(_LIBCPP_WIN32API) && _LIBCPP_HAS_LOCALIZATION71 72template <class _Source, __enable_if_t<__is_pathable<_Source>::value, int> = 0>73_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(const _Source& __s) {74  static_assert(75#  if _LIBCPP_HAS_CHAR8_T76      is_same<typename __is_pathable<_Source>::__char_type, char8_t>::value ||77#  endif78          is_same<typename __is_pathable<_Source>::__char_type, char>::value,79      "u8path(Source const&) requires Source have a character type of type "80      "'char' or 'char8_t'");81#  if defined(_LIBCPP_WIN32API)82  using _Traits = __is_pathable<_Source>;83  return u8path(std::__unwrap_iter(_Traits::__range_begin(__s)), std::__unwrap_iter(_Traits::__range_end(__s)));84#  else85  return path(__s);86#  endif87}88 89_LIBCPP_END_NAMESPACE_FILESYSTEM90 91#endif // _LIBCPP_STD_VER >= 1792 93#endif // _LIBCPP___FILESYSTEM_U8PATH_H94