Path: blob/main/contrib/llvm-project/libcxx/include/__filesystem/u8path.h
35262 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//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//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___FILESYSTEM_U8PATH_H10#define _LIBCPP___FILESYSTEM_U8PATH_H1112#include <__algorithm/unwrap_iter.h>13#include <__config>14#include <__filesystem/path.h>15#include <string>1617// Only required on Windows for __widen_from_utf8, and included conservatively18// because it requires support for localization.19#if defined(_LIBCPP_WIN32API)20# include <locale>21#endif2223#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)24# pragma GCC system_header25#endif2627#if _LIBCPP_STD_VER >= 172829_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM3031_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH3233template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>34_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _InputIt __l) {35static_assert(36# ifndef _LIBCPP_HAS_NO_CHAR8_T37is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||38# endif39is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,40"u8path(Iter, Iter) requires Iter have a value_type of type 'char'"41" or 'char8_t'");42# if defined(_LIBCPP_WIN32API)43string __tmp(__f, __l);44using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;45std::wstring __w;46__w.reserve(__tmp.size());47_CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());48return path(__w);49# else50return path(__f, __l);51# endif /* !_LIBCPP_WIN32API */52}5354# if defined(_LIBCPP_WIN32API)55template <class _InputIt, __enable_if_t<__is_pathable<_InputIt>::value, int> = 0>56_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _NullSentinel) {57static_assert(58# ifndef _LIBCPP_HAS_NO_CHAR8_T59is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value ||60# endif61is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,62"u8path(Iter, Iter) requires Iter have a value_type of type 'char'"63" or 'char8_t'");64string __tmp;65const char __sentinel = char{};66for (; *__f != __sentinel; ++__f)67__tmp.push_back(*__f);68using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>;69std::wstring __w;70__w.reserve(__tmp.size());71_CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size());72return path(__w);73}74# endif /* _LIBCPP_WIN32API */7576template <class _Source, __enable_if_t<__is_pathable<_Source>::value, int> = 0>77_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(const _Source& __s) {78static_assert(79# ifndef _LIBCPP_HAS_NO_CHAR8_T80is_same<typename __is_pathable<_Source>::__char_type, char8_t>::value ||81# endif82is_same<typename __is_pathable<_Source>::__char_type, char>::value,83"u8path(Source const&) requires Source have a character type of type "84"'char' or 'char8_t'");85# if defined(_LIBCPP_WIN32API)86using _Traits = __is_pathable<_Source>;87return u8path(std::__unwrap_iter(_Traits::__range_begin(__s)), std::__unwrap_iter(_Traits::__range_end(__s)));88# else89return path(__s);90# endif91}9293_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP9495_LIBCPP_END_NAMESPACE_FILESYSTEM9697#endif // _LIBCPP_STD_VER >= 179899#endif // _LIBCPP___FILESYSTEM_U8PATH_H100101102