Compare commits

...

51 Commits

Author SHA1 Message Date
7fa8f8fa48 Update version 2016-11-01 09:24:49 +01:00
1ef8b4a5de Update version to 3.0.1 2016-10-31 22:02:46 +01:00
4a66897fb6 Update ChangeLog 2016-10-31 22:02:43 +01:00
63639cba98 Fix Windows compilation with -fno-exceptions (#405)
(cherry picked from commit 15d0f32773)
2016-10-31 22:02:42 +01:00
2baf2a5e2c Fix Linux compilation with -fno-exceptions (#402)
(cherry picked from commit 8c63ea432c)
2016-10-31 22:02:42 +01:00
fb9015b3a1 CHAR_WIDTH -> CHAR_SIZE to avoid collision with ISO/IEC TS 18661-1:2014 macro
(cherry picked from commit abbefd7166)
2016-10-28 19:42:17 +02:00
0a0c2c9cdd Remove unnecessary "fmt/" prefix which should be maintained with additional include_directories() in each project. (#397)
(cherry picked from commit 1500f00525)
2016-10-23 12:17:31 +02:00
1c9a674d24 Fix compilation on Cygwin (#388)
(cherry picked from commit cee50b7572)
2016-10-23 12:17:30 +02:00
6e6adf431f Add FMT_OVERRIDE macro to allow specifying overriding functions in c++11 compilers
(cherry picked from commit 9ec3bea2d6)
2016-10-23 12:17:30 +02:00
f8289ba1da Fix compilation on Android.
(cherry picked from commit 5f26b5da28)
2016-10-23 12:17:30 +02:00
79100a21bc Correct syntax
(cherry picked from commit 04335aeadb)
2016-10-23 12:17:30 +02:00
f4a417f8fb Fix handling of unsigned char strings (#373)
(cherry picked from commit a79c7b4e8f)
2016-10-23 12:17:30 +02:00
5047091ad8 Add 'a' and 'A' format specifiers
(cherry picked from commit 53f9e7f65c)
2016-10-23 12:17:30 +02:00
f880a6cedf Add CUAUV, Seastar and ScyllaDB to the list of projects that use fmt
(cherry picked from commit 2bf59a97c6)
2016-10-23 12:01:53 +02:00
7459ce15d3 Don't use -std compiler flag if CMAKE_CXX_STANDARD is specified (#366)
(cherry picked from commit 12a6027b40)
2016-10-23 12:01:42 +02:00
f0a0674040 Use a heuristic to detect empty strftime result (#367)
(cherry picked from commit a5d0adf395)
2016-10-23 12:01:33 +02:00
c79174e1c0 Correct buffer growth when formatting time (#367)
(cherry picked from commit 1a23f9c274)
2016-10-23 12:01:17 +02:00
f116a28134 Add "n" to integer formatting types
(cherry picked from commit ed30108918)
2016-10-23 11:59:32 +02:00
6d91a801a4 Update usage.rst: change Homebrew package name
(cherry picked from commit 1dbc6bd1fc)
2016-10-23 11:59:05 +02:00
e3de93298b Remove unreachable code below FMT_THROW
(cherry picked from commit c8c9973669)
2016-10-23 11:58:44 +02:00
6f27f98103 Update readme
(cherry picked from commit c110c6eca7)
2016-10-23 11:55:51 +02:00
b8540e613e Workaround broken MinGW installation on AppVeyor (#355)
(cherry picked from commit 1acfd07f1e)
2016-10-23 11:54:55 +02:00
a20c81a061 Break a long line
(cherry picked from commit 903357c853)
2016-10-23 11:53:12 +02:00
5d306cf11c Fix compile on freebsd
(cherry picked from commit d7c4e1cb1f)
2016-10-23 11:53:00 +02:00
3f778b2099 check -> const_check to avoid a conflict with AssertMacros.h (#350)
(cherry picked from commit 8631694021)
2016-10-23 11:52:49 +02:00
27f604a153 Fix handling of thousands separator (#353)
(cherry picked from commit 0e6df7e511)
2016-10-23 11:52:39 +02:00
1127e7a953 Fix building with clang in header-only mode
Building under a recent clang compiler causes the use of an extern
template for the BasicData struct. However, the only instantiation of
that structure in format.cc is only done if FMT_HEADER_ONLY is not
defined. This causes the build to fail in C++11 or C++14 mode.
Therefore, only declare the BasicData template as extern if
FMT_HEADER_ONLY is not defined.

(cherry picked from commit 75f862bf57)
2016-10-23 11:52:28 +02:00
b838eb0c2e Reduce noise
(cherry picked from commit 5c876088d3)
2016-10-23 11:52:07 +02:00
59f9936009 Fix a link (#347)
(cherry picked from commit 2e69e454d0)
2016-10-23 11:51:40 +02:00
b26e239c05 Fix MSVC warnings
(cherry picked from commit e0d6f630f8)
2016-10-23 11:51:09 +02:00
300d4f3c89 Suppress -Wpadded warnings
(cherry picked from commit a201c61977)
2016-10-23 11:50:15 +02:00
8cfff4da4c Fix -Wpessimizing-move
(cherry picked from commit 4569b4dbd6)
2016-10-23 11:50:02 +02:00
92d3f31df5 Fix clang warning
(cherry picked from commit c9bb5468b6)
2016-10-23 11:49:54 +02:00
df05947b8a Fix a -Wweak-vtables warning in clang
(cherry picked from commit b26e76efe9)
2016-10-23 11:49:44 +02:00
679fed9187 Don't use strtod_l on Android (#345)
(cherry picked from commit c7739536e8)
2016-10-23 11:49:31 +02:00
14b4a2b073 Suppress clang's documentation warnings
(cherry picked from commit 18e3f16576)
2016-10-23 11:49:19 +02:00
8bb431fef3 Break long lines
(cherry picked from commit 231c16df25)
2016-10-23 11:47:59 +02:00
01e31f3154 Don't use --upgrade because it causes pip install older version of sphinx
(cherry picked from commit e68836c123)
2016-10-23 11:47:45 +02:00
713a061bc5 Make documentation installation optional (#333)
(cherry picked from commit dc1e36fa0e)
2016-10-23 11:47:36 +02:00
87f5f867f6 Update sphinx
(cherry picked from commit 7bb1b50835)
2016-10-23 11:47:32 +02:00
ae85c91e80 Detect if lconv contains thousands_sep
(cherry picked from commit 96c28f748d)
2016-10-23 11:47:15 +02:00
584fa85d18 Add fmt prefix to includes (#332)
Technically it is not necessary, but prevents errors when people add the
fmt directory itself rather than its parent to includes.

(cherry picked from commit e160c2b79a)
2016-10-23 11:46:38 +02:00
d5dd1cd2a0 Use a mock to test locale support
(cherry picked from commit e2a332e5df)
2016-10-23 11:46:05 +02:00
078c44e31c Improve formatting consistency
(cherry picked from commit ebff26f8f1)
2016-10-23 11:44:52 +02:00
2fd6c0b245 Workaround for missing lconv support in android (#327)
(cherry picked from commit 45a1509455)
2016-10-23 11:44:42 +02:00
affac0bea0 Check if setlocale succeeded
(cherry picked from commit 5b106083e7)
2016-10-23 11:44:32 +02:00
ae8ae747bd Workaround an issue with "delete this" in GMock and gcc 6.1.1
(cherry picked from commit d00b43c592)
2016-10-23 11:44:19 +02:00
c1c963e8b9 Correct docs
(cherry picked from commit d67eb8af2f)
2016-10-23 11:44:10 +02:00
5b26ada01c Fix clang -Weverything warnings (#250)
(cherry picked from commit 3400e0d609)
2016-10-23 11:44:02 +02:00
b6481599e6 Clarify performance tradeoffs (#320)
(cherry picked from commit f76583276a)
2016-10-23 11:43:49 +02:00
3f1cd52adc Fix a clang warning about an undefined template (#318)
(cherry picked from commit 744c2824c5)
2016-10-23 11:42:09 +02:00
28 changed files with 318 additions and 225 deletions

View File

@ -28,7 +28,7 @@ option(FMT_USE_CPP11 "Enable the addition of C++11 compiler flags." ON)
project(FMT)
# Starting with cmake 3.0 VERSION is part of the project command.
set(FMT_VERSION 3.0.0)
set(FMT_VERSION 3.0.1)
if (NOT FMT_VERSION MATCHES "^([0-9]+).([0-9]+).([0-9]+)$")
message(FATAL_ERROR "Invalid version format ${FMT_VERSION}.")
endif ()

View File

@ -1,3 +1,17 @@
3.0.1 - 2016-11-01
------------------
* Fixed handling of thousands seperator (`#353 <https://github.com/fmtlib/fmt/issues/353>`_)
* Fixed handling of ``unsigned char`` strings (`#373 <https://github.com/fmtlib/fmt/issues/373>`_)
* Corrected buffer growth when formatting time (`#367 <https://github.com/fmtlib/fmt/issues/367>`_)
* Removed warnings under MSVC and clang (`#318 <https://github.com/fmtlib/fmt/issues/318>`_, `#250 <https://github.com/fmtlib/fmt/issues/250>`_, also merged `#385 <https://github.com/fmtlib/fmt/pull/385>`_ and `#361 <https://github.com/fmtlib/fmt/pull/361>`_). Thanks `@jcelerier (Jean-Michaël Celerier) <https://github.com/jcelerier>`_ and `@nmoehrle (Nils Moehrle) <https://github.com/nmoehrle>`_.
* Fixed compilation issues under Android (`#327 <https://github.com/fmtlib/fmt/pull/327>`_, `#345 <https://github.com/fmtlib/fmt/issues/345>`_ and `#381 <https://github.com/fmtlib/fmt/pull/381>`_), FreeBSD (`#358 <https://github.com/fmtlib/fmt/pull/358>`_), Cygwin (`#388 <https://github.com/fmtlib/fmt/issues/388>`_), MinGW (`#355 <https://github.com/fmtlib/fmt/issues/355>`_) as well as other issues (`#350 <https://github.com/fmtlib/fmt/issues/350>`_, `#366 <https://github.com/fmtlib/fmt/issues/355>`_, `#348 <https://github.com/fmtlib/fmt/pull/348>`_, `#402 <https://github.com/fmtlib/fmt/pull/402>`_, `#405 <https://github.com/fmtlib/fmt/pull/405>`_). Thanks to `@dpantele (Dmitry) <https://github.com/dpantele>`_, `@hghwng (Hugh Wang) <https://github.com/hghwng>`_, `@arvedarved (Tilman Keskinöz) <https://github.com/arvedarved>`_, `@LogicalKnight (Sean) <https://github.com/LogicalKnight>`_ and `@JanHellwig (Jan Hellwig) <https://github.com/janhellwig>`_.
* Fixed some documentation issues and extended specification (`#320 <https://github.com/fmtlib/fmt/issues/320>`_, `#333 <https://github.com/fmtlib/fmt/pull/333>`_, `#347 <https://github.com/fmtlib/fmt/issues/347>`_, `#362 <https://github.com/fmtlib/fmt/pull/362>`_). Thanks to `@smellman (Taro Matsuzawa aka. btm) <https://github.com/smellman>`_.
3.0.0 - 2016-05-07
------------------

View File

@ -20,9 +20,11 @@ alternative to IOStreams.
Features
--------
* Two APIs: faster concatenation-based write API and slower (but still
very fast) replacement-based format API with positional arguments for
localization.
* Two APIs: faster concatenation-based `write API
<http://fmtlib.net/latest/api.html#write-api>`_ and slower,
but still very fast, replacement-based `format API
<http://fmtlib.net/latest/api.html#format-api>`_ with positional arguments
for localization.
* Write API similar to the one used by IOStreams but stateless allowing
faster implementation.
* Format API with `format string syntax
@ -35,7 +37,7 @@ Features
* Support for user-defined types.
* High speed: performance of the format API is close to that of
glibc's `printf <http://en.cppreference.com/w/cpp/io/c/fprintf>`_
and better than performance of IOStreams. See `Speed tests`_ and
and better than the performance of IOStreams. See `Speed tests`_ and
`Fast integer to string conversion in C++
<http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html>`_.
* Small code size both in terms of source code (format consists of a single
@ -89,6 +91,8 @@ An object of any user-defined type for which there is an overloaded
.. code:: c++
#include "fmt/ostream.h"
class Date {
int year_, month_, day_;
public:
@ -132,6 +136,8 @@ Projects using this library
* `AMPL/MP <https://github.com/ampl/mp>`_:
An open-source library for mathematical programming
* `CUAUV <http://cuauv.org/>`_: Cornell University's autonomous underwater vehicle
* `HarpyWar/pvpgn <https://github.com/pvpgn/pvpgn-server>`_:
Player vs Player Gaming Network with tweaks
@ -158,6 +164,12 @@ Projects using this library
* `Salesforce Analytics Cloud <http://www.salesforce.com/analytics-cloud/overview/>`_:
Business intelligence software
* `Scylla <http://www.scylladb.com/>`_: A Cassandra-compatible NoSQL data store that can handle
1 million transactions per second on a single server
* `Seastar <http://www.seastar-project.org/>`_: An advanced, open-source C++ framework for
high-performance server applications on modern hardware
* `spdlog <https://github.com/gabime/spdlog>`_: Super fast C++ logging library
* `Stellar <https://www.stellar.org/>`_: Financial platform

View File

@ -7,4 +7,5 @@ endif ()
add_custom_target(doc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build.py ${FMT_VERSION})
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ DESTINATION share/doc/fmt)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/
DESTINATION share/doc/fmt OPTIONAL)

View File

@ -22,6 +22,11 @@ arguments in the resulting string.
*args* is an argument list representing arbitrary arguments.
The `performance of the format API
<https://github.com/fmtlib/fmt/blob/master/README.rst#speed-tests>`_ is close
to that of glibc's ``printf`` and better than the performance of IOStreams.
For even better speed use the `write API`_.
.. _format:
.. doxygenfunction:: format(CStringRef, ArgList)
@ -136,6 +141,13 @@ a POSIX extension for positional arguments.
Write API
=========
The write API provides classes for writing formatted data into character
streams. It is usually faster than the `format API`_ but, as IOStreams,
may result in larger compiled code size. The main writer class is
`~fmt::BasicMemoryWriter` which stores its output in a memory buffer and provides
direct access to it. It is possible to create custom writers that
store output elsewhere by subclassing `~fmt::BasicWriter`.
.. doxygenclass:: fmt::BasicWriter
:members:

View File

@ -16,7 +16,7 @@ def pip_install(package, commit=None, **kwargs):
# return
package = 'git+git://github.com/{0}.git@{1}'.format(package, commit)
print('Installing {}'.format(package))
check_call(['pip', 'install', '--upgrade', package])
check_call(['pip', 'install', package])
def build_docs(version='dev'):
# Create virtualenv.
@ -46,9 +46,9 @@ def build_docs(version='dev'):
except DistributionNotFound:
pass
# Install Sphinx and Breathe.
pip_install('fmtlib/sphinx',
'12dde8afdb0a7bb5576e2656692c3478c69d8cc3',
check_version='1.4a0.dev-20151013')
pip_install('sphinx-doc/sphinx',
'12b83372ac9316e8cbe86e7fed889296a4cc29ee',
check_version='1.4.1.dev20160525')
pip_install('michaeljones/breathe',
'1c9d7f80378a92cffa755084823a78bb38ee4acc')
# Build docs.

View File

@ -24,8 +24,8 @@ Format API
The replacement-based Format API provides a safe alternative to ``printf``,
``sprintf`` and friends with comparable or `better performance
<http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html>`_.
The `format string syntax <doc/latest/index.html#format-string-syntax>`_ is similar
to the one used by `str.format <http://docs.python.org/2/library/stdtypes.html#str.format>`_
The `format string syntax <syntax.html>`_ is similar to the one used by
`str.format <http://docs.python.org/2/library/stdtypes.html#str.format>`_
in Python:
.. code:: c++

View File

@ -49,12 +49,10 @@ mini-language" or interpretation of the *format_spec*.
Most built-in types support a common formatting mini-language, which is
described in the next section.
A *format_spec* field can also include nested replacement fields within it.
These nested replacement fields can contain only an argument index;
format specifications are not allowed. Formatting is performed as if the
replacement fields within the format_spec are substituted before the
*format_spec* string is interpreted. This allows the formatting of a value
to be dynamically specified.
A *format_spec* field can also include nested replacement fields in certain
positions within it. These nested replacement fields can contain only an
argument index; format specifications are not allowed. This allows the
formatting of a value to be dynamically specified.
See the :ref:`formatexamples` section for some examples.
@ -80,8 +78,8 @@ The general form of a *standard format specifier* is:
sign: "+" | "-" | " "
width: `integer` | "{" `arg_id` "}"
precision: `integer` | "{" `arg_id` "}"
type: `int_type` | "c" | "e" | "E" | "f" | "F" | "g" | "G" | "p" | "s"
int_type: "b" | "B" | "d" | "o" | "x" | "X"
type: `int_type` | "a" | "A" | "c" | "e" | "E" | "f" | "F" | "g" | "G" | "p" | "s"
int_type: "b" | "B" | "d" | "n" | "o" | "x" | "X"
The *fill* character can be any character other than '{' or '}'. The presence
of a fill character is signaled by the character following it, which must be
@ -234,7 +232,7 @@ The available presentation types for floating-point values are:
+=========+==========================================================+
| ``'a'`` | Hexadecimal floating point format. Prints the number in |
| | base 16 with prefix ``"0x"`` and lower-case letters for |
| | digits above 9. Uses 'p' to indicate the exponent. |
| | digits above 9. Uses ``'p'`` to indicate the exponent. |
+---------+----------------------------------------------------------+
| ``'A'`` | Same as ``'a'`` except it uses upper-case letters for |
| | the prefix, digits above 9 and to indicate the exponent. |

View File

@ -87,4 +87,4 @@ Homebrew
fmt can be installed on OS X using `Homebrew <http://brew.sh/>`_::
brew install cppformat
brew install fmt

View File

@ -20,7 +20,7 @@ if (FMT_PEDANTIC)
target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS})
endif ()
target_include_directories(fmt INTERFACE
target_include_directories(fmt PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
@ -74,7 +74,8 @@ if (FMT_INSTALL)
${PROJECT_SOURCE_DIR}/support/cmake/fmt-config.cmake.in
${project_config}
INSTALL_DESTINATION ${FMT_CMAKE_DIR})
export(TARGETS ${INSTALL_TARGETS} FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
export(TARGETS ${INSTALL_TARGETS}
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
# Install version, config and target files.
install(
@ -83,7 +84,8 @@ if (FMT_INSTALL)
install(EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR})
# Install the library and headers.
install(TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name} DESTINATION ${FMT_LIB_DIR})
install(TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name}
DESTINATION ${FMT_LIB_DIR})
install(FILES ${FMT_HEADERS} DESTINATION include/fmt)
if (FMT_CPPFORMAT)
install(TARGETS cppformat DESTINATION ${FMT_LIB_DIR})

View File

@ -79,6 +79,11 @@ static inline fmt::internal::Null<> strerror_s(char *, std::size_t, ...) {
}
namespace fmt {
FMT_FUNC internal::RuntimeError::~RuntimeError() throw() {}
FMT_FUNC FormatError::~FormatError() throw() {}
FMT_FUNC SystemError::~SystemError() throw() {}
namespace {
#ifndef _MSC_VER

View File

@ -50,7 +50,13 @@
# include <iterator>
#endif
#if defined(_MSC_VER) && _MSC_VER <= 1500
#ifdef _MSC_VER
# define FMT_MSC_VER _MSC_VER
#else
# define FMT_MSC_VER 0
#endif
#if FMT_MSC_VER && FMT_MSC_VER <= 1500
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
typedef __int64 intmax_t;
@ -99,7 +105,8 @@ typedef __int64 intmax_t;
#if defined(__clang__) && !defined(FMT_ICC_VERSION)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdocumentation"
# pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
# pragma clang diagnostic ignored "-Wpadded"
#endif
#ifdef __GNUC_LIBSTD__
@ -130,7 +137,7 @@ typedef __int64 intmax_t;
// since version 2013.
# define FMT_USE_VARIADIC_TEMPLATES \
(FMT_HAS_FEATURE(cxx_variadic_templates) || \
(FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1800)
(FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1800)
#endif
#ifndef FMT_USE_RVALUE_REFERENCES
@ -141,7 +148,7 @@ typedef __int64 intmax_t;
# else
# define FMT_USE_RVALUE_REFERENCES \
(FMT_HAS_FEATURE(cxx_rvalue_references) || \
(FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1600)
(FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1600)
# endif
#endif
@ -153,7 +160,7 @@ typedef __int64 intmax_t;
#if defined(__GNUC__) && !defined(__EXCEPTIONS)
# define FMT_EXCEPTIONS 0
#endif
#if defined(_MSC_VER) && !_HAS_EXCEPTIONS
#if FMT_MSC_VER && !_HAS_EXCEPTIONS
# define FMT_EXCEPTIONS 0
#endif
#ifndef FMT_EXCEPTIONS
@ -177,7 +184,7 @@ typedef __int64 intmax_t;
# if FMT_EXCEPTIONS
# if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \
_MSC_VER >= 1900
FMT_MSC_VER >= 1900
# define FMT_NOEXCEPT noexcept
# else
# define FMT_NOEXCEPT throw()
@ -187,6 +194,17 @@ typedef __int64 intmax_t;
# endif
#endif
#ifndef FMT_OVERRIDE
# if FMT_USE_OVERRIDE || FMT_HAS_FEATURE(cxx_override) || \
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \
FMT_MSC_VER >= 1900
# define FMT_OVERRIDE override
# else
# define FMT_OVERRIDE
# endif
#endif
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
#ifndef FMT_USE_DELETED_FUNCTIONS
@ -194,7 +212,7 @@ typedef __int64 intmax_t;
#endif
#if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions) || \
(FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1800
(FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1800
# define FMT_DELETED_OR_UNDEFINED = delete
# define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) = delete; \
@ -214,7 +232,7 @@ typedef __int64 intmax_t;
# define FMT_USE_USER_DEFINED_LITERALS \
FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES && \
(FMT_HAS_FEATURE(cxx_user_literals) || \
(FMT_GCC_VERSION >= 407 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1900) && \
(FMT_GCC_VERSION >= 407 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900) && \
(!defined(FMT_ICC_VERSION) || FMT_ICC_VERSION >= 1500)
#endif
@ -222,7 +240,6 @@ typedef __int64 intmax_t;
# define FMT_ASSERT(condition, message) assert((condition) && message)
#endif
#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
# define FMT_BUILTIN_CLZ(n) __builtin_clz(n)
#endif
@ -231,11 +248,11 @@ typedef __int64 intmax_t;
# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n)
#endif
// Some compilers masquerade as both MSVC and GCC-likes or
// Some compilers masquerade as both MSVC and GCC-likes or
// otherwise support __builtin_clz and __builtin_clzll, so
// only define FMT_BUILTIN_CLZ using the MSVC intrinsics
// if the clz and clzll builtins are not available.
#if defined(_MSC_VER) && !defined(FMT_BUILTIN_CLZLL)
#if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL)
# include <intrin.h> // _BitScanReverse, _BitScanReverse64
namespace fmt {
@ -247,7 +264,7 @@ inline uint32_t clz(uint32_t x) {
assert(x != 0);
// Static analysis complains about using uninitialized data
// "r", but the only way that can happen is if "x" is 0,
// "r", but the only way that can happen is if "x" is 0,
// which the callers guarantee to not happen.
# pragma warning(suppress: 6102)
return 31 - r;
@ -273,7 +290,7 @@ inline uint32_t clzll(uint64_t x) {
assert(x != 0);
// Static analysis complains about using uninitialized data
// "r", but the only way that can happen is if "x" is 0,
// "r", but the only way that can happen is if "x" is 0,
// which the callers guarantee to not happen.
# pragma warning(suppress: 6102)
return 63 - r;
@ -303,7 +320,7 @@ inline DummyInt _isnan(...) { return DummyInt(); }
// A helper function to suppress bogus "conditional expression is constant"
// warnings.
template <typename T>
inline T check(T value) { return value; }
inline T const_check(T value) { return value; }
}
} // namespace fmt
@ -322,8 +339,8 @@ class numeric_limits<fmt::internal::DummyInt> :
using namespace fmt::internal;
// The resolution "priority" is:
// isinf macro > std::isinf > ::isinf > fmt::internal::isinf
if (check(sizeof(isinf(x)) == sizeof(bool) ||
sizeof(isinf(x)) == sizeof(int))) {
if (const_check(sizeof(isinf(x)) == sizeof(bool) ||
sizeof(isinf(x)) == sizeof(int))) {
return isinf(x) != 0;
}
return !_finite(static_cast<double>(x));
@ -333,8 +350,8 @@ class numeric_limits<fmt::internal::DummyInt> :
template <typename T>
static bool isnotanumber(T x) {
using namespace fmt::internal;
if (check(sizeof(isnan(x)) == sizeof(bool) ||
sizeof(isnan(x)) == sizeof(int))) {
if (const_check(sizeof(isnan(x)) == sizeof(bool) ||
sizeof(isnan(x)) == sizeof(int))) {
return isnan(x) != 0;
}
return _isnan(static_cast<double>(x)) != 0;
@ -343,7 +360,7 @@ class numeric_limits<fmt::internal::DummyInt> :
// Portable version of signbit.
static bool isnegative(double x) {
using namespace fmt::internal;
if (check(sizeof(signbit(x)) == sizeof(int)))
if (const_check(sizeof(signbit(x)) == sizeof(int)))
return signbit(x) != 0;
if (x < 0) return true;
if (!isnotanumber(x)) return false;
@ -525,13 +542,12 @@ class BasicCStringRef {
typedef BasicCStringRef<char> CStringRef;
typedef BasicCStringRef<wchar_t> WCStringRef;
/**
A formatting error such as invalid format string.
*/
/** A formatting error such as invalid format string. */
class FormatError : public std::runtime_error {
public:
explicit FormatError(CStringRef message)
: std::runtime_error(message.c_str()) {}
~FormatError() throw();
};
namespace internal {
@ -657,8 +673,8 @@ void Buffer<T>::append(const U *begin, const U *end) {
namespace internal {
// A memory buffer for trivially copyable/constructible types with the first SIZE
// elements stored in the object itself.
// A memory buffer for trivially copyable/constructible types with the first
// SIZE elements stored in the object itself.
template <typename T, std::size_t SIZE, typename Allocator = std::allocator<T> >
class MemoryBuffer : private Allocator, public Buffer<T> {
private:
@ -670,7 +686,7 @@ class MemoryBuffer : private Allocator, public Buffer<T> {
}
protected:
void grow(std::size_t size);
void grow(std::size_t size) FMT_OVERRIDE;
public:
explicit MemoryBuffer(const Allocator &alloc = Allocator())
@ -830,6 +846,16 @@ struct FMT_API BasicData {
static const char DIGITS[];
};
#ifndef FMT_USE_EXTERN_TEMPLATES
// Clang doesn't have a feature check for extern templates so we check
// for variadic templates which were introduced in the same version.
# define FMT_USE_EXTERN_TEMPLATES (__clang__ && FMT_USE_VARIADIC_TEMPLATES)
#endif
#if FMT_USE_EXTERN_TEMPLATES && !defined(FMT_HEADER_ONLY)
extern template struct BasicData<void>;
#endif
typedef BasicData<> Data;
#ifdef FMT_BUILTIN_CLZLL
@ -918,6 +944,7 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits,
}
unsigned index = static_cast<unsigned>(value * 2);
*--buffer = Data::DIGITS[index + 1];
thousands_sep(buffer);
*--buffer = Data::DIGITS[index];
}
@ -1105,6 +1132,21 @@ struct Not { enum { value = 0 }; };
template<>
struct Not<false> { enum { value = 1 }; };
template<typename T, T> struct LConvCheck {
LConvCheck(int) {}
};
// Returns the thousands separator for the current locale.
// We check if ``lconv`` contains ``thousands_sep`` because on Android
// ``lconv`` is stubbed as an empty struct.
template <typename LConv>
inline StringRef thousands_sep(
LConv *lc, LConvCheck<char *LConv::*, &LConv::thousands_sep> = 0) {
return lc->thousands_sep;
}
inline fmt::StringRef thousands_sep(...) { return ""; }
// Makes an Arg object from any type.
template <typename Formatter>
class MakeValue : public Arg {
@ -1126,7 +1168,7 @@ class MakeValue : public Arg {
// characters and strings into narrow strings as in
// fmt::format("{}", L"test");
// To fix this, use a wide format string: fmt::format(L"{}", L"test").
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
#if !FMT_MSC_VER || defined(_NATIVE_WCHAR_T_DEFINED)
MakeValue(typename WCharHelper<wchar_t, Char>::Unsupported);
#endif
MakeValue(typename WCharHelper<wchar_t *, Char>::Unsupported);
@ -1172,7 +1214,7 @@ class MakeValue : public Arg {
MakeValue(long value) {
// To minimize the number of types we need to deal with, long is
// translated either to int or to long long depending on its size.
if (check(sizeof(long) == sizeof(int)))
if (const_check(sizeof(long) == sizeof(int)))
int_value = static_cast<int>(value);
else
long_long_value = value;
@ -1182,7 +1224,7 @@ class MakeValue : public Arg {
}
MakeValue(unsigned long value) {
if (check(sizeof(unsigned long) == sizeof(unsigned)))
if (const_check(sizeof(unsigned long) == sizeof(unsigned)))
uint_value = static_cast<unsigned>(value);
else
ulong_long_value = value;
@ -1214,7 +1256,9 @@ class MakeValue : public Arg {
FMT_MAKE_VALUE(char *, string.value, CSTRING)
FMT_MAKE_VALUE(const char *, string.value, CSTRING)
FMT_MAKE_VALUE(signed char *, sstring.value, CSTRING)
FMT_MAKE_VALUE(const signed char *, sstring.value, CSTRING)
FMT_MAKE_VALUE(unsigned char *, ustring.value, CSTRING)
FMT_MAKE_VALUE(const unsigned char *, ustring.value, CSTRING)
FMT_MAKE_STR_VALUE(const std::string &, STRING)
FMT_MAKE_STR_VALUE(StringRef, STRING)
@ -1268,7 +1312,7 @@ public:
MakeArg() {
type = Arg::NONE;
}
template <typename T>
MakeArg(const T &value)
: Arg(MakeValue<Formatter>(value)) {
@ -1288,6 +1332,7 @@ struct NamedArg : Arg {
class RuntimeError : public std::runtime_error {
protected:
RuntimeError() : std::runtime_error("") {}
~RuntimeError() throw();
};
template <typename Char>
@ -1487,9 +1532,10 @@ class ArgVisitor {
*/
Result visit(const Arg &arg) {
switch (arg.type) {
default:
case Arg::NONE:
case Arg::NAMED_ARG:
FMT_ASSERT(false, "invalid argument type");
return Result();
break;
case Arg::INT:
return FMT_DISPATCH(visit_int(arg.int_value));
case Arg::UINT:
@ -1517,6 +1563,7 @@ class ArgVisitor {
case Arg::CUSTOM:
return FMT_DISPATCH(visit_custom(arg.custom));
}
return Result();
}
};
@ -1822,21 +1869,21 @@ class ArgFormatterBase : public ArgVisitor<Impl, void> {
typedef typename BasicWriter<Char>::CharPtr CharPtr;
Char fill = internal::CharTraits<Char>::cast(spec_.fill());
CharPtr out = CharPtr();
const unsigned CHAR_WIDTH = 1;
if (spec_.width_ > CHAR_WIDTH) {
const unsigned CHAR_SIZE = 1;
if (spec_.width_ > CHAR_SIZE) {
out = writer_.grow_buffer(spec_.width_);
if (spec_.align_ == ALIGN_RIGHT) {
std::uninitialized_fill_n(out, spec_.width_ - CHAR_WIDTH, fill);
out += spec_.width_ - CHAR_WIDTH;
std::uninitialized_fill_n(out, spec_.width_ - CHAR_SIZE, fill);
out += spec_.width_ - CHAR_SIZE;
} else if (spec_.align_ == ALIGN_CENTER) {
out = writer_.fill_padding(out, spec_.width_,
internal::check(CHAR_WIDTH), fill);
internal::const_check(CHAR_SIZE), fill);
} else {
std::uninitialized_fill_n(out + CHAR_WIDTH,
spec_.width_ - CHAR_WIDTH, fill);
std::uninitialized_fill_n(out + CHAR_SIZE,
spec_.width_ - CHAR_SIZE, fill);
}
} else {
out = writer_.grow_buffer(CHAR_WIDTH);
out = writer_.grow_buffer(CHAR_SIZE);
}
*out = internal::CharTraits<Char>::cast(value);
}
@ -2063,7 +2110,7 @@ struct ArgArray;
template <unsigned N>
struct ArgArray<N, true/*IsPacked*/> {
typedef Value Type[N > 0 ? N : 1];
template <typename Formatter, typename T>
static Value make(const T &value) {
#ifdef __clang__
@ -2258,6 +2305,8 @@ class SystemError : public internal::RuntimeError {
}
FMT_VARIADIC_CTOR(SystemError, init, int, CStringRef)
~SystemError() throw();
int error_code() const { return error_code_; }
};
@ -2588,7 +2637,6 @@ void BasicWriter<Char>::write_str(
if (str_size == 0) {
if (!str_value) {
FMT_THROW(FormatError("string pointer is null"));
return;
}
}
std::size_t precision = static_cast<std::size_t>(spec.precision_);
@ -2753,9 +2801,12 @@ void BasicWriter<Char>::write_int(T value, Spec spec) {
}
case 'n': {
unsigned num_digits = internal::count_digits(abs_value);
fmt::StringRef sep = std::localeconv()->thousands_sep;
fmt::StringRef sep = "";
#ifndef ANDROID
sep = internal::thousands_sep(std::localeconv());
#endif
unsigned size = static_cast<unsigned>(
num_digits + sep.size() * (num_digits - 1) / 3);
num_digits + sep.size() * ((num_digits - 1) / 3));
CharPtr p = prepare_int_buffer(size, spec, prefix, prefix_size) + 1;
internal::format_decimal(get(p), abs_value, 0, internal::ThousandsSep(sep));
break;
@ -2780,7 +2831,7 @@ void BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
case 'e': case 'f': case 'g': case 'a':
break;
case 'F':
#ifdef _MSC_VER
#if FMT_MSC_VER
// MSVC's printf doesn't support 'F'.
type = 'f';
#endif
@ -2873,7 +2924,7 @@ void BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
Char *start = 0;
for (;;) {
std::size_t buffer_size = buffer_.capacity() - offset;
#ifdef _MSC_VER
#if FMT_MSC_VER
// MSVC's vsnprintf_s doesn't work with zero size, so reserve
// space for at least one extra character to make the size non-zero.
// Note that the buffer's capacity will increase by more than 1.

View File

@ -4,25 +4,7 @@
Copyright (c) 2012 - 2016, Victor Zverovich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
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.
For the license information refer to format.h.
*/
#include "ostream.h"

View File

@ -4,25 +4,7 @@
Copyright (c) 2012 - 2016, Victor Zverovich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
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.
For the license information refer to format.h.
*/
#ifndef FMT_OSTREAM_H_

View File

@ -1,28 +1,10 @@
/*
A C++ interface to POSIX functions.
Copyright (c) 2014 - 2016, Victor Zverovich
Copyright (c) 2012 - 2016, Victor Zverovich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
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.
For the license information refer to format.h.
*/
// Disable bogus MSVC warnings.
@ -90,7 +72,7 @@ fmt::BufferedFile::BufferedFile(
fmt::CStringRef filename, fmt::CStringRef mode) {
FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), 0);
if (!file_)
throw SystemError(errno, "cannot open file {}", filename);
FMT_THROW(SystemError(errno, "cannot open file {}", filename));
}
void fmt::BufferedFile::close() {
@ -99,7 +81,7 @@ void fmt::BufferedFile::close() {
int result = FMT_SYSTEM(fclose(file_));
file_ = 0;
if (result != 0)
throw SystemError(errno, "cannot close file");
FMT_THROW(SystemError(errno, "cannot close file"));
}
// A macro used to prevent expansion of fileno on broken versions of MinGW.
@ -108,7 +90,7 @@ void fmt::BufferedFile::close() {
int fmt::BufferedFile::fileno() const {
int fd = FMT_POSIX_CALL(fileno FMT_ARGS(file_));
if (fd == -1)
throw SystemError(errno, "cannot get file descriptor");
FMT_THROW(SystemError(errno, "cannot get file descriptor"));
return fd;
}
@ -121,7 +103,7 @@ fmt::File::File(fmt::CStringRef path, int oflag) {
FMT_RETRY(fd_, FMT_POSIX_CALL(open(path.c_str(), oflag, mode)));
#endif
if (fd_ == -1)
throw SystemError(errno, "cannot open file {}", path);
FMT_THROW(SystemError(errno, "cannot open file {}", path));
}
fmt::File::~File() FMT_NOEXCEPT {
@ -139,7 +121,7 @@ void fmt::File::close() {
int result = FMT_POSIX_CALL(close(fd_));
fd_ = -1;
if (result != 0)
throw SystemError(errno, "cannot close file");
FMT_THROW(SystemError(errno, "cannot close file"));
}
fmt::LongLong fmt::File::size() const {
@ -153,7 +135,7 @@ fmt::LongLong fmt::File::size() const {
if (size_lower == INVALID_FILE_SIZE) {
DWORD error = GetLastError();
if (error != NO_ERROR)
throw WindowsError(GetLastError(), "cannot get file size");
FMT_THROW(WindowsError(GetLastError(), "cannot get file size"));
}
fmt::ULongLong long_size = size_upper;
return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower;
@ -161,7 +143,7 @@ fmt::LongLong fmt::File::size() const {
typedef struct stat Stat;
Stat file_stat = Stat();
if (FMT_POSIX_CALL(fstat(fd_, &file_stat)) == -1)
throw SystemError(errno, "cannot get file attributes");
FMT_THROW(SystemError(errno, "cannot get file attributes"));
FMT_STATIC_ASSERT(sizeof(fmt::LongLong) >= sizeof(file_stat.st_size),
"return type of File::size is not large enough");
return file_stat.st_size;
@ -172,7 +154,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) {
RWResult result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count))));
if (result < 0)
throw SystemError(errno, "cannot read from file");
FMT_THROW(SystemError(errno, "cannot read from file"));
return internal::to_unsigned(result);
}
@ -180,7 +162,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) {
RWResult result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(write(fd_, buffer, convert_rwcount(count))));
if (result < 0)
throw SystemError(errno, "cannot write to file");
FMT_THROW(SystemError(errno, "cannot write to file"));
return internal::to_unsigned(result);
}
@ -189,7 +171,7 @@ fmt::File fmt::File::dup(int fd) {
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html
int new_fd = FMT_POSIX_CALL(dup(fd));
if (new_fd == -1)
throw SystemError(errno, "cannot duplicate file descriptor {}", fd);
FMT_THROW(SystemError(errno, "cannot duplicate file descriptor {}", fd));
return File(new_fd);
}
@ -197,8 +179,8 @@ void fmt::File::dup2(int fd) {
int result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd)));
if (result == -1) {
throw SystemError(errno,
"cannot duplicate file descriptor {} to {}", fd_, fd);
FMT_THROW(SystemError(errno,
"cannot duplicate file descriptor {} to {}", fd_, fd));
}
}
@ -225,7 +207,7 @@ void fmt::File::pipe(File &read_end, File &write_end) {
int result = FMT_POSIX_CALL(pipe(fds));
#endif
if (result != 0)
throw SystemError(errno, "cannot create pipe");
FMT_THROW(SystemError(errno, "cannot create pipe"));
// The following assignments don't throw because read_fd and write_fd
// are closed.
read_end = File(fds[0]);
@ -236,7 +218,7 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) {
// Don't retry as fdopen doesn't return EINTR.
FILE *f = FMT_POSIX_CALL(fdopen(fd_, mode));
if (!f)
throw SystemError(errno, "cannot associate stream with file descriptor");
FMT_THROW(SystemError(errno, "cannot associate stream with file descriptor"));
BufferedFile file(f);
fd_ = -1;
return file;
@ -250,7 +232,7 @@ long fmt::getpagesize() {
#else
long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE));
if (size < 0)
throw SystemError(errno, "cannot get memory page size");
FMT_THROW(SystemError(errno, "cannot get memory page size"));
return size;
#endif
}

View File

@ -1,34 +1,16 @@
/*
A C++ interface to POSIX functions.
Copyright (c) 2014 - 2016, Victor Zverovich
Copyright (c) 2012 - 2016, Victor Zverovich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
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.
For the license information refer to format.h.
*/
#ifndef FMT_POSIX_H_
#define FMT_POSIX_H_
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(__CYGWIN__)
// Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/.
# undef __STRICT_ANSI__
#endif
@ -41,7 +23,7 @@
#include <cstddef>
#ifdef __APPLE__
#if defined __APPLE__ || defined(__FreeBSD__)
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X
#endif
@ -339,7 +321,8 @@ class File {
// Returns the memory page size.
long getpagesize();
#if defined(LC_NUMERIC_MASK) || defined(_MSC_VER)
#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \
!defined(__ANDROID__) && !defined(__CYGWIN__)
# define FMT_LOCALE
#endif
@ -374,7 +357,7 @@ class Locale {
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", NULL)) {
if (!locale_)
throw fmt::SystemError(errno, "cannot create locale");
FMT_THROW(fmt::SystemError(errno, "cannot create locale"));
}
~Locale() { freelocale(locale_); }

View File

@ -4,31 +4,13 @@
Copyright (c) 2012 - 2016, Victor Zverovich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
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.
For the license information refer to format.h.
*/
#ifndef FMT_TIME_H_
#define FMT_TIME_H_
#include "fmt/format.h"
#include "format.h"
#include <ctime>
namespace fmt {
@ -54,8 +36,15 @@ void format(BasicFormatter<char, ArgFormatter> &f,
buffer.resize(start + count);
break;
}
if (size >= format.size() * 256) {
// If the buffer is 256 times larger than the format string, assume
// that `strftime` gives an empty result. There doesn't seem to be a
// better way to distinguish the two cases:
// https://github.com/fmtlib/fmt/issues/367
break;
}
const std::size_t MIN_GROWTH = 10;
buffer.reserve(buffer.capacity() + size > MIN_GROWTH ? size : MIN_GROWTH);
buffer.reserve(buffer.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
}
format_str = end + 1;
}

View File

@ -20,3 +20,7 @@ build_script:
on_failure:
- appveyor PushArtifact Testing/Temporary/LastTest.log
- appveyor AddTest test
# Uncomment this to debug AppVeyor failures.
#on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

View File

@ -37,6 +37,11 @@ if (FMT_USE_CPP11)
endif ()
endif ()
if (CMAKE_CXX_STANDARD)
# Don't use -std compiler flag if CMAKE_CXX_STANDARD is specified.
set(CPP11_FLAG )
endif ()
set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG})
# Check if variadic templates are working and not affected by GCC bug 39653:

View File

@ -56,11 +56,19 @@ if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wno-long-long -Wno-variadic-macros)
endif ()
function(add_fmt_executable name)
add_executable(${name} ${ARGN})
if (MINGW)
target_link_libraries(${name} -static-libgcc -static-libstdc++)
endif ()
endfunction()
# Adds a test.
# Usage: add_fmt_test(name srcs...)
function(add_fmt_test name)
add_executable(${name} ${name}.cc ${ARGN})
add_fmt_executable(${name} ${name}.cc ${ARGN})
target_link_libraries(${name} test-main)
# define if certain c++ features can be used
target_compile_definitions(${name} PRIVATE
FMT_USE_TYPE_TRAITS=$<BOOL:${SUPPORTS_TYPE_TRAITS}>
@ -77,9 +85,11 @@ add_fmt_test(format-test)
add_fmt_test(format-impl-test)
add_fmt_test(ostream-test)
add_fmt_test(printf-test)
add_fmt_test(time-test)
add_fmt_test(util-test mock-allocator.h)
add_fmt_test(macro-test)
# Enable stricter options for one test to make sure that the header is free of
# warnings.
if (FMT_PEDANTIC AND MSVC)
@ -87,7 +97,8 @@ if (FMT_PEDANTIC AND MSVC)
endif ()
if (HAVE_OPEN)
add_executable(posix-mock-test posix-mock-test.cc ../fmt/format.cc ${TEST_MAIN_SRC})
add_fmt_executable(posix-mock-test
posix-mock-test.cc ../fmt/format.cc ${TEST_MAIN_SRC})
target_include_directories(posix-mock-test PRIVATE ${PROJECT_SOURCE_DIR})
target_compile_definitions(posix-mock-test PRIVATE FMT_USE_FILE_DESCRIPTORS=1)
target_link_libraries(posix-mock-test gmock)
@ -95,7 +106,7 @@ if (HAVE_OPEN)
add_fmt_test(posix-test)
endif ()
add_executable(header-only-test
add_fmt_executable(header-only-test
header-only-test.cc header-only-test2.cc test-main.cc)
target_link_libraries(header-only-test gmock)
if (TARGET fmt-header-only)
@ -109,6 +120,7 @@ endif ()
check_cxx_compiler_flag(-fno-exceptions HAVE_FNO_EXCEPTIONS_FLAG)
if (HAVE_FNO_EXCEPTIONS_FLAG)
add_library(noexception-test ../fmt/format.cc)
target_include_directories(noexception-test PRIVATE ${PROJECT_SOURCE_DIR})
target_compile_options(noexception-test PRIVATE -fno-exceptions)
endif ()
@ -116,6 +128,7 @@ if (FMT_PEDANTIC)
# Test that the library compiles without windows.h.
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_library(no-windows-h-test ../fmt/format.cc)
target_include_directories(no-windows-h-test PRIVATE ${PROJECT_SOURCE_DIR})
target_compile_definitions(no-windows-h-test PRIVATE FMT_USE_WINDOWS_H=0)
endif ()

View File

@ -43,8 +43,23 @@
// Test that the library compiles if None is defined to 0 as done by xlib.h.
#define None 0
struct LocaleMock {
static LocaleMock *instance;
MOCK_METHOD0(localeconv, lconv *());
} *LocaleMock::instance;
namespace fmt {
namespace std {
using namespace ::std;
lconv *localeconv() {
return LocaleMock::instance ?
LocaleMock::instance->localeconv() : ::std::localeconv();
}
}
}
#include "fmt/format.h"
#include "fmt/time.h"
#include "util.h"
#include "mock-allocator.h"
@ -917,7 +932,7 @@ TEST(FormatterTest, RuntimeWidth) {
FormatError, "number is too big");
EXPECT_THROW_MSG(format("{0:{1}}", 0, -1l),
FormatError, "negative width");
if (fmt::internal::check(sizeof(long) > sizeof(int))) {
if (fmt::internal::const_check(sizeof(long) > sizeof(int))) {
long value = INT_MAX;
EXPECT_THROW_MSG(format("{0:{1}}", 0, (value + 1)),
FormatError, "number is too big");
@ -1036,7 +1051,7 @@ TEST(FormatterTest, RuntimePrecision) {
FormatError, "number is too big");
EXPECT_THROW_MSG(format("{0:.{1}}", 0, -1l),
FormatError, "negative precision");
if (fmt::internal::check(sizeof(long) > sizeof(int))) {
if (fmt::internal::const_check(sizeof(long) > sizeof(int))) {
long value = INT_MAX;
EXPECT_THROW_MSG(format("{0:.{1}}", 0, (value + 1)),
FormatError, "number is too big");
@ -1209,13 +1224,14 @@ TEST(FormatterTest, FormatOct) {
}
TEST(FormatterTest, FormatIntLocale) {
#ifndef _WIN32
const char *locale = "en_US.utf-8";
#else
const char *locale = "English_United States";
#endif
std::setlocale(LC_ALL, locale);
EXPECT_EQ("1,234,567", format("{:n}", 1234567));
ScopedMock<LocaleMock> mock;
lconv lc = {};
char sep[] = "--";
lc.thousands_sep = sep;
EXPECT_CALL(mock, localeconv()).Times(3).WillRepeatedly(testing::Return(&lc));
EXPECT_EQ("123", format("{:n}", 123));
EXPECT_EQ("1--234", format("{:n}", 1234));
EXPECT_EQ("1--234--567", format("{:n}", 1234567));
}
TEST(FormatterTest, FormatFloat) {
@ -1327,6 +1343,8 @@ TEST(FormatterTest, FormatUCharString) {
EXPECT_EQ("test", format("{0:s}", str));
const unsigned char *const_str = str;
EXPECT_EQ("test", format("{0:s}", const_str));
unsigned char *ptr = str;
EXPECT_EQ("test", format("{0:s}", ptr));
}
TEST(FormatterTest, FormatPointer) {
@ -1534,15 +1552,6 @@ TEST(FormatTest, Variadic) {
EXPECT_EQ(L"abc1", format(L"{}c{}", L"ab", 1));
}
TEST(FormatTest, Time) {
std::tm tm = std::tm();
tm.tm_year = 116;
tm.tm_mon = 3;
tm.tm_mday = 25;
EXPECT_EQ("The date is 2016-04-25.",
fmt::format("The date is {:%Y-%m-%d}.", tm));
}
template <typename T>
std::string str(const T &value) {
return fmt::format("{}", value);

View File

@ -10090,8 +10090,9 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// threads concurrently.
Result InvokeWith(const ArgumentTuple& args)
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
return static_cast<const ResultHolder*>(
this->UntypedInvokeWith(&args))->GetValueAndDelete();
const ResultHolder *rh = static_cast<const ResultHolder*>(
this->UntypedInvokeWith(&args));
return rh ? rh->GetValueAndDelete() : Result();
}
// Adds and returns a default action spec for this mock function.

View File

@ -29,7 +29,7 @@
#define FMT_GTEST_EXTRA_H_
#include <string>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "fmt/format.h"
@ -172,4 +172,10 @@ std::string read(fmt::File &f, std::size_t count);
#endif // FMT_USE_FILE_DESCRIPTORS
template <typename Mock>
struct ScopedMock : testing::StrictMock<Mock> {
ScopedMock() { Mock::instance = this; }
~ScopedMock() { Mock::instance = 0; }
};
#endif // FMT_GTEST_EXTRA_H_

View File

@ -453,12 +453,6 @@ TEST(BufferedFileTest, FilenoNoRetry) {
fileno_count = 0;
}
template <typename Mock>
struct ScopedMock : testing::StrictMock<Mock> {
ScopedMock() { Mock::instance = this; }
~ScopedMock() { Mock::instance = 0; }
};
struct TestMock {
static TestMock *instance;
} *TestMock::instance;

View File

@ -232,7 +232,7 @@ TEST(FileTest, MoveAssignmentClosesFile) {
File OpenBufferedFile(int &fd) {
File f = open_file();
fd = f.descriptor();
return std::move(f);
return f;
}
TEST(FileTest, MoveFromTemporaryInCtor) {

View File

@ -295,12 +295,13 @@ void TestLength(const char *length_spec, U value) {
fmt::LongLong signed_value = 0;
fmt::ULongLong unsigned_value = 0;
// Apply integer promotion to the argument.
fmt::ULongLong max = std::numeric_limits<U>::max();
using fmt::internal::check;
if (check(max <= static_cast<unsigned>(std::numeric_limits<int>::max()))) {
using std::numeric_limits;
fmt::ULongLong max = numeric_limits<U>::max();
using fmt::internal::const_check;
if (const_check(max <= static_cast<unsigned>(numeric_limits<int>::max()))) {
signed_value = static_cast<int>(value);
unsigned_value = static_cast<unsigned>(value);
} else if (check(max <= std::numeric_limits<unsigned>::max())) {
} else if (const_check(max <= numeric_limits<unsigned>::max())) {
signed_value = static_cast<unsigned>(value);
unsigned_value = static_cast<unsigned>(value);
}

33
test/time-test.cc Normal file
View File

@ -0,0 +1,33 @@
/*
Time formatting tests
Copyright (c) 2012 - 2016, Victor Zverovich
All rights reserved.
For the license information refer to format.h.
*/
#include "gmock/gmock.h"
#include "fmt/time.h"
TEST(TimeTest, Format) {
std::tm tm = std::tm();
tm.tm_year = 116;
tm.tm_mon = 3;
tm.tm_mday = 25;
EXPECT_EQ("The date is 2016-04-25.",
fmt::format("The date is {:%Y-%m-%d}.", tm));
}
TEST(TimeTest, GrowBuffer) {
std::string s = "{:";
for (int i = 0; i < 30; ++i)
s += "%c";
s += "}\n";
std::time_t t = std::time(0);
fmt::format(s, *std::localtime(&t));
}
TEST(TimeTest, EmptyResult) {
EXPECT_EQ("", fmt::format("{}", std::tm()));
}

View File

@ -708,7 +708,7 @@ TEST(ArgVisitorTest, VisitUnhandledArg) {
TEST(ArgVisitorTest, VisitInvalidArg) {
Arg arg = Arg();
arg.type = static_cast<Arg::Type>(Arg::CUSTOM + 1);
arg.type = static_cast<Arg::Type>(Arg::NONE);
EXPECT_ASSERT(TestVisitor().visit(arg), "invalid argument type");
}
@ -956,3 +956,17 @@ TEST(UtilTest, Conditional) {
fmt::internal::Conditional<false, int, char>::type *pc = &c;
(void)pc;
}
struct TestLConv {
char *thousands_sep;
};
struct EmptyLConv {};
TEST(UtilTest, ThousandsSep) {
char foo[] = "foo";
TestLConv lc = {foo};
EXPECT_EQ("foo", fmt::internal::thousands_sep(&lc).to_string());
EmptyLConv empty_lc;
EXPECT_EQ("", fmt::internal::thousands_sep(&empty_lc));
}