@@ -690,6 +690,13 @@ typedef string __path_string;
690
690
typedef char __path_value;
691
691
#endif
692
692
693
+ #if defined(_LIBCPP_WIN32API)
694
+ _LIBCPP_FUNC_VIS
695
+ size_t __wide_to_char (const wstring&, char *, size_t );
696
+ _LIBCPP_FUNC_VIS
697
+ size_t __char_to_wide (const string&, wchar_t *, size_t );
698
+ #endif
699
+
693
700
template <class _ECharT >
694
701
struct _PathCVT ;
695
702
@@ -793,6 +800,48 @@ struct _PathCVT<__path_value> {
793
800
};
794
801
795
802
#if defined(_LIBCPP_WIN32API)
803
+ template <>
804
+ struct _PathCVT <char > {
805
+
806
+ static void
807
+ __append_string (__path_string& __dest, const basic_string<char > &__str) {
808
+ size_t __size = __char_to_wide (__str, nullptr , 0 );
809
+ size_t __pos = __dest.size ();
810
+ __dest.resize (__pos + __size);
811
+ __char_to_wide (__str, const_cast <__path_value*>(__dest.data ()) + __pos, __size);
812
+ }
813
+
814
+ template <class _Iter >
815
+ static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type
816
+ __append_range (__path_string& __dest, _Iter __b, _Iter __e) {
817
+ basic_string<char > __tmp (__b, __e);
818
+ __append_string (__dest, __tmp);
819
+ }
820
+
821
+ template <class _Iter >
822
+ static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type
823
+ __append_range (__path_string& __dest, _Iter __b, _Iter __e) {
824
+ basic_string<char > __tmp (__b, __e);
825
+ __append_string (__dest, __tmp);
826
+ }
827
+
828
+ template <class _Iter >
829
+ static void __append_range (__path_string& __dest, _Iter __b, _NullSentinel) {
830
+ const char __sentinel = char {};
831
+ basic_string<char > __tmp;
832
+ for (; *__b != __sentinel; ++__b)
833
+ __tmp.push_back (*__b);
834
+ __append_string (__dest, __tmp);
835
+ }
836
+
837
+ template <class _Source >
838
+ static void __append_source (__path_string& __dest, _Source const & __s) {
839
+ using _Traits = __is_pathable<_Source>;
840
+ __append_range (__dest, _Traits::__range_begin (__s),
841
+ _Traits::__range_end (__s));
842
+ }
843
+ };
844
+
796
845
template <class _ECharT >
797
846
struct _PathExport {
798
847
typedef __narrow_to_utf8<sizeof (wchar_t ) * __CHAR_BIT__> _Narrower;
@@ -806,6 +855,17 @@ struct _PathExport {
806
855
}
807
856
};
808
857
858
+ template <>
859
+ struct _PathExport <char > {
860
+ template <class _Str >
861
+ static void __append (_Str& __dest, const __path_string& __src) {
862
+ size_t __size = __wide_to_char (__src, nullptr , 0 );
863
+ size_t __pos = __dest.size ();
864
+ __dest.resize (__size);
865
+ __wide_to_char (__src, const_cast <char *>(__dest.data ()) + __pos, __size);
866
+ }
867
+ };
868
+
809
869
template <>
810
870
struct _PathExport <wchar_t > {
811
871
template <class _Str >
@@ -1110,7 +1170,11 @@ public:
1110
1170
return string<char >();
1111
1171
}
1112
1172
_LIBCPP_INLINE_VISIBILITY __u8_string u8string () const {
1113
- return string<__u8_string::value_type>();
1173
+ using _CVT = __narrow_to_utf8<sizeof (wchar_t ) * __CHAR_BIT__>;
1174
+ __u8_string __s;
1175
+ __s.reserve (__pn_.size ());
1176
+ _CVT ()(back_inserter (__s), __pn_.data (), __pn_.data () + __pn_.size ());
1177
+ return __s;
1114
1178
}
1115
1179
1116
1180
_LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string () const {
@@ -1373,9 +1437,42 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
1373
1437
is_same<typename __is_pathable<_InputIt>::__char_type, char >::value,
1374
1438
" u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
1375
1439
" or 'char8_t'" );
1440
+ #if defined(_LIBCPP_WIN32API)
1441
+ string __tmp (__f, __l);
1442
+ using _CVT = __widen_from_utf8<sizeof (wchar_t ) * __CHAR_BIT__>;
1443
+ _VSTD::wstring __w;
1444
+ __w.reserve (__tmp.size ());
1445
+ _CVT ()(back_inserter (__w), __tmp.data (), __tmp.data () + __tmp.size ());
1446
+ return path (__w);
1447
+ #else
1376
1448
return path (__f, __l);
1449
+ #endif /* !_LIBCPP_WIN32API */
1377
1450
}
1378
1451
1452
+ #if defined(_LIBCPP_WIN32API)
1453
+ template <class _InputIt >
1454
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
1455
+ typename enable_if<__is_pathable<_InputIt>::value, path>::type
1456
+ u8path (_InputIt __f, _NullSentinel) {
1457
+ static_assert (
1458
+ #ifndef _LIBCPP_NO_HAS_CHAR8_T
1459
+ is_same<typename __is_pathable<_InputIt>::__char_type, char8_t >::value ||
1460
+ #endif
1461
+ is_same<typename __is_pathable<_InputIt>::__char_type, char >::value,
1462
+ " u8path(Iter, Iter) requires Iter have a value_type of type 'char'"
1463
+ " or 'char8_t'" );
1464
+ string __tmp;
1465
+ const char __sentinel = char {};
1466
+ for (; *__f != __sentinel; ++__f)
1467
+ __tmp.push_back (*__f);
1468
+ using _CVT = __widen_from_utf8<sizeof (wchar_t ) * __CHAR_BIT__>;
1469
+ _VSTD::wstring __w;
1470
+ __w.reserve (__tmp.size ());
1471
+ _CVT ()(back_inserter (__w), __tmp.data (), __tmp.data () + __tmp.size ());
1472
+ return path (__w);
1473
+ }
1474
+ #endif /* _LIBCPP_WIN32API */
1475
+
1379
1476
template <class _Source >
1380
1477
_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
1381
1478
typename enable_if<__is_pathable<_Source>::value, path>::type
@@ -1387,7 +1484,12 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T
1387
1484
is_same<typename __is_pathable<_Source>::__char_type, char >::value,
1388
1485
" u8path(Source const&) requires Source have a character type of type "
1389
1486
" 'char' or 'char8_t'" );
1487
+ #if defined(_LIBCPP_WIN32API)
1488
+ using _Traits = __is_pathable<_Source>;
1489
+ return u8path (__unwrap_iter (_Traits::__range_begin (__s)), __unwrap_iter (_Traits::__range_end (__s)));
1490
+ #else
1390
1491
return path (__s);
1492
+ #endif
1391
1493
}
1392
1494
1393
1495
class _LIBCPP_TYPE_VIS path::iterator {
0 commit comments