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
f184ad0a
Commit
f184ad0a
authored
Nov 16, 2013
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore the 'B' type by
https://github.com/gcflymoto
and add tests.
parent
4f3ae78a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
10 deletions
+13
-10
format.h
format.h
+2
-2
format_test.cc
format_test.cc
+11
-8
No files found.
format.h
View file @
f184ad0a
...
...
@@ -729,7 +729,7 @@ BasicWriter<Char> &BasicWriter<Char>::operator<<(
}
break
;
}
case
'b'
:
{
case
'b'
:
case
'B'
:
{
UnsignedType
n
=
abs_value
;
bool
print_prefix
=
f
.
hash_flag
();
if
(
print_prefix
)
size
+=
2
;
...
...
@@ -742,7 +742,7 @@ BasicWriter<Char> &BasicWriter<Char>::operator<<(
*
p
--
=
'0'
+
(
n
&
1
);
}
while
((
n
>>=
1
)
!=
0
);
if
(
print_prefix
)
{
*
p
--
=
'b'
;
*
p
--
=
f
.
type
()
;
*
p
=
'0'
;
}
break
;
...
...
format_test.cc
View file @
f184ad0a
...
...
@@ -316,6 +316,14 @@ TEST(WriterTest, WriteWideString) {
//fmt::WWriter() << "abc";
}
TEST
(
WriterTest
,
bin
)
{
using
fmt
::
bin
;
EXPECT_EQ
(
"1100101011111110"
,
str
(
Writer
()
<<
bin
(
0xcafe
)));
EXPECT_EQ
(
"1011101010111110"
,
str
(
Writer
()
<<
bin
(
0xbabeu
)));
EXPECT_EQ
(
"1101111010101101"
,
str
(
Writer
()
<<
bin
(
0xdeadl
)));
EXPECT_EQ
(
"1011111011101111"
,
str
(
Writer
()
<<
bin
(
0xbeeful
)));
}
TEST
(
WriterTest
,
oct
)
{
using
fmt
::
oct
;
EXPECT_EQ
(
"12"
,
str
(
Writer
()
<<
oct
(
static_cast
<
short
>
(
012
))));
...
...
@@ -325,14 +333,6 @@ TEST(WriterTest, oct) {
EXPECT_EQ
(
"70"
,
str
(
Writer
()
<<
oct
(
070ul
)));
}
TEST
(
WriterTest
,
bin
)
{
using
fmt
::
bin
;
EXPECT_EQ
(
"1100101011111110"
,
str
(
Writer
()
<<
bin
(
0xcafe
)));
EXPECT_EQ
(
"1011101010111110"
,
str
(
Writer
()
<<
bin
(
0xbabeu
)));
EXPECT_EQ
(
"1101111010101101"
,
str
(
Writer
()
<<
bin
(
0xdeadl
)));
EXPECT_EQ
(
"1011111011101111"
,
str
(
Writer
()
<<
bin
(
0xbeeful
)));
}
TEST
(
WriterTest
,
hex
)
{
using
fmt
::
hex
;
fmt
::
IntFormatter
<
int
,
fmt
::
TypeSpec
<
'x'
>
>
(
*
phex
)(
int
value
)
=
hex
;
...
...
@@ -685,6 +685,9 @@ TEST(FormatterTest, SpaceSign) {
TEST
(
FormatterTest
,
HashFlag
)
{
EXPECT_EQ
(
"42"
,
str
(
Format
(
"{0:#}"
)
<<
42
));
EXPECT_EQ
(
"-42"
,
str
(
Format
(
"{0:#}"
)
<<
-
42
));
EXPECT_EQ
(
"0b101010"
,
str
(
Format
(
"{0:#b}"
)
<<
0x42
));
EXPECT_EQ
(
"0B101010"
,
str
(
Format
(
"{0:#B}"
)
<<
0x42
));
EXPECT_EQ
(
"-0b101010"
,
str
(
Format
(
"{0:#b}"
)
<<
-
0x42
));
EXPECT_EQ
(
"0x42"
,
str
(
Format
(
"{0:#x}"
)
<<
0x42
));
EXPECT_EQ
(
"0X42"
,
str
(
Format
(
"{0:#X}"
)
<<
0x42
));
EXPECT_EQ
(
"-0x42"
,
str
(
Format
(
"{0:#x}"
)
<<
-
0x42
));
...
...
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