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
dbfd021a
Commit
dbfd021a
authored
Jan 22, 2013
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document the write API.
parent
abe75da8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
2 deletions
+52
-2
doc/index.rst
doc/index.rst
+11
-0
format.h
format.h
+38
-2
format_test.cc
format_test.cc
+3
-0
No files found.
doc/index.rst
View file @
dbfd021a
...
...
@@ -23,6 +23,17 @@ String Formatting API
.. doxygenfunction:: fmt::c_str
Write API
---------
.. doxygenfunction:: fmt::oct
.. doxygenfunction:: fmt::hex
.. doxygenfunction:: fmt::hexu
.. doxygenfunction:: fmt::pad
.. _formatstrings:
Format String Syntax
...
...
format.h
View file @
dbfd021a
...
...
@@ -36,7 +36,6 @@
#include <stdexcept>
#include <string>
#include <sstream>
#include <vector>
namespace
fmt
{
...
...
@@ -277,8 +276,40 @@ class IntFormatter : public SpecT {
T
value
()
const
{
return
value_
;
}
};
/**
Returns an integer formatter that formats the value in base 8.
*/
IntFormatter
<
int
,
TypeSpec
<
'o'
>
>
oct
(
int
value
);
/**
Returns an integer formatter that formats the value in base 16 using
lower-case letters for the digits above 9.
*/
IntFormatter
<
int
,
TypeSpec
<
'x'
>
>
hex
(
int
value
);
/**
Returns an integer formatter that formats the value in base 16 using
upper-case letters for the digits above 9.
*/
IntFormatter
<
int
,
TypeSpec
<
'X'
>
>
hexu
(
int
value
);
/**
\rst
Returns an integer formatter that pads the formatted argument with the fill
character to the specified width using the default (right) alignment.
**Example**::
std::string s = str(BasicFormatter() << pad(hex(0xcafe), 8, '0'));
// s == "0000cafe"
\endrst
*/
template
<
char
TYPE_CODE
>
IntFormatter
<
int
,
AlignTypeSpec
<
TYPE_CODE
>
>
pad
(
int
value
,
unsigned
width
,
char
fill
=
' '
);
#define DEFINE_INT_FORMATTERS(TYPE) \
/* Returns an integer formatter that formats value in the octal base. */
\
inline IntFormatter<TYPE, TypeSpec<'o'> > oct(TYPE value) { \
return IntFormatter<TYPE, TypeSpec<'o'> >(value, TypeSpec<'o'>()); \
} \
...
...
@@ -312,6 +343,8 @@ DEFINE_INT_FORMATTERS(unsigned long)
class
BasicFormatter
{
private:
// Returns the number of decimal digits in n. Trailing zeros are not counted
// except for n == 0 in which case CountDigits returns 1.
static
unsigned
CountDigits
(
uint64_t
n
)
{
unsigned
count
=
1
;
for
(;;)
{
...
...
@@ -671,6 +704,9 @@ class Formatter : public BasicFormatter {
internal
::
ArgInserter
operator
()(
StringRef
format
);
}
;
inline
std
::
string
str
(
const
BasicFormatter
&
f
)
{
return
f
.
str
();
}
inline
const
char
*
c_str
(
const
BasicFormatter
&
f
)
{
return
f
.
c_str
();
}
std
::
string
str
(
internal
::
FormatterProxy
p
);
const
char
*
c_str
(
internal
::
FormatterProxy
p
);
...
...
format_test.cc
View file @
dbfd021a
...
...
@@ -917,6 +917,9 @@ TEST(FormatterTest, FormatterAppend) {
}
TEST
(
FormatterTest
,
FormatterExamples
)
{
using
fmt
::
hex
;
EXPECT_EQ
(
"0000cafe"
,
str
(
BasicFormatter
()
<<
pad
(
hex
(
0xcafe
),
8
,
'0'
)));
std
::
string
message
=
str
(
Format
(
"The answer is {}"
)
<<
42
);
EXPECT_EQ
(
"The answer is 42"
,
message
);
...
...
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