Commit e149433a authored by Tobias Pfeiffer's avatar Tobias Pfeiffer

Bumped fmt to version 6.0.0

parent 65d02e49
Copyright (c) 2012 - 2016, Victor Zverovich Copyright (c) 2012 - present, Victor Zverovich
All rights reserved. Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Redistribution and use in source and binary forms, with or without The above copyright notice and this permission notice shall be
modification, are permitted provided that the following conditions are met: included in all copies or substantial portions of the Software.
1. Redistributions of source code must retain the above copyright notice, this THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
list of conditions and the following disclaimer. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2. Redistributions in binary form must reproduce the above copyright notice, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
this list of conditions and the following disclaimer in the documentation NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
and/or other materials provided with the distribution. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND --- Optional exception to the license ---
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE As an exception, if, as a result of your compiling your source code, portions
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR of this Software are embedded into a machine-executable object form of such
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES source code, you may redistribute such embedded portions in such object form
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; without including the above copyright and permission notices.
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -8,65 +8,65 @@ ...@@ -8,65 +8,65 @@
#ifndef FMT_LOCALE_H_ #ifndef FMT_LOCALE_H_
#define FMT_LOCALE_H_ #define FMT_LOCALE_H_
#include "format.h"
#include <locale> #include <locale>
#include "format.h"
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace internal { namespace internal {
template <typename Char> template <typename Char>
typename buffer_context<Char>::type::iterator vformat_to( typename buffer_context<Char>::iterator vformat_to(
const std::locale &loc, basic_buffer<Char> &buf, const std::locale& loc, buffer<Char>& buf,
basic_string_view<Char> format_str, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) { basic_format_args<buffer_context<Char>> args) {
typedef back_insert_range<basic_buffer<Char> > range; using range = buffer_range<Char>;
return vformat_to<arg_formatter<range>>( return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str), args,
buf, to_string_view(format_str), args, internal::locale_ref(loc)); internal::locale_ref(loc));
} }
template <typename Char> template <typename Char>
std::basic_string<Char> vformat( std::basic_string<Char> vformat(const std::locale& loc,
const std::locale &loc, basic_string_view<Char> format_str, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) { basic_format_args<buffer_context<Char>> args) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
internal::vformat_to(loc, buffer, format_str, args); internal::vformat_to(loc, buffer, format_str, args);
return fmt::to_string(buffer); return fmt::to_string(buffer);
} }
} } // namespace internal
template <typename S, typename Char = FMT_CHAR(S)> template <typename S, typename Char = char_t<S>>
inline std::basic_string<Char> vformat( inline std::basic_string<Char> vformat(
const std::locale &loc, const S &format_str, const std::locale& loc, const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) { basic_format_args<buffer_context<Char>> args) {
return internal::vformat(loc, to_string_view(format_str), args); return internal::vformat(loc, to_string_view(format_str), args);
} }
template <typename S, typename... Args> template <typename S, typename... Args, typename Char = char_t<S>>
inline std::basic_string<FMT_CHAR(S)> format( inline std::basic_string<Char> format(const std::locale& loc,
const std::locale &loc, const S &format_str, const Args &... args) { const S& format_str, Args&&... args) {
return internal::vformat( return internal::vformat(
loc, to_string_view(format_str), loc, to_string_view(format_str),
*internal::checked_args<S, Args...>(format_str, args...)); {internal::make_args_checked<Args...>(format_str, args...)});
} }
template <typename String, typename OutputIt, typename... Args> template <typename S, typename OutputIt, typename... Args,
inline typename std::enable_if<internal::is_output_iterator<OutputIt>::value, typename Char = enable_if_t<
OutputIt>::type internal::is_output_iterator<OutputIt>::value, char_t<S>>>
vformat_to(OutputIt out, const std::locale &loc, const String &format_str, inline OutputIt vformat_to(OutputIt out, const std::locale& loc,
typename format_args_t<OutputIt, FMT_CHAR(String)>::type args) { const S& format_str,
typedef output_range<OutputIt, FMT_CHAR(String)> range; format_args_t<OutputIt, Char> args) {
using range = internal::output_range<OutputIt, Char>;
return vformat_to<arg_formatter<range>>( return vformat_to<arg_formatter<range>>(
range(out), to_string_view(format_str), args, internal::locale_ref(loc)); range(out), to_string_view(format_str), args, internal::locale_ref(loc));
} }
template <typename OutputIt, typename S, typename... Args> template <typename OutputIt, typename S, typename... Args,
inline typename std::enable_if< FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value&&
internal::is_string<S>::value && internal::is_string<S>::value)>
internal::is_output_iterator<OutputIt>::value, OutputIt>::type inline OutputIt format_to(OutputIt out, const std::locale& loc,
format_to(OutputIt out, const std::locale &loc, const S &format_str, const S& format_str, Args&&... args) {
const Args &... args) {
internal::check_format_string<Args...>(format_str); internal::check_format_string<Args...>(format_str);
typedef typename format_context_t<OutputIt, FMT_CHAR(S)>::type context; using context = format_context_t<OutputIt, char_t<S>>;
format_arg_store<context, Args...> as{args...}; format_arg_store<context, Args...> as{args...};
return vformat_to(out, loc, to_string_view(format_str), return vformat_to(out, loc, to_string_view(format_str),
basic_format_args<context>(as)); basic_format_args<context>(as));
......
...@@ -8,22 +8,21 @@ ...@@ -8,22 +8,21 @@
#ifndef FMT_OSTREAM_H_ #ifndef FMT_OSTREAM_H_
#define FMT_OSTREAM_H_ #define FMT_OSTREAM_H_
#include "format.h"
#include <ostream> #include <ostream>
#include "format.h"
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace internal { namespace internal {
template <class Char> template <class Char> class formatbuf : public std::basic_streambuf<Char> {
class formatbuf : public std::basic_streambuf<Char> {
private: private:
typedef typename std::basic_streambuf<Char>::int_type int_type; using int_type = typename std::basic_streambuf<Char>::int_type;
typedef typename std::basic_streambuf<Char>::traits_type traits_type; using traits_type = typename std::basic_streambuf<Char>::traits_type;
basic_buffer<Char> &buffer_; buffer<Char>& buffer_;
public: public:
formatbuf(basic_buffer<Char> &buffer) : buffer_(buffer) {} formatbuf(buffer<Char>& buf) : buffer_(buf) {}
protected: protected:
// The put-area is actually always empty. This makes the implementation // The put-area is actually always empty. This makes the implementation
...@@ -39,33 +38,32 @@ class formatbuf : public std::basic_streambuf<Char> { ...@@ -39,33 +38,32 @@ class formatbuf : public std::basic_streambuf<Char> {
return ch; return ch;
} }
std::streamsize xsputn(const Char *s, std::streamsize count) FMT_OVERRIDE { std::streamsize xsputn(const Char* s, std::streamsize count) FMT_OVERRIDE {
buffer_.append(s, s + count); buffer_.append(s, s + count);
return count; return count;
} }
}; };
template <typename Char> template <typename Char> struct test_stream : std::basic_ostream<Char> {
struct test_stream : std::basic_ostream<Char> {
private: private:
struct null; struct null;
// Hide all operator<< from std::basic_ostream<Char>. // Hide all operator<< from std::basic_ostream<Char>.
void operator<<(null); void operator<<(null);
}; };
// Checks if T has a user-defined operator<< (e.g. not a member of std::ostream). // Checks if T has a user-defined operator<< (e.g. not a member of
template <typename T, typename Char> // std::ostream).
class is_streamable { template <typename T, typename Char> class is_streamable {
private: private:
template <typename U> template <typename U>
static decltype( static decltype((void)(std::declval<test_stream<Char>&>()
internal::declval<test_stream<Char>&>() << std::declval<U>()),
<< internal::declval<U>(), std::true_type()) test(int); std::true_type())
test(int);
template <typename> template <typename> static std::false_type test(...);
static std::false_type test(...);
typedef decltype(test<T>(0)) result; using result = decltype(test<T>(0));
public: public:
static const bool value = result::value; static const bool value = result::value;
...@@ -73,65 +71,51 @@ class is_streamable { ...@@ -73,65 +71,51 @@ class is_streamable {
// Write the content of buf to os. // Write the content of buf to os.
template <typename Char> template <typename Char>
void write(std::basic_ostream<Char> &os, basic_buffer<Char> &buf) { void write(std::basic_ostream<Char>& os, buffer<Char>& buf) {
const Char *data = buf.data(); const Char* buf_data = buf.data();
typedef std::make_unsigned<std::streamsize>::type UnsignedStreamSize; using unsigned_streamsize = std::make_unsigned<std::streamsize>::type;
UnsignedStreamSize size = buf.size(); unsigned_streamsize size = buf.size();
UnsignedStreamSize max_size = unsigned_streamsize max_size =
internal::to_unsigned((std::numeric_limits<std::streamsize>::max)()); to_unsigned((std::numeric_limits<std::streamsize>::max)());
do { do {
UnsignedStreamSize n = size <= max_size ? size : max_size; unsigned_streamsize n = size <= max_size ? size : max_size;
os.write(data, static_cast<std::streamsize>(n)); os.write(buf_data, static_cast<std::streamsize>(n));
data += n; buf_data += n;
size -= n; size -= n;
} while (size != 0); } while (size != 0);
} }
template <typename Char, typename T> template <typename Char, typename T>
void format_value(basic_buffer<Char> &buffer, const T &value) { void format_value(buffer<Char>& buf, const T& value) {
internal::formatbuf<Char> format_buf(buffer); formatbuf<Char> format_buf(buf);
std::basic_ostream<Char> output(&format_buf); std::basic_ostream<Char> output(&format_buf);
output.exceptions(std::ios_base::failbit | std::ios_base::badbit); output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
output << value; output << value;
buffer.resize(buffer.size()); buf.resize(buf.size());
} }
} // namespace internal
// Disable conversion to int if T has an overloaded operator<< which is a free
// function (not a member of std::ostream).
template <typename T, typename Char>
struct convert_to_int<T, Char, void> {
static const bool value =
convert_to_int<T, Char, int>::value &&
!internal::is_streamable<T, Char>::value;
};
// Formats an object of type T that has an overloaded ostream operator<<. // Formats an object of type T that has an overloaded ostream operator<<.
template <typename T, typename Char> template <typename T, typename Char>
struct formatter<T, Char, struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
typename std::enable_if<
internal::is_streamable<T, Char>::value &&
!internal::format_type<
typename buffer_context<Char>::type, T>::value>::type>
: formatter<basic_string_view<Char>, Char> { : formatter<basic_string_view<Char>, Char> {
template <typename Context> template <typename Context>
auto format(const T &value, Context &ctx) -> decltype(ctx.out()) { auto format(const T& value, Context& ctx) -> decltype(ctx.out()) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
internal::format_value(buffer, value); format_value(buffer, value);
basic_string_view<Char> str(buffer.data(), buffer.size()); basic_string_view<Char> str(buffer.data(), buffer.size());
return formatter<basic_string_view<Char>, Char>::format(str, ctx); return formatter<basic_string_view<Char>, Char>::format(str, ctx);
} }
}; };
} // namespace internal
template <typename Char> template <typename Char>
inline void vprint(std::basic_ostream<Char> &os, void vprint(std::basic_ostream<Char>& os, basic_string_view<Char> format_str,
basic_string_view<Char> format_str, basic_format_args<buffer_context<Char>> args) {
basic_format_args<typename buffer_context<Char>::type> args) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
internal::vformat_to(buffer, format_str, args); internal::vformat_to(buffer, format_str, args);
internal::write(os, buffer); internal::write(os, buffer);
} }
/** /**
\rst \rst
Prints formatted data to the stream *os*. Prints formatted data to the stream *os*.
...@@ -141,12 +125,11 @@ inline void vprint(std::basic_ostream<Char> &os, ...@@ -141,12 +125,11 @@ inline void vprint(std::basic_ostream<Char> &os,
fmt::print(cerr, "Don't {}!", "panic"); fmt::print(cerr, "Don't {}!", "panic");
\endrst \endrst
*/ */
template <typename S, typename... Args> template <typename S, typename... Args,
inline typename std::enable_if<internal::is_string<S>::value>::type typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
print(std::basic_ostream<FMT_CHAR(S)> &os, const S &format_str, void print(std::basic_ostream<Char>& os, const S& format_str, Args&&... args) {
const Args & ... args) { vprint(os, to_string_view(format_str),
internal::checked_args<S, Args...> ca(format_str, args...); {internal::make_args_checked<Args...>(format_str, args...)});
vprint(os, to_string_view(format_str), *ca);
} }
FMT_END_NAMESPACE FMT_END_NAMESPACE
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#if defined(__MINGW32__) || defined(__CYGWIN__) #if defined(__MINGW32__) || defined(__CYGWIN__)
// Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/. // Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/.
# undef __STRICT_ANSI__ # undef __STRICT_ANSI__
#endif #endif
#include <errno.h> #include <errno.h>
...@@ -22,42 +22,42 @@ ...@@ -22,42 +22,42 @@
#include <cstddef> #include <cstddef>
#if defined __APPLE__ || defined(__FreeBSD__) #if defined __APPLE__ || defined(__FreeBSD__)
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X # include <xlocale.h> // for LC_NUMERIC_MASK on OS X
#endif #endif
#include "format.h" #include "format.h"
#ifndef FMT_POSIX #ifndef FMT_POSIX
# if defined(_WIN32) && !defined(__MINGW32__) # if defined(_WIN32) && !defined(__MINGW32__)
// Fix warnings about deprecated symbols. // Fix warnings about deprecated symbols.
# define FMT_POSIX(call) _##call # define FMT_POSIX(call) _##call
# else # else
# define FMT_POSIX(call) call # define FMT_POSIX(call) call
# endif # endif
#endif #endif
// Calls to system functions are wrapped in FMT_SYSTEM for testability. // Calls to system functions are wrapped in FMT_SYSTEM for testability.
#ifdef FMT_SYSTEM #ifdef FMT_SYSTEM
# define FMT_POSIX_CALL(call) FMT_SYSTEM(call) # define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
#else #else
# define FMT_SYSTEM(call) call # define FMT_SYSTEM(call) call
# ifdef _WIN32 # ifdef _WIN32
// Fix warnings about deprecated symbols. // Fix warnings about deprecated symbols.
# define FMT_POSIX_CALL(call) ::_##call # define FMT_POSIX_CALL(call) ::_##call
# else # else
# define FMT_POSIX_CALL(call) ::call # define FMT_POSIX_CALL(call) ::call
# endif # endif
#endif #endif
// Retries the expression while it evaluates to error_result and errno // Retries the expression while it evaluates to error_result and errno
// equals to EINTR. // equals to EINTR.
#ifndef _WIN32 #ifndef _WIN32
# define FMT_RETRY_VAL(result, expression, error_result) \ # define FMT_RETRY_VAL(result, expression, error_result) \
do { \ do { \
result = (expression); \ result = (expression); \
} while (result == error_result && errno == EINTR) } while (result == error_result && errno == EINTR)
#else #else
# define FMT_RETRY_VAL(result, expression, error_result) result = (expression) # define FMT_RETRY_VAL(result, expression, error_result) result = (expression)
#endif #endif
#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1) #define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
...@@ -69,7 +69,7 @@ FMT_BEGIN_NAMESPACE ...@@ -69,7 +69,7 @@ FMT_BEGIN_NAMESPACE
A reference to a null-terminated string. It can be constructed from a C A reference to a null-terminated string. It can be constructed from a C
string or ``std::string``. string or ``std::string``.
You can use one of the following typedefs for common character types: You can use one of the following type aliases for common character types:
+---------------+-----------------------------+ +---------------+-----------------------------+
| Type | Definition | | Type | Definition |
...@@ -89,28 +89,27 @@ FMT_BEGIN_NAMESPACE ...@@ -89,28 +89,27 @@ FMT_BEGIN_NAMESPACE
format(std::string("{}"), 42); format(std::string("{}"), 42);
\endrst \endrst
*/ */
template <typename Char> template <typename Char> class basic_cstring_view {
class basic_cstring_view {
private: private:
const Char *data_; const Char* data_;
public: public:
/** Constructs a string reference object from a C string. */ /** Constructs a string reference object from a C string. */
basic_cstring_view(const Char *s) : data_(s) {} basic_cstring_view(const Char* s) : data_(s) {}
/** /**
\rst \rst
Constructs a string reference from an ``std::string`` object. Constructs a string reference from an ``std::string`` object.
\endrst \endrst
*/ */
basic_cstring_view(const std::basic_string<Char> &s) : data_(s.c_str()) {} basic_cstring_view(const std::basic_string<Char>& s) : data_(s.c_str()) {}
/** Returns the pointer to a C string. */ /** Returns the pointer to a C string. */
const Char *c_str() const { return data_; } const Char* c_str() const { return data_; }
}; };
typedef basic_cstring_view<char> cstring_view; using cstring_view = basic_cstring_view<char>;
typedef basic_cstring_view<wchar_t> wcstring_view; using wcstring_view = basic_cstring_view<wchar_t>;
// An error code. // An error code.
class error_code { class error_code {
...@@ -126,33 +125,32 @@ class error_code { ...@@ -126,33 +125,32 @@ class error_code {
// A buffered file. // A buffered file.
class buffered_file { class buffered_file {
private: private:
FILE *file_; FILE* file_;
friend class file; friend class file;
explicit buffered_file(FILE *f) : file_(f) {} explicit buffered_file(FILE* f) : file_(f) {}
public: public:
// Constructs a buffered_file object which doesn't represent any file. // Constructs a buffered_file object which doesn't represent any file.
buffered_file() FMT_NOEXCEPT : file_(FMT_NULL) {} buffered_file() FMT_NOEXCEPT : file_(nullptr) {}
// Destroys the object closing the file it represents if any. // Destroys the object closing the file it represents if any.
FMT_API ~buffered_file() FMT_NOEXCEPT; FMT_API ~buffered_file() FMT_NOEXCEPT;
private: private:
buffered_file(const buffered_file &) = delete; buffered_file(const buffered_file&) = delete;
void operator=(const buffered_file &) = delete; void operator=(const buffered_file&) = delete;
public: public:
buffered_file(buffered_file &&other) FMT_NOEXCEPT : file_(other.file_) { buffered_file(buffered_file&& other) FMT_NOEXCEPT : file_(other.file_) {
other.file_ = FMT_NULL; other.file_ = nullptr;
} }
buffered_file& operator=(buffered_file &&other) { buffered_file& operator=(buffered_file&& other) {
close(); close();
file_ = other.file_; file_ = other.file_;
other.file_ = FMT_NULL; other.file_ = nullptr;
return *this; return *this;
} }
...@@ -163,18 +161,18 @@ class buffered_file { ...@@ -163,18 +161,18 @@ class buffered_file {
FMT_API void close(); FMT_API void close();
// Returns the pointer to a FILE object representing this file. // Returns the pointer to a FILE object representing this file.
FILE *get() const FMT_NOEXCEPT { return file_; } FILE* get() const FMT_NOEXCEPT { return file_; }
// We place parentheses around fileno to workaround a bug in some versions // We place parentheses around fileno to workaround a bug in some versions
// of MinGW that define fileno as a macro. // of MinGW that define fileno as a macro.
FMT_API int (fileno)() const; FMT_API int(fileno)() const;
void vprint(string_view format_str, format_args args) { void vprint(string_view format_str, format_args args) {
fmt::vprint(file_, format_str, args); fmt::vprint(file_, format_str, args);
} }
template <typename... Args> template <typename... Args>
inline void print(string_view format_str, const Args & ... args) { inline void print(string_view format_str, const Args&... args) {
vprint(format_str, make_format_args(args...)); vprint(format_str, make_format_args(args...));
} }
}; };
...@@ -195,9 +193,9 @@ class file { ...@@ -195,9 +193,9 @@ class file {
public: public:
// Possible values for the oflag argument to the constructor. // Possible values for the oflag argument to the constructor.
enum { enum {
RDONLY = FMT_POSIX(O_RDONLY), // Open for reading only. RDONLY = FMT_POSIX(O_RDONLY), // Open for reading only.
WRONLY = FMT_POSIX(O_WRONLY), // Open for writing only. WRONLY = FMT_POSIX(O_WRONLY), // Open for writing only.
RDWR = FMT_POSIX(O_RDWR) // Open for reading and writing. RDWR = FMT_POSIX(O_RDWR) // Open for reading and writing.
}; };
// Constructs a file object which doesn't represent any file. // Constructs a file object which doesn't represent any file.
...@@ -207,15 +205,13 @@ class file { ...@@ -207,15 +205,13 @@ class file {
FMT_API file(cstring_view path, int oflag); FMT_API file(cstring_view path, int oflag);
private: private:
file(const file &) = delete; file(const file&) = delete;
void operator=(const file &) = delete; void operator=(const file&) = delete;
public: public:
file(file &&other) FMT_NOEXCEPT : fd_(other.fd_) { file(file&& other) FMT_NOEXCEPT : fd_(other.fd_) { other.fd_ = -1; }
other.fd_ = -1;
}
file& operator=(file &&other) { file& operator=(file&& other) {
close(); close();
fd_ = other.fd_; fd_ = other.fd_;
other.fd_ = -1; other.fd_ = -1;
...@@ -236,10 +232,10 @@ class file { ...@@ -236,10 +232,10 @@ class file {
FMT_API long long size() const; FMT_API long long size() const;
// Attempts to read count bytes from the file into the specified buffer. // Attempts to read count bytes from the file into the specified buffer.
FMT_API std::size_t read(void *buffer, std::size_t count); FMT_API std::size_t read(void* buffer, std::size_t count);
// Attempts to write count bytes from the specified buffer to the file. // Attempts to write count bytes from the specified buffer to the file.
FMT_API std::size_t write(const void *buffer, std::size_t count); FMT_API std::size_t write(const void* buffer, std::size_t count);
// Duplicates a file descriptor with the dup function and returns // Duplicates a file descriptor with the dup function and returns
// the duplicate as a file object. // the duplicate as a file object.
...@@ -251,68 +247,59 @@ class file { ...@@ -251,68 +247,59 @@ class file {
// Makes fd be the copy of this file descriptor, closing fd first if // Makes fd be the copy of this file descriptor, closing fd first if
// necessary. // necessary.
FMT_API void dup2(int fd, error_code &ec) FMT_NOEXCEPT; FMT_API void dup2(int fd, error_code& ec) FMT_NOEXCEPT;
// Creates a pipe setting up read_end and write_end file objects for reading // Creates a pipe setting up read_end and write_end file objects for reading
// and writing respectively. // and writing respectively.
FMT_API static void pipe(file &read_end, file &write_end); FMT_API static void pipe(file& read_end, file& write_end);
// Creates a buffered_file object associated with this file and detaches // Creates a buffered_file object associated with this file and detaches
// this file object from the file. // this file object from the file.
FMT_API buffered_file fdopen(const char *mode); FMT_API buffered_file fdopen(const char* mode);
}; };
// Returns the memory page size. // Returns the memory page size.
long getpagesize(); long getpagesize();
#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \
!defined(__ANDROID__) && !defined(__CYGWIN__) && !defined(__OpenBSD__) && \
!defined(__NEWLIB_H__)
# define FMT_LOCALE
#endif
#ifdef FMT_LOCALE #ifdef FMT_LOCALE
// A "C" numeric locale. // A "C" numeric locale.
class Locale { class Locale {
private: private:
# ifdef _MSC_VER # ifdef _WIN32
typedef _locale_t locale_t; using locale_t = _locale_t;
enum { LC_NUMERIC_MASK = LC_NUMERIC }; enum { LC_NUMERIC_MASK = LC_NUMERIC };
static locale_t newlocale(int category_mask, const char *locale, locale_t) { static locale_t newlocale(int category_mask, const char* locale, locale_t) {
return _create_locale(category_mask, locale); return _create_locale(category_mask, locale);
} }
static void freelocale(locale_t locale) { static void freelocale(locale_t locale) { _free_locale(locale); }
_free_locale(locale);
}
static double strtod_l(const char *nptr, char **endptr, _locale_t locale) { static double strtod_l(const char* nptr, char** endptr, _locale_t locale) {
return _strtod_l(nptr, endptr, locale); return _strtod_l(nptr, endptr, locale);
} }
# endif # endif
locale_t locale_; locale_t locale_;
Locale(const Locale &) = delete; Locale(const Locale&) = delete;
void operator=(const Locale &) = delete; void operator=(const Locale&) = delete;
public: public:
typedef locale_t Type; using type = locale_t;
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL)) { Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", nullptr)) {
if (!locale_) if (!locale_) FMT_THROW(system_error(errno, "cannot create locale"));
FMT_THROW(system_error(errno, "cannot create locale"));
} }
~Locale() { freelocale(locale_); } ~Locale() { freelocale(locale_); }
Type get() const { return locale_; } type get() const { return locale_; }
// Converts string to floating-point number and advances str past the end // Converts string to floating-point number and advances str past the end
// of the parsed input. // of the parsed input.
double strtod(const char *&str) const { double strtod(const char*& str) const {
char *end = FMT_NULL; char* end = nullptr;
double result = strtod_l(str, &end, locale_); double result = strtod_l(str, &end, locale_);
str = end; str = end;
return result; return result;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment