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
656a8378
Commit
656a8378
authored
Apr 22, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ArgInfo instead of Arg where possible.
parent
5b8126f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
16 deletions
+24
-16
format.cc
format.cc
+9
-9
format.h
format.h
+15
-7
No files found.
format.cc
View file @
656a8378
...
...
@@ -388,7 +388,7 @@ unsigned fmt::BasicFormatter<Char>::ParseUInt(const Char *&s) const {
}
template
<
typename
Char
>
inline
const
typename
fmt
::
BasicFormatter
<
Char
>::
Arg
inline
const
typename
fmt
::
BasicFormatter
<
Char
>::
Arg
Info
&
fmt
::
BasicFormatter
<
Char
>::
ParseArgIndex
(
const
Char
*&
s
)
{
unsigned
arg_index
=
0
;
if
(
*
s
<
'0'
||
*
s
>
'9'
)
{
...
...
@@ -409,11 +409,11 @@ inline const typename fmt::BasicFormatter<Char>::Arg
}
if
(
arg_index
>=
args_
.
size
())
ReportError
(
s
,
"argument index is out of range in format"
);
return
*
args_
[
arg_index
];
return
args_
[
arg_index
];
}
template
<
typename
Char
>
void
fmt
::
BasicFormatter
<
Char
>::
CheckSign
(
const
Char
*&
s
,
const
Arg
&
arg
)
{
void
fmt
::
BasicFormatter
<
Char
>::
CheckSign
(
const
Char
*&
s
,
const
Arg
Info
&
arg
)
{
char
sign
=
static_cast
<
char
>
(
*
s
);
if
(
arg
.
type
>
LAST_NUMERIC_TYPE
)
{
ReportError
(
s
,
...
...
@@ -446,7 +446,7 @@ void fmt::BasicFormatter<Char>::DoFormat() {
num_open_braces_
=
1
;
writer
.
buffer_
.
append
(
start
,
s
-
1
);
const
Arg
&
arg
=
ParseArgIndex
(
s
);
const
Arg
Info
&
arg
=
ParseArgIndex
(
s
);
FormatSpec
spec
;
int
precision
=
-
1
;
...
...
@@ -537,7 +537,7 @@ void fmt::BasicFormatter<Char>::DoFormat() {
}
else
if
(
*
s
==
'{'
)
{
++
s
;
++
num_open_braces_
;
const
Arg
&
precision_arg
=
ParseArgIndex
(
s
);
const
Arg
Info
&
precision_arg
=
ParseArgIndex
(
s
);
ULongLong
value
=
0
;
switch
(
precision_arg
.
type
)
{
case
INT
:
...
...
@@ -702,11 +702,11 @@ template void fmt::BasicFormatter<char>::ReportError(
template
unsigned
fmt
::
BasicFormatter
<
char
>
::
ParseUInt
(
const
char
*&
s
)
const
;
template
const
fmt
::
BasicFormatter
<
char
>
::
Arg
template
const
fmt
::
BasicFormatter
<
char
>
::
Arg
Info
&
fmt
::
BasicFormatter
<
char
>::
ParseArgIndex
(
const
char
*&
s
);
template
void
fmt
::
BasicFormatter
<
char
>
::
CheckSign
(
const
char
*&
s
,
const
Arg
&
arg
);
const
char
*&
s
,
const
Arg
Info
&
arg
);
template
void
fmt
::
BasicFormatter
<
char
>
::
DoFormat
();
...
...
@@ -732,11 +732,11 @@ template void fmt::BasicFormatter<wchar_t>::ReportError(
template
unsigned
fmt
::
BasicFormatter
<
wchar_t
>
::
ParseUInt
(
const
wchar_t
*&
s
)
const
;
template
const
fmt
::
BasicFormatter
<
wchar_t
>
::
Arg
template
const
fmt
::
BasicFormatter
<
wchar_t
>
::
Arg
Info
&
fmt
::
BasicFormatter
<
wchar_t
>::
ParseArgIndex
(
const
wchar_t
*&
s
);
template
void
fmt
::
BasicFormatter
<
wchar_t
>
::
CheckSign
(
const
wchar_t
*&
s
,
const
Arg
&
arg
);
const
wchar_t
*&
s
,
const
Arg
Info
&
arg
);
template
void
fmt
::
BasicFormatter
<
wchar_t
>
::
DoFormat
();
...
...
format.h
View file @
656a8378
...
...
@@ -1031,7 +1031,15 @@ class BasicFormatter {
};
// A wrapper around a format argument used to ensure that the formatting
// is performed before the argument is destroyed.
// is performed before the argument is destroyed. It is private so that
// its objects are only created by automatic conversions and not by users.
// Example:
//
// Format("{}") << std::string("test");
//
// Here an Arg object that wraps a temporary string is automatically
// created. It triggers formatting when destroyed which makes sure that
// the temporary string is still alive at the time of the formatting.
class
Arg
:
public
ArgInfo
{
private:
// This method is private to disallow formatting of arbitrary pointers.
...
...
@@ -1118,7 +1126,7 @@ class BasicFormatter {
// Format is called here to make sure that a referred object is
// still alive, for example:
//
// Print("{
0
}") << std::string("test");
// Print("{}") << std::string("test");
//
// Here an Arg object refers to a temporary std::string which is
// destroyed at the end of the statement. Since the string object is
...
...
@@ -1132,7 +1140,7 @@ class BasicFormatter {
};
enum
{
NUM_INLINE_ARGS
=
10
};
internal
::
Array
<
const
Arg
*
,
NUM_INLINE_ARGS
>
args_
;
// Format arguments.
internal
::
Array
<
ArgInfo
,
NUM_INLINE_ARGS
>
args_
;
// Format arguments.
const
Char
*
format_
;
// Format string.
int
num_open_braces_
;
...
...
@@ -1153,9 +1161,9 @@ class BasicFormatter {
unsigned
ParseUInt
(
const
Char
*&
s
)
const
;
// Parses argument index and returns an argument with this index.
const
Arg
&
ParseArgIndex
(
const
Char
*&
s
);
const
Arg
Info
&
ParseArgIndex
(
const
Char
*&
s
);
void
CheckSign
(
const
Char
*&
s
,
const
Arg
&
arg
);
void
CheckSign
(
const
Char
*&
s
,
const
Arg
Info
&
arg
);
// Parses the format string and performs the actual formatting,
// writing the output to writer_.
...
...
@@ -1194,7 +1202,7 @@ class BasicFormatter {
// TODO: don't copy arguments
args_
.
reserve
(
args
.
size
());
for
(
const
Arg
&
arg
:
args
)
args_
.
push_back
(
&
arg
);
args_
.
push_back
(
arg
);
}
#endif
...
...
@@ -1211,7 +1219,7 @@ class BasicFormatter {
// Feeds an argument to a formatter.
BasicFormatter
&
operator
<<
(
const
Arg
&
arg
)
{
arg
.
formatter
=
this
;
args_
.
push_back
(
&
arg
);
args_
.
push_back
(
arg
);
return
*
this
;
}
...
...
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