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
c1db2935
Commit
c1db2935
authored
Jul 24, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use Writer's buffer directly in formatters. Unfriend BasicFormatter.
parent
a7d94f0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
31 deletions
+35
-31
format.cc
format.cc
+19
-19
format.h
format.h
+16
-12
No files found.
format.cc
View file @
c1db2935
...
...
@@ -425,17 +425,17 @@ class fmt::internal::ArgFormatter :
:
formatter_
(
f
),
writer_
(
f
.
writer
()),
spec_
(
s
),
format_
(
fmt
)
{}
template
<
typename
T
>
void
visit_any_int
(
T
value
)
{
writer_
.
FormatI
nt
(
value
,
spec_
);
}
void
visit_any_int
(
T
value
)
{
writer_
.
write_i
nt
(
value
,
spec_
);
}
template
<
typename
T
>
void
visit_any_double
(
T
value
)
{
writer_
.
FormatD
ouble
(
value
,
spec_
);
}
void
visit_any_double
(
T
value
)
{
writer_
.
write_d
ouble
(
value
,
spec_
);
}
void
visit_char
(
int
value
)
{
if
(
spec_
.
type_
&&
spec_
.
type_
!=
'c'
)
{
switch
(
spec_
.
type_
)
{
// TODO: don't duplicate integer format specifiers here
case
'd'
:
case
'x'
:
case
'X'
:
case
'b'
:
case
'B'
:
case
'o'
:
writer_
.
FormatI
nt
(
value
,
spec_
);
writer_
.
write_i
nt
(
value
,
spec_
);
break
;
default:
internal
::
ReportUnknownType
(
spec_
.
type_
,
"char"
);
...
...
@@ -474,7 +474,7 @@ class fmt::internal::ArgFormatter :
fmt
::
internal
::
ReportUnknownType
(
spec_
.
type_
,
"pointer"
);
spec_
.
flags_
=
fmt
::
HASH_FLAG
;
spec_
.
type_
=
'x'
;
writer_
.
FormatI
nt
(
reinterpret_cast
<
uintptr_t
>
(
value
),
spec_
);
writer_
.
write_i
nt
(
reinterpret_cast
<
uintptr_t
>
(
value
),
spec_
);
}
void
visit_custom
(
Arg
::
CustomValue
c
)
{
...
...
@@ -507,7 +507,7 @@ typename fmt::BasicWriter<Char>::CharPtr
template
<
typename
Char
>
template
<
typename
T
>
void
fmt
::
BasicWriter
<
Char
>::
FormatD
ouble
(
T
value
,
const
FormatSpec
&
spec
)
{
void
fmt
::
BasicWriter
<
Char
>::
write_d
ouble
(
T
value
,
const
FormatSpec
&
spec
)
{
// Check type.
char
type
=
spec
.
type
();
bool
upper
=
false
;
...
...
@@ -818,11 +818,11 @@ void fmt::internal::PrintfFormatter<Char>::Format(
Char
c
=
*
s
++
;
if
(
c
!=
'%'
)
continue
;
if
(
*
s
==
c
)
{
write
r
.
buffer_
.
append
(
start
,
s
);
write
(
writer
,
start
,
s
);
start
=
++
s
;
continue
;
}
write
r
.
buffer_
.
append
(
start
,
s
-
1
);
write
(
writer
,
start
,
s
-
1
);
FormatSpec
spec
;
spec
.
align_
=
ALIGN_RIGHT
;
...
...
@@ -892,20 +892,20 @@ void fmt::internal::PrintfFormatter<Char>::Format(
// Format argument.
switch
(
arg
.
type
)
{
case
Arg
:
:
INT
:
writer
.
FormatI
nt
(
arg
.
int_value
,
spec
);
writer
.
write_i
nt
(
arg
.
int_value
,
spec
);
break
;
case
Arg
:
:
UINT
:
writer
.
FormatI
nt
(
arg
.
uint_value
,
spec
);
writer
.
write_i
nt
(
arg
.
uint_value
,
spec
);
break
;
case
Arg
:
:
LONG_LONG
:
writer
.
FormatI
nt
(
arg
.
long_long_value
,
spec
);
writer
.
write_i
nt
(
arg
.
long_long_value
,
spec
);
break
;
case
Arg
:
:
ULONG_LONG
:
writer
.
FormatI
nt
(
arg
.
ulong_long_value
,
spec
);
writer
.
write_i
nt
(
arg
.
ulong_long_value
,
spec
);
break
;
case
Arg
:
:
CHAR
:
{
if
(
spec
.
type_
&&
spec
.
type_
!=
'c'
)
writer
.
FormatI
nt
(
arg
.
int_value
,
spec
);
writer
.
write_i
nt
(
arg
.
int_value
,
spec
);
typedef
typename
BasicWriter
<
Char
>::
CharPtr
CharPtr
;
CharPtr
out
=
CharPtr
();
if
(
spec
.
width_
>
1
)
{
...
...
@@ -924,10 +924,10 @@ void fmt::internal::PrintfFormatter<Char>::Format(
break
;
}
case
Arg
:
:
DOUBLE
:
writer
.
FormatD
ouble
(
arg
.
double_value
,
spec
);
writer
.
write_d
ouble
(
arg
.
double_value
,
spec
);
break
;
case
Arg
:
:
LONG_DOUBLE
:
writer
.
FormatD
ouble
(
arg
.
long_double_value
,
spec
);
writer
.
write_d
ouble
(
arg
.
long_double_value
,
spec
);
break
;
case
Arg
:
:
STRING
:
writer
.
write_str
(
arg
.
string
,
spec
);
...
...
@@ -940,7 +940,7 @@ void fmt::internal::PrintfFormatter<Char>::Format(
internal
::
ReportUnknownType
(
spec
.
type_
,
"pointer"
);
spec
.
flags_
=
HASH_FLAG
;
spec
.
type_
=
'x'
;
writer
.
FormatI
nt
(
reinterpret_cast
<
uintptr_t
>
(
arg
.
pointer_value
),
spec
);
writer
.
write_i
nt
(
reinterpret_cast
<
uintptr_t
>
(
arg
.
pointer_value
),
spec
);
break
;
case
Arg
:
:
CUSTOM
:
if
(
spec
.
type_
)
...
...
@@ -952,7 +952,7 @@ void fmt::internal::PrintfFormatter<Char>::Format(
break
;
}
}
write
r
.
buffer_
.
append
(
start
,
s
);
write
(
writer
,
start
,
s
);
}
template
<
typename
Char
>
...
...
@@ -1111,18 +1111,18 @@ void fmt::BasicFormatter<Char>::Format(
Char
c
=
*
s
++
;
if
(
c
!=
'{'
&&
c
!=
'}'
)
continue
;
if
(
*
s
==
c
)
{
write
r_
.
buffer_
.
append
(
start_
,
s
);
write
(
writer_
,
start_
,
s
);
start_
=
++
s
;
continue
;
}
if
(
c
==
'}'
)
throw
FormatError
(
"unmatched '}' in format"
);
report_error_
.
num_open_braces
=
1
;
write
r_
.
buffer_
.
append
(
start_
,
s
-
1
);
write
(
writer_
,
start_
,
s
-
1
);
Arg
arg
=
ParseArgIndex
(
s
);
s
=
format
(
s
,
arg
);
}
write
r_
.
buffer_
.
append
(
start_
,
s
);
write
(
writer_
,
start_
,
s
);
}
void
fmt
::
ReportSystemError
(
...
...
format.h
View file @
c1db2935
...
...
@@ -853,6 +853,12 @@ protected:
const
Arg
&
handle_arg_index
(
unsigned
arg_index
);
template
<
typename
Char
>
void
write
(
BasicWriter
<
Char
>
&
w
,
const
Char
*
start
,
const
Char
*
end
)
{
if
(
start
!=
end
)
w
<<
BasicStringRef
<
Char
>
(
start
,
end
-
start
);
}
// TODO
};
...
...
@@ -1331,11 +1337,11 @@ class BasicWriter {
// Formats an integer.
template
<
typename
T
,
typename
Spec
>
void
FormatI
nt
(
T
value
,
const
Spec
&
spec
);
void
write_i
nt
(
T
value
,
const
Spec
&
spec
);
// Formats a floating-point number (double or long double).
template
<
typename
T
>
void
FormatD
ouble
(
T
value
,
const
FormatSpec
&
spec
);
void
write_d
ouble
(
T
value
,
const
FormatSpec
&
spec
);
// Writes a formatted string.
template
<
typename
StringChar
>
...
...
@@ -1353,7 +1359,6 @@ class BasicWriter {
void
operator
<<
(
typename
internal
::
CharTraits
<
Char
>::
UnsupportedStrType
);
friend
class
internal
::
ArgFormatter
<
Char
>
;
friend
class
BasicFormatter
<
Char
>
;
friend
class
internal
::
PrintfFormatter
<
Char
>
;
public:
...
...
@@ -1462,7 +1467,7 @@ class BasicWriter {
}
BasicWriter
&
operator
<<
(
double
value
)
{
FormatD
ouble
(
value
,
FormatSpec
());
write_d
ouble
(
value
,
FormatSpec
());
return
*
this
;
}
...
...
@@ -1471,7 +1476,7 @@ class BasicWriter {
(``'g'``) and writes it to the stream.
*/
BasicWriter
&
operator
<<
(
long
double
value
)
{
FormatD
ouble
(
value
,
FormatSpec
());
write_d
ouble
(
value
,
FormatSpec
());
return
*
this
;
}
...
...
@@ -1479,29 +1484,28 @@ class BasicWriter {
Writes a character to the stream.
*/
BasicWriter
&
operator
<<
(
char
value
)
{
*
GrowBuffer
(
1
)
=
value
;
buffer_
.
push_back
(
value
)
;
return
*
this
;
}
BasicWriter
&
operator
<<
(
wchar_t
value
)
{
*
GrowBuffer
(
1
)
=
internal
::
CharTraits
<
Char
>::
convert
(
value
);
buffer_
.
push_back
(
internal
::
CharTraits
<
Char
>::
convert
(
value
)
);
return
*
this
;
}
/**
Writes *value* to the stream.
*/
BasicWriter
&
operator
<<
(
const
fmt
::
BasicStringRef
<
Char
>
value
)
{
BasicWriter
&
operator
<<
(
fmt
::
BasicStringRef
<
Char
>
value
)
{
const
Char
*
str
=
value
.
c_str
();
std
::
size_t
size
=
value
.
size
();
std
::
copy
(
str
,
str
+
size
,
GrowBuffer
(
size
));
buffer_
.
append
(
str
,
str
+
value
.
size
());
return
*
this
;
}
template
<
typename
T
,
typename
Spec
,
typename
FillChar
>
BasicWriter
&
operator
<<
(
const
IntFormatSpec
<
T
,
Spec
,
FillChar
>
&
spec
)
{
internal
::
CharTraits
<
Char
>::
convert
(
FillChar
());
FormatI
nt
(
spec
.
value
(),
spec
);
write_i
nt
(
spec
.
value
(),
spec
);
return
*
this
;
}
...
...
@@ -1603,7 +1607,7 @@ typename fmt::BasicWriter<Char>::CharPtr
template
<
typename
Char
>
template
<
typename
T
,
typename
Spec
>
void
BasicWriter
<
Char
>::
FormatI
nt
(
T
value
,
const
Spec
&
spec
)
{
void
BasicWriter
<
Char
>::
write_i
nt
(
T
value
,
const
Spec
&
spec
)
{
unsigned
prefix_size
=
0
;
typedef
typename
internal
::
IntTraits
<
T
>::
MainType
UnsignedType
;
UnsignedType
abs_value
=
value
;
...
...
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