Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
9393fe26
Commit
9393fe26
authored
Jul 25, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prepare -> compile
parent
b48ffc14
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
54 deletions
+55
-54
CMakeLists.txt
CMakeLists.txt
+3
-2
include/fmt/compile.h
include/fmt/compile.h
+11
-11
test/CMakeLists.txt
test/CMakeLists.txt
+4
-4
test/compile-error-test/CMakeLists.txt
test/compile-error-test/CMakeLists.txt
+0
-0
test/compile-test.cc
test/compile-test.cc
+37
-37
No files found.
CMakeLists.txt
View file @
9393fe26
...
@@ -151,8 +151,9 @@ function(add_headers VAR)
...
@@ -151,8 +151,9 @@ function(add_headers VAR)
endfunction
()
endfunction
()
# Define the fmt library, its includes and the needed defines.
# Define the fmt library, its includes and the needed defines.
add_headers
(
FMT_HEADERS chrono.h color.h core.h format.h format-inl.h locale.h
add_headers
(
FMT_HEADERS chrono.h color.h compile.h core.h format.h format-inl.h
ostream.h prepare.h printf.h ranges.h safe-duration-cast.h
)
locale.h ostream.h printf.h ranges.h
safe-duration-cast.h
)
set
(
FMT_SOURCES src/format.cc
)
set
(
FMT_SOURCES src/format.cc
)
if
(
HAVE_OPEN
)
if
(
HAVE_OPEN
)
add_headers
(
FMT_HEADERS posix.h
)
add_headers
(
FMT_HEADERS posix.h
)
...
...
include/fmt/
prepar
e.h
→
include/fmt/
compil
e.h
View file @
9393fe26
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
//
//
// For the license information refer to format.h.
// For the license information refer to format.h.
#ifndef FMT_
PREPAR
E_H_
#ifndef FMT_
COMPIL
E_H_
#define FMT_
PREPAR
E_H_
#define FMT_
COMPIL
E_H_
#ifndef FMT_HAS_CONSTRUCTIBLE_TRAITS
#ifndef FMT_HAS_CONSTRUCTIBLE_TRAITS
# define FMT_HAS_CONSTRUCTIBLE_TRAITS \
# define FMT_HAS_CONSTRUCTIBLE_TRAITS \
...
@@ -728,41 +728,41 @@ using wprepared_format_t =
...
@@ -728,41 +728,41 @@ using wprepared_format_t =
#if FMT_USE_CONSTEXPR
#if FMT_USE_CONSTEXPR
template
<
typename
...
Args
,
typename
Format
>
template
<
typename
...
Args
,
typename
Format
>
FMT_CONSTEXPR
auto
prepar
e
(
Format
format
)
{
FMT_CONSTEXPR
auto
compil
e
(
Format
format
)
{
return
internal
::
do_prepare
<
Format
,
Args
...
>
(
return
internal
::
do_prepare
<
Format
,
Args
...
>
(
typename
internal
::
format_tag
<
Format
>::
type
{},
std
::
move
(
format
));
typename
internal
::
format_tag
<
Format
>::
type
{},
std
::
move
(
format
));
}
}
#else
#else
template
<
typename
...
Args
,
typename
Format
>
template
<
typename
...
Args
,
typename
Format
>
auto
prepar
e
(
Format
format
)
->
auto
compil
e
(
Format
format
)
->
typename
internal
::
preparator
<
Format
,
Args
...
>::
prepared_format_type
{
typename
internal
::
preparator
<
Format
,
Args
...
>::
prepared_format_type
{
return
internal
::
preparator
<
Format
,
Args
...
>::
prepare
(
std
::
move
(
format
));
return
internal
::
preparator
<
Format
,
Args
...
>::
prepare
(
std
::
move
(
format
));
}
}
#endif
#endif
template
<
typename
...
Args
,
typename
Char
>
template
<
typename
...
Args
,
typename
Char
>
auto
prepar
e
(
const
Char
*
format
)
->
auto
compil
e
(
const
Char
*
format
)
->
typename
internal
::
preparator
<
std
::
basic_string
<
Char
>
,
typename
internal
::
preparator
<
std
::
basic_string
<
Char
>
,
Args
...
>::
prepared_format_type
{
Args
...
>::
prepared_format_type
{
return
prepar
e
<
Args
...
>
(
internal
::
to_runtime_format
(
format
));
return
compil
e
<
Args
...
>
(
internal
::
to_runtime_format
(
format
));
}
}
template
<
typename
...
Args
,
typename
Char
,
unsigned
N
>
template
<
typename
...
Args
,
typename
Char
,
unsigned
N
>
auto
prepar
e
(
const
Char
(
format
)[
N
])
->
auto
compil
e
(
const
Char
(
format
)[
N
])
->
typename
internal
::
preparator
<
std
::
basic_string
<
Char
>
,
typename
internal
::
preparator
<
std
::
basic_string
<
Char
>
,
Args
...
>::
prepared_format_type
{
Args
...
>::
prepared_format_type
{
const
auto
view
=
basic_string_view
<
Char
>
(
format
,
N
);
const
auto
view
=
basic_string_view
<
Char
>
(
format
,
N
);
return
prepar
e
<
Args
...
>
(
internal
::
to_runtime_format
(
view
));
return
compil
e
<
Args
...
>
(
internal
::
to_runtime_format
(
view
));
}
}
template
<
typename
...
Args
,
typename
Char
>
template
<
typename
...
Args
,
typename
Char
>
auto
prepar
e
(
basic_string_view
<
Char
>
format
)
->
auto
compil
e
(
basic_string_view
<
Char
>
format
)
->
typename
internal
::
preparator
<
std
::
basic_string
<
Char
>
,
typename
internal
::
preparator
<
std
::
basic_string
<
Char
>
,
Args
...
>::
prepared_format_type
{
Args
...
>::
prepared_format_type
{
return
prepar
e
<
Args
...
>
(
internal
::
to_runtime_format
(
format
));
return
compil
e
<
Args
...
>
(
internal
::
to_runtime_format
(
format
));
}
}
FMT_END_NAMESPACE
FMT_END_NAMESPACE
#endif // FMT_
PREPAR
E_H_
#endif // FMT_
COMPIL
E_H_
test/CMakeLists.txt
View file @
9393fe26
...
@@ -101,7 +101,7 @@ if (NOT (MSVC AND BUILD_SHARED_LIBS))
...
@@ -101,7 +101,7 @@ if (NOT (MSVC AND BUILD_SHARED_LIBS))
endif
()
endif
()
add_fmt_test
(
locale-test
)
add_fmt_test
(
locale-test
)
add_fmt_test
(
ostream-test
)
add_fmt_test
(
ostream-test
)
add_fmt_test
(
prepar
e-test
)
add_fmt_test
(
compil
e-test
)
add_fmt_test
(
printf-test
)
add_fmt_test
(
printf-test
)
add_fmt_test
(
custom-formatter-test
)
add_fmt_test
(
custom-formatter-test
)
add_fmt_test
(
ranges-test
)
add_fmt_test
(
ranges-test
)
...
@@ -180,10 +180,10 @@ if (FMT_PEDANTIC)
...
@@ -180,10 +180,10 @@ if (FMT_PEDANTIC)
target_include_directories
(
no-windows-h-test SYSTEM PUBLIC gtest gmock
)
target_include_directories
(
no-windows-h-test SYSTEM PUBLIC gtest gmock
)
endif
()
endif
()
add_test
(
compile-test
${
CMAKE_CTEST_COMMAND
}
add_test
(
compile-
error-
test
${
CMAKE_CTEST_COMMAND
}
--build-and-test
--build-and-test
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/compile-test"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/compile-
error-
test"
"
${
CMAKE_CURRENT_BINARY_DIR
}
/compile-test"
"
${
CMAKE_CURRENT_BINARY_DIR
}
/compile-
error-
test"
--build-generator
${
CMAKE_GENERATOR
}
--build-generator
${
CMAKE_GENERATOR
}
--build-makeprogram
${
CMAKE_MAKE_PROGRAM
}
--build-makeprogram
${
CMAKE_MAKE_PROGRAM
}
--build-options
--build-options
...
...
test/compile-test/CMakeLists.txt
→
test/compile-
error-
test/CMakeLists.txt
View file @
9393fe26
File moved
test/
prepar
e-test.cc
→
test/
compil
e-test.cc
View file @
9393fe26
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
// Copyright (c) 2012 - present, Victor Zverovich
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
// All rights reserved.
//
//
// For the license information refer to
prepare
.h.
// For the license information refer to
format
.h.
#include <stdint.h>
#include <stdint.h>
#include <cctype>
#include <cctype>
...
@@ -16,12 +16,12 @@
...
@@ -16,12 +16,12 @@
#include <memory>
#include <memory>
#include <string>
#include <string>
// Check if fmt/
prepar
e.h compiles with windows.h included before it.
// Check if fmt/
compil
e.h compiles with windows.h included before it.
#ifdef _WIN32
#ifdef _WIN32
# include <windows.h>
# include <windows.h>
#endif
#endif
#include "fmt/
prepar
e.h"
#include "fmt/
compil
e.h"
#include "gmock.h"
#include "gmock.h"
#include "gtest-extra.h"
#include "gtest-extra.h"
#include "mock-allocator.h"
#include "mock-allocator.h"
...
@@ -434,11 +434,11 @@ TEST(PrepareTest, CompileTimePreparedPartsTypeProvider) {
...
@@ -434,11 +434,11 @@ TEST(PrepareTest, CompileTimePreparedPartsTypeProvider) {
// Use the struct instead of a function to workaround GCC 4.4's 'sorry,
// Use the struct instead of a function to workaround GCC 4.4's 'sorry,
// unimplemented: mangling template_id_expr' issue.
// unimplemented: mangling template_id_expr' issue.
template
<
typename
...
Args
>
struct
copied_prepared_format_creator
{
template
<
typename
...
Args
>
struct
copied_prepared_format_creator
{
static
decltype
(
fmt
::
prepar
e
<
Args
...
>
(
std
::
declval
<
std
::
string
>
()))
make
(
static
decltype
(
fmt
::
compil
e
<
Args
...
>
(
std
::
declval
<
std
::
string
>
()))
make
(
std
::
string
format_str
)
{
std
::
string
format_str
)
{
auto
prepared_format
=
fmt
::
prepar
e
<
Args
...
>
(
std
::
move
(
format_str
));
auto
prepared_format
=
fmt
::
compil
e
<
Args
...
>
(
std
::
move
(
format_str
));
auto
copied_prepared_format
=
prepared_format
;
auto
copied_prepared_format
=
prepared_format
;
prepared_format
=
fmt
::
prepar
e
<
Args
...
>
(
""
);
prepared_format
=
fmt
::
compil
e
<
Args
...
>
(
""
);
return
copied_prepared_format
;
return
copied_prepared_format
;
}
}
...
@@ -478,9 +478,9 @@ TEST(PrepareTest, CopyPreparedFormat_InternalStringViewsAreNotInvalidated) {
...
@@ -478,9 +478,9 @@ TEST(PrepareTest, CopyPreparedFormat_InternalStringViewsAreNotInvalidated) {
TEST
(
PrepareTest
,
ReusedPreparedFormatType
)
{
TEST
(
PrepareTest
,
ReusedPreparedFormatType
)
{
typedef
fmt
::
prepared_format
<
std
::
string
,
int
>::
type
prepared_format
;
typedef
fmt
::
prepared_format
<
std
::
string
,
int
>::
type
prepared_format
;
prepared_format
prepared
=
fmt
::
prepar
e
<
prepared_format
>
(
"The {} is {}."
);
prepared_format
prepared
=
fmt
::
compil
e
<
prepared_format
>
(
"The {} is {}."
);
EXPECT_EQ
(
"The answer is 42."
,
prepared
.
format
(
"answer"
,
42
));
EXPECT_EQ
(
"The answer is 42."
,
prepared
.
format
(
"answer"
,
42
));
prepared
=
fmt
::
prepar
e
<
prepared_format
>
(
"40 {} 2 = {}"
);
prepared
=
fmt
::
compil
e
<
prepared_format
>
(
"40 {} 2 = {}"
);
EXPECT_EQ
(
"40 + 2 = 42"
,
prepared
.
format
(
"+"
,
42
));
EXPECT_EQ
(
"40 + 2 = 42"
,
prepared
.
format
(
"+"
,
42
));
}
}
...
@@ -491,9 +491,9 @@ TEST(PrepareTest, UserProvidedPartsContainerUnderlyingContainer) {
...
@@ -491,9 +491,9 @@ TEST(PrepareTest, UserProvidedPartsContainerUnderlyingContainer) {
typedef
fmt
::
basic_prepared_format
<
std
::
string
,
parts_container
,
std
::
string
,
typedef
fmt
::
basic_prepared_format
<
std
::
string
,
parts_container
,
std
::
string
,
int
>::
type
prepared_format
;
int
>::
type
prepared_format
;
prepared_format
prepared
=
fmt
::
prepar
e
<
prepared_format
>
(
"The {} is {}."
);
prepared_format
prepared
=
fmt
::
compil
e
<
prepared_format
>
(
"The {} is {}."
);
EXPECT_EQ
(
"The answer is 42."
,
prepared
.
format
(
"answer"
,
42
));
EXPECT_EQ
(
"The answer is 42."
,
prepared
.
format
(
"answer"
,
42
));
prepared
=
fmt
::
prepar
e
<
prepared_format
>
(
"40 {} 2 = {}"
);
prepared
=
fmt
::
compil
e
<
prepared_format
>
(
"40 {} 2 = {}"
);
EXPECT_EQ
(
"40 + 2 = 42"
,
prepared
.
format
(
"+"
,
42
));
EXPECT_EQ
(
"40 + 2 = 42"
,
prepared
.
format
(
"+"
,
42
));
}
}
...
@@ -535,67 +535,67 @@ TEST(PrepareTest, UserProvidedPartsContainer) {
...
@@ -535,67 +535,67 @@ TEST(PrepareTest, UserProvidedPartsContainer) {
typedef
fmt
::
basic_prepared_format
<
std
::
string
,
custom_parts_container
,
typedef
fmt
::
basic_prepared_format
<
std
::
string
,
custom_parts_container
,
std
::
string
,
int
>::
type
prepared_format
;
std
::
string
,
int
>::
type
prepared_format
;
prepared_format
prepared
=
fmt
::
prepar
e
<
prepared_format
>
(
"The {} is {}."
);
prepared_format
prepared
=
fmt
::
compil
e
<
prepared_format
>
(
"The {} is {}."
);
EXPECT_EQ
(
"The answer is 42."
,
prepared
.
format
(
"answer"
,
42
));
EXPECT_EQ
(
"The answer is 42."
,
prepared
.
format
(
"answer"
,
42
));
prepared
=
fmt
::
prepar
e
<
prepared_format
>
(
"40 {} 2 = {}"
);
prepared
=
fmt
::
compil
e
<
prepared_format
>
(
"40 {} 2 = {}"
);
EXPECT_EQ
(
"40 + 2 = 42"
,
prepared
.
format
(
"+"
,
42
));
EXPECT_EQ
(
"40 + 2 = 42"
,
prepared
.
format
(
"+"
,
42
));
}
}
TEST
(
PrepareTest
,
PassConstCharPointerFormat
)
{
TEST
(
PrepareTest
,
PassConstCharPointerFormat
)
{
const
char
*
c_format
=
"test {}"
;
const
char
*
c_format
=
"test {}"
;
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
c_format
);
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
c_format
);
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
const
wchar_t
*
wc_format
=
L"test {}"
;
const
wchar_t
*
wc_format
=
L"test {}"
;
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
wc_format
);
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
wc_format
);
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
}
}
TEST
(
PrepareTest
,
PassCharArrayFormat
)
{
TEST
(
PrepareTest
,
PassCharArrayFormat
)
{
char
c_format
[]
=
"test {}"
;
char
c_format
[]
=
"test {}"
;
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
c_format
);
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
c_format
);
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
wchar_t
wc_format
[]
=
L"test {}"
;
wchar_t
wc_format
[]
=
L"test {}"
;
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
wc_format
);
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
wc_format
);
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
}
}
TEST
(
PrepareTest
,
PassConstCharArrayFormat
)
{
TEST
(
PrepareTest
,
PassConstCharArrayFormat
)
{
const
char
c_format
[]
=
"test {}"
;
const
char
c_format
[]
=
"test {}"
;
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
c_format
);
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
c_format
);
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
const
wchar_t
wc_format
[]
=
L"test {}"
;
const
wchar_t
wc_format
[]
=
L"test {}"
;
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
wc_format
);
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
wc_format
);
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
}
}
TEST
(
PrepareTest
,
PassStringLiteralFormat
)
{
TEST
(
PrepareTest
,
PassStringLiteralFormat
)
{
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
"test {}"
);
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
"test {}"
);
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
L"test {}"
);
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
L"test {}"
);
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
}
}
TEST
(
PrepareTest
,
PassStringViewFormat
)
{
TEST
(
PrepareTest
,
PassStringViewFormat
)
{
const
auto
prepared
=
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
fmt
::
basic_string_view
<
char
>
(
"test {}"
));
fmt
::
compil
e
<
int
>
(
fmt
::
basic_string_view
<
char
>
(
"test {}"
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
const
auto
wprepared
=
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
fmt
::
basic_string_view
<
wchar_t
>
(
L"test {}"
));
fmt
::
compil
e
<
int
>
(
fmt
::
basic_string_view
<
wchar_t
>
(
L"test {}"
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
}
}
TEST
(
PrepareTest
,
PassBasicStringFormat
)
{
TEST
(
PrepareTest
,
PassBasicStringFormat
)
{
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
std
::
string
(
"test {}"
));
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
std
::
string
(
"test {}"
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
std
::
wstring
(
L"test {}"
));
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
std
::
wstring
(
L"test {}"
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
}
}
#if FMT_USE_CONSTEXPR
#if FMT_USE_CONSTEXPR
TEST
(
PrepareTest
,
PassCompileString
)
{
TEST
(
PrepareTest
,
PassCompileString
)
{
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
FMT_STRING
(
"test {}"
));
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
FMT_STRING
(
"test {}"
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
FMT_STRING
(
L"test {}"
));
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
FMT_STRING
(
L"test {}"
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
EXPECT_EQ
(
L"test 42"
,
wprepared
.
format
(
42
));
}
}
#endif
#endif
...
@@ -634,61 +634,61 @@ template <typename T> struct user_allocator {
...
@@ -634,61 +634,61 @@ template <typename T> struct user_allocator {
TEST
(
PrepareTest
,
PassUserTypeFormat
)
{
TEST
(
PrepareTest
,
PassUserTypeFormat
)
{
typedef
std
::
basic_string
<
char
,
std
::
char_traits
<
char
>
,
user_allocator
<
char
>>
typedef
std
::
basic_string
<
char
,
std
::
char_traits
<
char
>
,
user_allocator
<
char
>>
user_format
;
user_format
;
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
user_format
(
"test {}"
));
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
user_format
(
"test {}"
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
EXPECT_EQ
(
"test 42"
,
prepared
.
format
(
42
));
}
}
TEST
(
PrepareTest
,
FormatToArrayOfChars
)
{
TEST
(
PrepareTest
,
FormatToArrayOfChars
)
{
char
buffer
[
32
]
=
{
0
};
char
buffer
[
32
]
=
{
0
};
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
"4{}"
);
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
"4{}"
);
prepared
.
format_to
(
buffer
,
2
);
prepared
.
format_to
(
buffer
,
2
);
EXPECT_EQ
(
std
::
string
(
"42"
),
buffer
);
EXPECT_EQ
(
std
::
string
(
"42"
),
buffer
);
wchar_t
wbuffer
[
32
]
=
{
0
};
wchar_t
wbuffer
[
32
]
=
{
0
};
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
L"4{}"
);
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
L"4{}"
);
wprepared
.
format_to
(
wbuffer
,
2
);
wprepared
.
format_to
(
wbuffer
,
2
);
EXPECT_EQ
(
std
::
wstring
(
L"42"
),
wbuffer
);
EXPECT_EQ
(
std
::
wstring
(
L"42"
),
wbuffer
);
}
}
TEST
(
PrepareTest
,
FormatToIterator
)
{
TEST
(
PrepareTest
,
FormatToIterator
)
{
std
::
string
s
(
2
,
' '
);
std
::
string
s
(
2
,
' '
);
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
"4{}"
);
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
"4{}"
);
prepared
.
format_to
(
s
.
begin
(),
2
);
prepared
.
format_to
(
s
.
begin
(),
2
);
EXPECT_EQ
(
"42"
,
s
);
EXPECT_EQ
(
"42"
,
s
);
std
::
wstring
ws
(
2
,
L' '
);
std
::
wstring
ws
(
2
,
L' '
);
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
L"4{}"
);
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
L"4{}"
);
wprepared
.
format_to
(
ws
.
begin
(),
2
);
wprepared
.
format_to
(
ws
.
begin
(),
2
);
EXPECT_EQ
(
L"42"
,
ws
);
EXPECT_EQ
(
L"42"
,
ws
);
}
}
TEST
(
PrepareTest
,
FormatToBackInserter
)
{
TEST
(
PrepareTest
,
FormatToBackInserter
)
{
std
::
string
s
;
std
::
string
s
;
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
"4{}"
);
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
"4{}"
);
prepared
.
format_to
(
std
::
back_inserter
(
s
),
2
);
prepared
.
format_to
(
std
::
back_inserter
(
s
),
2
);
EXPECT_EQ
(
"42"
,
s
);
EXPECT_EQ
(
"42"
,
s
);
std
::
wstring
ws
;
std
::
wstring
ws
;
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
L"4{}"
);
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
L"4{}"
);
wprepared
.
format_to
(
std
::
back_inserter
(
ws
),
2
);
wprepared
.
format_to
(
std
::
back_inserter
(
ws
),
2
);
EXPECT_EQ
(
L"42"
,
ws
);
EXPECT_EQ
(
L"42"
,
ws
);
}
}
TEST
(
PrepareTest
,
FormatToBasicMemoryBuffer
)
{
TEST
(
PrepareTest
,
FormatToBasicMemoryBuffer
)
{
fmt
::
basic_memory_buffer
<
char
,
100
>
buffer
;
fmt
::
basic_memory_buffer
<
char
,
100
>
buffer
;
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
"4{}"
);
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
"4{}"
);
prepared
.
format_to
(
buffer
,
2
);
prepared
.
format_to
(
buffer
,
2
);
EXPECT_EQ
(
"42"
,
to_string
(
buffer
));
EXPECT_EQ
(
"42"
,
to_string
(
buffer
));
fmt
::
basic_memory_buffer
<
wchar_t
,
100
>
wbuffer
;
fmt
::
basic_memory_buffer
<
wchar_t
,
100
>
wbuffer
;
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
L"4{}"
);
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
L"4{}"
);
wprepared
.
format_to
(
wbuffer
,
2
);
wprepared
.
format_to
(
wbuffer
,
2
);
EXPECT_EQ
(
L"42"
,
to_string
(
wbuffer
));
EXPECT_EQ
(
L"42"
,
to_string
(
wbuffer
));
}
}
TEST
(
PrepareTest
,
FormatToMemoryBuffer
)
{
TEST
(
PrepareTest
,
FormatToMemoryBuffer
)
{
fmt
::
memory_buffer
buffer
;
fmt
::
memory_buffer
buffer
;
const
auto
prepared
=
fmt
::
prepar
e
<
int
>
(
"4{}"
);
const
auto
prepared
=
fmt
::
compil
e
<
int
>
(
"4{}"
);
prepared
.
format_to
(
buffer
,
2
);
prepared
.
format_to
(
buffer
,
2
);
EXPECT_EQ
(
"42"
,
to_string
(
buffer
));
EXPECT_EQ
(
"42"
,
to_string
(
buffer
));
fmt
::
wmemory_buffer
wbuffer
;
fmt
::
wmemory_buffer
wbuffer
;
const
auto
wprepared
=
fmt
::
prepar
e
<
int
>
(
L"4{}"
);
const
auto
wprepared
=
fmt
::
compil
e
<
int
>
(
L"4{}"
);
wprepared
.
format_to
(
wbuffer
,
2
);
wprepared
.
format_to
(
wbuffer
,
2
);
EXPECT_EQ
(
L"42"
,
to_string
(
wbuffer
));
EXPECT_EQ
(
L"42"
,
to_string
(
wbuffer
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment