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
f219dcd5
Commit
f219dcd5
authored
Dec 24, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fmt::bytes
parent
dea7fde8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
4 deletions
+27
-4
include/fmt/core.h
include/fmt/core.h
+5
-4
include/fmt/format.h
include/fmt/format.h
+16
-0
test/format-test.cc
test/format-test.cc
+6
-0
No files found.
include/fmt/core.h
View file @
f219dcd5
...
@@ -1513,8 +1513,8 @@ FMT_API void vprint_mojibake(std::FILE*, string_view, format_args);
...
@@ -1513,8 +1513,8 @@ FMT_API void vprint_mojibake(std::FILE*, string_view, format_args);
/**
/**
\rst
\rst
Prints formatted data to the file *f*.
For wide format strings *f* should
be
Prints formatted data to the file *f*.
Strings are assumed to
be
in wide-oriented mode set via ``fwide(f, 1)``
.
Unicode-encoded unless the ``FMT_UNICODE`` macro is set to 0
.
**Example**::
**Example**::
...
@@ -1535,8 +1535,9 @@ inline void print(std::FILE* f, const S& format_str, Args&&... args) {
...
@@ -1535,8 +1535,9 @@ inline void print(std::FILE* f, const S& format_str, Args&&... args) {
/**
/**
\rst
\rst
Formats ``args`` according to specifications in ``format_str`` and writes the
Formats ``args`` according to specifications in ``format_str`` and writes
output to ``stdout``.
the output to ``stdout``. Strings are assumed to be Unicode-encoded unless
the ``FMT_UNICODE`` macro is set to 0.
**Example**::
**Example**::
...
...
include/fmt/format.h
View file @
f219dcd5
...
@@ -3112,6 +3112,22 @@ template <typename T> inline const void* ptr(const std::shared_ptr<T>& p) {
...
@@ -3112,6 +3112,22 @@ template <typename T> inline const void* ptr(const std::shared_ptr<T>& p) {
return
p
.
get
();
return
p
.
get
();
}
}
class
bytes
{
private:
string_view
data_
;
friend
struct
formatter
<
bytes
>
;
public:
explicit
bytes
(
string_view
data
)
:
data_
(
data
)
{}
};
template
<
>
struct
formatter
<
bytes
>
:
formatter
<
string_view
>
{
template
<
typename
FormatContext
>
auto
format
(
bytes
b
,
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
return
formatter
<
string_view
>::
format
(
b
.
data_
,
ctx
);
}
};
template
<
typename
It
,
typename
Char
>
struct
arg_join
:
internal
::
view
{
template
<
typename
It
,
typename
Char
>
struct
arg_join
:
internal
::
view
{
It
begin
;
It
begin
;
It
end
;
It
end
;
...
...
test/format-test.cc
View file @
f219dcd5
...
@@ -1766,6 +1766,12 @@ TEST(FormatTest, Dynamic) {
...
@@ -1766,6 +1766,12 @@ TEST(FormatTest, Dynamic) {
EXPECT_EQ
(
"42 and abc1 and 1.5"
,
result
);
EXPECT_EQ
(
"42 and abc1 and 1.5"
,
result
);
}
}
TEST
(
FormatTest
,
Bytes
)
{
auto
s
=
fmt
::
format
(
"{:10}"
,
fmt
::
bytes
(
"ёжик"
));
EXPECT_EQ
(
"ёжик "
,
s
);
EXPECT_EQ
(
10
,
s
.
size
());
}
TEST
(
FormatTest
,
JoinArg
)
{
TEST
(
FormatTest
,
JoinArg
)
{
using
fmt
::
join
;
using
fmt
::
join
;
int
v1
[
3
]
=
{
1
,
2
,
3
};
int
v1
[
3
]
=
{
1
,
2
,
3
};
...
...
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