summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2015-08-18 17:58:22 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2015-08-18 17:58:22 +0000
commit989575394506ef2f6f9f012a19e616fa818b0b3b (patch)
treebab32224d433f3cea0247063bd7836d67c255070 /libstdc++-v3/include/bits
parenta861752473fb992264ecdab938e77433a2107ac6 (diff)
downloadgcc-989575394506ef2f6f9f012a19e616fa818b0b3b.tar.gz
Backport Filesystem TS from mainline
* acinclude.m4 (GLIBCXX_ENABLE_FILESYSTEM_TS, GLIBCXX_CHECK_FILESYSTEM_DEPS): Define. * configure.ac: Use them. * configure: Regenerate. * config.h.in: Regenerate. * include/Makefile.am: Add filesystem headers. Fix order of headers. * include/Makefile.in: Regenerate. * include/bits/locale_conv.h (__do_str_codecvt, __str_codecvt_in, __str_codecvt_out, wstring_convert): Refactor to move all conversion logic to non-member functions. * include/bits/quoted_string.h (_Quoted_string, operator<<, operator>>): Move from <iomanip> to new header. * include/experimental/filesystem: New. * include/experimental/fs_dir.h: New. * include/experimental/fs_fwd.h: New. * include/experimental/fs_ops.h: New. * include/experimental/fs_path.h: New. * include/std/iomanip (_Quoted_string, operator<<, operator>>): Move to <bits/quoted_string.h>. * libstdcxx/v6/printers.py (StdExpPathPrinter): Define. * scripts/testsuite_flags.in: Add filesystem dir to ldflags. * src/Makefile.am: Add filesystem sub-dir. * src/Makefile.in: Regenerate. * src/filesystem/Makefile.am: New. * src/filesystem/Makefile.in: New. * src/filesystem/dir.cc: New. * src/filesystem/ops.cc: New. * src/filesystem/path.cc: New. * testsuite/experimental/filesystem/operations/absolute.cc: New. * testsuite/experimental/filesystem/operations/copy.cc: New. * testsuite/experimental/filesystem/operations/current_path.cc: New. * testsuite/experimental/filesystem/operations/exists.cc: New. * testsuite/experimental/filesystem/operations/file_size.cc: New. * testsuite/experimental/filesystem/operations/status.cc: New. * testsuite/experimental/filesystem/operations/temp_directory_path.cc: New. * testsuite/experimental/filesystem/path/append/path.cc: New. * testsuite/experimental/filesystem/path/assign/assign.cc: New. * testsuite/experimental/filesystem/path/assign/copy.cc: New. * testsuite/experimental/filesystem/path/compare/compare.cc: New. * testsuite/experimental/filesystem/path/compare/path.cc: New. * testsuite/experimental/filesystem/path/compare/strings.cc: New. * testsuite/experimental/filesystem/path/concat/path.cc: New. * testsuite/experimental/filesystem/path/concat/strings.cc: New. * testsuite/experimental/filesystem/path/construct/copy.cc: New. * testsuite/experimental/filesystem/path/construct/default.cc: New. * testsuite/experimental/filesystem/path/construct/locale.cc: New. * testsuite/experimental/filesystem/path/construct/range.cc: New. * testsuite/experimental/filesystem/path/decompose/extension.cc: New. * testsuite/experimental/filesystem/path/decompose/filename.cc: New. * testsuite/experimental/filesystem/path/decompose/parent_path.cc: New. * testsuite/experimental/filesystem/path/decompose/relative_path.cc: New. * testsuite/experimental/filesystem/path/decompose/root_directory.cc: New. * testsuite/experimental/filesystem/path/decompose/root_name.cc: New. * testsuite/experimental/filesystem/path/decompose/root_path.cc: New. * testsuite/experimental/filesystem/path/decompose/stem.cc: New. * testsuite/experimental/filesystem/path/generic/generic_string.cc: New. * testsuite/experimental/filesystem/path/itr/traversal.cc: New. * testsuite/experimental/filesystem/path/modifiers/clear.cc: New. * testsuite/experimental/filesystem/path/modifiers/make_preferred.cc: New. * testsuite/experimental/filesystem/path/modifiers/remove_filename.cc: New. * testsuite/experimental/filesystem/path/modifiers/ replace_extension.cc: New. * testsuite/experimental/filesystem/path/modifiers/replace_filename.cc: New. * testsuite/experimental/filesystem/path/modifiers/swap.cc: New. * testsuite/experimental/filesystem/path/nonmember/hash_value.cc: New. * testsuite/experimental/filesystem/path/query/empty.cc: New. * testsuite/experimental/filesystem/path/query/has_extension.cc: New. * testsuite/experimental/filesystem/path/query/has_filename.cc: New. * testsuite/experimental/filesystem/path/query/has_parent_path.cc: New. * testsuite/experimental/filesystem/path/query/has_relative_path.cc: New. * testsuite/experimental/filesystem/path/query/has_root_directory.cc: New. * testsuite/experimental/filesystem/path/query/has_root_name.cc: New. * testsuite/experimental/filesystem/path/query/has_root_path.cc: New. * testsuite/experimental/filesystem/path/query/has_stem.cc: New. * testsuite/experimental/filesystem/path/query/is_relative.cc: New. * testsuite/lib/dg-options.exp (dg-require-filesystem-ts): Define. * testsuite/lib/libstdc++.exp (check_v3_target_filesystem_ts): Define. * testsuite/util/testsuite_fs.h: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-5-branch@226983 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r--libstdc++-v3/include/bits/locale_conv.h189
-rw-r--r--libstdc++-v3/include/bits/quoted_string.h164
2 files changed, 290 insertions, 63 deletions
diff --git a/libstdc++-v3/include/bits/locale_conv.h b/libstdc++-v3/include/bits/locale_conv.h
index de49dd517fd..146f78b38d0 100644
--- a/libstdc++-v3/include/bits/locale_conv.h
+++ b/libstdc++-v3/include/bits/locale_conv.h
@@ -51,7 +51,114 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @{
*/
+ template<typename _OutStr, typename _InChar, typename _Codecvt,
+ typename _State, typename _Fn>
+ bool
+ __do_str_codecvt(const _InChar* __first, const _InChar* __last,
+ _OutStr& __outstr, const _Codecvt& __cvt, _State& __state,
+ size_t& __count, _Fn __fn)
+ {
+ if (__first == __last)
+ {
+ __outstr.clear();
+ __count = 0;
+ return true;
+ }
+
+ size_t __outchars = 0;
+ auto __next = __first;
+ const auto __maxlen = __cvt.max_length() + 1;
+
+ codecvt_base::result __result;
+ do
+ {
+ __outstr.resize(__outstr.size() + (__last - __next) * __maxlen);
+ auto __outnext = &__outstr.front() + __outchars;
+ auto const __outlast = &__outstr.back() + 1;
+ __result = (__cvt.*__fn)(__state, __next, __last, __next,
+ __outnext, __outlast, __outnext);
+ __outchars = __outnext - &__outstr.front();
+ }
+ while (__result == codecvt_base::partial && __next != __last
+ && (__outstr.size() - __outchars) < __maxlen);
+
+ if (__result == codecvt_base::error)
+ return false;
+
+ if (__result == codecvt_base::noconv)
+ {
+ __outstr.assign(__first, __last);
+ __count = __last - __first;
+ }
+ else
+ {
+ __outstr.resize(__outchars);
+ __count = __next - __first;
+ }
+
+ return true;
+ }
+
+ // Convert narrow character string to wide.
+ template<typename _CharT, typename _Traits, typename _Alloc, typename _State>
+ inline bool
+ __str_codecvt_in(const char* __first, const char* __last,
+ basic_string<_CharT, _Traits, _Alloc>& __outstr,
+ const codecvt<_CharT, char, _State>& __cvt,
+ _State& __state, size_t& __count)
+ {
+ using _Codecvt = codecvt<_CharT, char, _State>;
+ using _ConvFn
+ = codecvt_base::result
+ (_Codecvt::*)(_State&, const char*, const char*, const char*&,
+ _CharT*, _CharT*, _CharT*&) const;
+ _ConvFn __fn = &codecvt<_CharT, char, _State>::in;
+ return __do_str_codecvt(__first, __last, __outstr, __cvt, __state,
+ __count, __fn);
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc, typename _State>
+ inline bool
+ __str_codecvt_in(const char* __first, const char* __last,
+ basic_string<_CharT, _Traits, _Alloc>& __outstr,
+ const codecvt<_CharT, char, _State>& __cvt)
+ {
+ _State __state = {};
+ size_t __n;
+ return __str_codecvt_in(__first, __last, __outstr, __cvt, __state, __n);
+ }
+
+ // Convert wide character string to narrow.
+ template<typename _CharT, typename _Traits, typename _Alloc, typename _State>
+ inline bool
+ __str_codecvt_out(const _CharT* __first, const _CharT* __last,
+ basic_string<char, _Traits, _Alloc>& __outstr,
+ const codecvt<_CharT, char, _State>& __cvt,
+ _State& __state, size_t& __count)
+ {
+ using _Codecvt = codecvt<_CharT, char, _State>;
+ using _ConvFn
+ = codecvt_base::result
+ (_Codecvt::*)(_State&, const _CharT*, const _CharT*, const _CharT*&,
+ char*, char*, char*&) const;
+ _ConvFn __fn = &codecvt<_CharT, char, _State>::out;
+ return __do_str_codecvt(__first, __last, __outstr, __cvt, __state,
+ __count, __fn);
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc, typename _State>
+ inline bool
+ __str_codecvt_out(const _CharT* __first, const _CharT* __last,
+ basic_string<char, _Traits, _Alloc>& __outstr,
+ const codecvt<_CharT, char, _State>& __cvt)
+ {
+ _State __state = {};
+ size_t __n;
+ return __str_codecvt_out(__first, __last, __outstr, __cvt, __state, __n);
+ }
+
_GLIBCXX_BEGIN_NAMESPACE_CXX11
+
/// String conversions
template<typename _Codecvt, typename _Elem = wchar_t,
typename _Wide_alloc = allocator<_Elem>,
@@ -137,9 +244,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
wide_string
from_bytes(const char* __first, const char* __last)
{
- auto __errstr = _M_with_strings ? &_M_wide_err_string : nullptr;
- _ConvFn<char, _Elem> __fn = &_Codecvt::in;
- return _M_conv(__first, __last, __errstr, __fn);
+ if (!_M_with_cvtstate)
+ _M_state = state_type();
+ wide_string __out{ _M_wide_err_string.get_allocator() };
+ if (__str_codecvt_in(__first, __last, __out, *_M_cvt, _M_state,
+ _M_count))
+ return __out;
+ if (_M_with_strings)
+ return _M_wide_err_string;
+ __throw_range_error("wstring_convert::from_bytes");
}
/// @}
@@ -167,9 +280,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
byte_string
to_bytes(const _Elem* __first, const _Elem* __last)
{
- auto __errstr = _M_with_strings ? &_M_byte_err_string : nullptr;
- _ConvFn<_Elem, char> __fn = &_Codecvt::out;
- return _M_conv(__first, __last, __errstr, __fn);
+ if (!_M_with_cvtstate)
+ _M_state = state_type();
+ byte_string __out{ _M_byte_err_string.get_allocator() };
+ if (__str_codecvt_out(__first, __last, __out, *_M_cvt, _M_state,
+ _M_count))
+ return __out;
+ if (_M_with_strings)
+ return _M_byte_err_string;
+ __throw_range_error("wstring_convert::to_bytes");
}
/// @}
@@ -182,63 +301,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
state_type state() const { return _M_state; }
private:
- template<typename _InC, typename _OutC>
- using _ConvFn
- = codecvt_base::result
- (_Codecvt::*)(state_type&, const _InC*, const _InC*, const _InC*&,
- _OutC*, _OutC*, _OutC*&) const;
-
- template<typename _InChar, typename _OutStr, typename _MemFn>
- _OutStr
- _M_conv(const _InChar* __first, const _InChar* __last,
- const _OutStr* __err, _MemFn __memfn)
- {
- auto __outstr = __err ? _OutStr(__err->get_allocator()) : _OutStr();
-
- if (__first == __last)
- {
- _M_count = 0;
- return __outstr;
- }
-
- if (!_M_with_cvtstate)
- _M_state = state_type();
-
- size_t __outchars = 0;
- auto __next = __first;
- const auto __maxlen = _M_cvt->max_length() + 1;
-
- codecvt_base::result __result;
- do
- {
- __outstr.resize(__outstr.size() + (__last - __next) * __maxlen);
- auto __outnext = &__outstr.front() + __outchars;
- auto const __outlast = &__outstr.back() + 1;
- __result = ((*_M_cvt).*__memfn)(_M_state, __next, __last, __next,
- __outnext, __outlast, __outnext);
- __outchars = __outnext - &__outstr.front();
- }
- while (__result == codecvt_base::partial && __next != __last
- && (__outstr.size() - __outchars) < __maxlen);
-
- if (__result == codecvt_base::noconv)
- {
- __outstr.assign(__first, __last);
- _M_count = __outstr.size();
- return __outstr;
- }
-
- __outstr.resize(__outchars);
- _M_count = __next - __first;
-
- if (__result != codecvt_base::error)
- return __outstr;
- else if (__err)
- return *__err;
- else
- __throw_range_error("wstring_convert");
- }
-
unique_ptr<_Codecvt> _M_cvt;
byte_string _M_byte_err_string;
wide_string _M_wide_err_string;
@@ -247,6 +309,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
bool _M_with_cvtstate = false;
bool _M_with_strings = false;
};
+
_GLIBCXX_END_NAMESPACE_CXX11
/// Buffer conversions
diff --git a/libstdc++-v3/include/bits/quoted_string.h b/libstdc++-v3/include/bits/quoted_string.h
new file mode 100644
index 00000000000..7e75ce4b969
--- /dev/null
+++ b/libstdc++-v3/include/bits/quoted_string.h
@@ -0,0 +1,164 @@
+// Helpers for quoted stream manipulators -*- C++ -*-
+
+// Copyright (C) 2013-2015 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file bits/quoted_string.h
+ * This is an internal header file, included by other library headers.
+ * Do not attempt to use it directly. @headername{iomanip}
+ */
+
+#ifndef _GLIBCXX_QUOTED_STRING_H
+#define _GLIBCXX_QUOTED_STRING_H 1
+
+#pragma GCC system_header
+
+#if __cplusplus < 201103L
+# include <bits/c++0x_warning.h>
+#else
+#include <sstream>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+ namespace __detail {
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ /**
+ * @brief Struct for delimited strings.
+ */
+ template<typename _String, typename _CharT>
+ struct _Quoted_string
+ {
+ static_assert(is_reference<_String>::value
+ || is_pointer<_String>::value,
+ "String type must be pointer or reference");
+
+ _Quoted_string(_String __str, _CharT __del, _CharT __esc)
+ : _M_string(__str), _M_delim{__del}, _M_escape{__esc}
+ { }
+
+ _Quoted_string&
+ operator=(_Quoted_string&) = delete;
+
+ _String _M_string;
+ _CharT _M_delim;
+ _CharT _M_escape;
+ };
+
+ /**
+ * @brief Inserter for quoted strings.
+ *
+ * _GLIBCXX_RESOLVE_LIB_DEFECTS
+ * DR 2344 quoted()'s interaction with padding is unclear
+ */
+ template<typename _CharT, typename _Traits>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const _Quoted_string<const _CharT*, _CharT>& __str)
+ {
+ std::basic_ostringstream<_CharT, _Traits> __ostr;
+ __ostr << __str._M_delim;
+ for (const _CharT* __c = __str._M_string; *__c; ++__c)
+ {
+ if (*__c == __str._M_delim || *__c == __str._M_escape)
+ __ostr << __str._M_escape;
+ __ostr << *__c;
+ }
+ __ostr << __str._M_delim;
+
+ return __os << __ostr.str();
+ }
+
+ /**
+ * @brief Inserter for quoted strings.
+ *
+ * _GLIBCXX_RESOLVE_LIB_DEFECTS
+ * DR 2344 quoted()'s interaction with padding is unclear
+ */
+ template<typename _CharT, typename _Traits, typename _String>
+ std::basic_ostream<_CharT, _Traits>&
+ operator<<(std::basic_ostream<_CharT, _Traits>& __os,
+ const _Quoted_string<_String, _CharT>& __str)
+ {
+ std::basic_ostringstream<_CharT, _Traits> __ostr;
+ __ostr << __str._M_delim;
+ for (auto& __c : __str._M_string)
+ {
+ if (__c == __str._M_delim || __c == __str._M_escape)
+ __ostr << __str._M_escape;
+ __ostr << __c;
+ }
+ __ostr << __str._M_delim;
+
+ return __os << __ostr.str();
+ }
+
+ /**
+ * @brief Extractor for delimited strings.
+ * The left and right delimiters can be different.
+ */
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ std::basic_istream<_CharT, _Traits>&
+ operator>>(std::basic_istream<_CharT, _Traits>& __is,
+ const _Quoted_string<basic_string<_CharT, _Traits, _Alloc>&,
+ _CharT>& __str)
+ {
+ _CharT __c;
+ __is >> __c;
+ if (!__is.good())
+ return __is;
+ if (__c != __str._M_delim)
+ {
+ __is.unget();
+ __is >> __str._M_string;
+ return __is;
+ }
+ __str._M_string.clear();
+ std::ios_base::fmtflags __flags
+ = __is.flags(__is.flags() & ~std::ios_base::skipws);
+ do
+ {
+ __is >> __c;
+ if (!__is.good())
+ break;
+ if (__c == __str._M_escape)
+ {
+ __is >> __c;
+ if (!__is.good())
+ break;
+ }
+ else if (__c == __str._M_delim)
+ break;
+ __str._M_string += __c;
+ }
+ while (true);
+ __is.setf(__flags);
+
+ return __is;
+ }
+
+ _GLIBCXX_END_NAMESPACE_VERSION
+ } // namespace __detail
+} // namespace std
+
+#endif // C++11
+#endif /* _GLIBCXX_QUOTED_STRING_H */