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
4d049cf5
Commit
4d049cf5
authored
Jul 28, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More fixes for
https://github.com/cppformat/cppformat/issues/50
.
parent
75b5eb4b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
79 deletions
+75
-79
format.cc
format.cc
+30
-30
format.h
format.h
+34
-35
posix.cc
posix.cc
+2
-2
test/util-test.cc
test/util-test.cc
+9
-12
No files found.
format.cc
View file @
4d049cf5
...
...
@@ -443,17 +443,17 @@ class fmt::internal::ArgFormatter :
CharPtr
out
=
CharPtr
();
if
(
spec_
.
width_
>
1
)
{
Char
fill
=
static_cast
<
Char
>
(
spec_
.
fill
());
out
=
writer_
.
GrowB
uffer
(
spec_
.
width_
);
out
=
writer_
.
grow_b
uffer
(
spec_
.
width_
);
if
(
spec_
.
align_
==
fmt
::
ALIGN_RIGHT
)
{
std
::
fill_n
(
out
,
spec_
.
width_
-
1
,
fill
);
out
+=
spec_
.
width_
-
1
;
}
else
if
(
spec_
.
align_
==
fmt
::
ALIGN_CENTER
)
{
out
=
writer_
.
FillP
adding
(
out
,
spec_
.
width_
,
1
,
fill
);
out
=
writer_
.
fill_p
adding
(
out
,
spec_
.
width_
,
1
,
fill
);
}
else
{
std
::
fill_n
(
out
+
1
,
spec_
.
width_
-
1
,
fill
);
}
}
else
{
out
=
writer_
.
GrowB
uffer
(
1
);
out
=
writer_
.
grow_b
uffer
(
1
);
}
*
out
=
static_cast
<
Char
>
(
value
);
}
...
...
@@ -489,7 +489,7 @@ void fmt::internal::FormatErrorReporter<Char>::operator()(
// content area.
template
<
typename
Char
>
typename
fmt
::
BasicWriter
<
Char
>::
CharPtr
fmt
::
BasicWriter
<
Char
>::
FillP
adding
(
CharPtr
buffer
,
fmt
::
BasicWriter
<
Char
>::
fill_p
adding
(
CharPtr
buffer
,
unsigned
total_size
,
std
::
size_t
content_size
,
wchar_t
fill
)
{
std
::
size_t
padding
=
total_size
-
content_size
;
std
::
size_t
left_padding
=
padding
/
2
;
...
...
@@ -631,9 +631,9 @@ void fmt::BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
if
(
spec
.
align
()
==
ALIGN_CENTER
&&
spec
.
width
()
>
static_cast
<
unsigned
>
(
n
))
{
unsigned
width
=
spec
.
width
();
CharPtr
p
=
GrowB
uffer
(
width
);
CharPtr
p
=
grow_b
uffer
(
width
);
std
::
copy
(
p
,
p
+
n
,
p
+
(
width
-
n
)
/
2
);
FillP
adding
(
p
,
spec
.
width
(),
n
,
fill
);
fill_p
adding
(
p
,
spec
.
width
(),
n
,
fill
);
return
;
}
if
(
spec
.
fill
()
!=
' '
||
sign
)
{
...
...
@@ -642,7 +642,7 @@ void fmt::BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
if
(
sign
)
*
(
start
-
1
)
=
sign
;
}
GrowB
uffer
(
n
);
grow_b
uffer
(
n
);
return
;
}
// If n is negative we ask to increase the capacity by at least 1,
...
...
@@ -672,7 +672,7 @@ void fmt::BasicWriter<Char>::write_str(
template
<
typename
Char
>
inline
const
Arg
&
fmt
::
BasicFormatter
<
Char
>::
ParseArgI
ndex
(
const
Char
*&
s
)
{
&
fmt
::
BasicFormatter
<
Char
>::
parse_arg_i
ndex
(
const
Char
*&
s
)
{
unsigned
arg_index
=
0
;
if
(
*
s
<
'0'
||
*
s
>
'9'
)
{
if
(
*
s
!=
'}'
&&
*
s
!=
':'
)
...
...
@@ -696,7 +696,7 @@ inline const Arg
}
template
<
typename
Char
>
void
fmt
::
BasicFormatter
<
Char
>::
CheckS
ign
(
void
fmt
::
BasicFormatter
<
Char
>::
check_s
ign
(
const
Char
*&
s
,
const
Arg
&
arg
)
{
char
sign
=
static_cast
<
char
>
(
*
s
);
if
(
arg
.
type
>
Arg
::
LAST_NUMERIC_TYPE
)
{
...
...
@@ -742,7 +742,7 @@ const Arg &fmt::internal::FormatterBase::handle_arg_index(unsigned arg_index) {
}
template
<
typename
Char
>
void
fmt
::
internal
::
PrintfFormatter
<
Char
>::
ParseF
lags
(
void
fmt
::
internal
::
PrintfFormatter
<
Char
>::
parse_f
lags
(
FormatSpec
&
spec
,
const
Char
*&
s
)
{
for
(;;)
{
switch
(
*
s
++
)
{
...
...
@@ -769,7 +769,7 @@ void fmt::internal::PrintfFormatter<Char>::ParseFlags(
}
template
<
typename
Char
>
unsigned
fmt
::
internal
::
PrintfFormatter
<
Char
>::
ParseH
eader
(
unsigned
fmt
::
internal
::
PrintfFormatter
<
Char
>::
parse_h
eader
(
const
Char
*&
s
,
FormatSpec
&
spec
)
{
unsigned
arg_index
=
UINT_MAX
;
Char
c
=
*
s
;
...
...
@@ -791,7 +791,7 @@ unsigned fmt::internal::PrintfFormatter<Char>::ParseHeader(
}
}
}
ParseF
lags
(
spec
,
s
);
parse_f
lags
(
spec
,
s
);
// Parse width.
if
(
*
s
>=
'0'
&&
*
s
<=
'9'
)
{
spec
.
width_
=
ParseNonnegativeInt
(
s
,
error_
);
...
...
@@ -803,7 +803,7 @@ unsigned fmt::internal::PrintfFormatter<Char>::ParseHeader(
}
template
<
typename
Char
>
void
fmt
::
internal
::
PrintfFormatter
<
Char
>::
F
ormat
(
void
fmt
::
internal
::
PrintfFormatter
<
Char
>::
f
ormat
(
BasicWriter
<
Char
>
&
writer
,
BasicStringRef
<
Char
>
format
,
const
ArgList
&
args
)
{
const
Char
*
start
=
format
.
c_str
();
...
...
@@ -835,7 +835,7 @@ void fmt::internal::PrintfFormatter<Char>::Format(
// is OK for both cases.
// Parse argument index, flags and width.
unsigned
arg_index
=
ParseH
eader
(
s
,
spec
);
unsigned
arg_index
=
parse_h
eader
(
s
,
spec
);
// Parse precision.
if
(
*
s
==
'.'
)
{
...
...
@@ -906,7 +906,7 @@ void fmt::internal::PrintfFormatter<Char>::Format(
CharPtr
out
=
CharPtr
();
if
(
spec
.
width_
>
1
)
{
Char
fill
=
' '
;
out
=
writer
.
GrowB
uffer
(
spec
.
width_
);
out
=
writer
.
grow_b
uffer
(
spec
.
width_
);
if
(
spec
.
align_
!=
ALIGN_LEFT
)
{
std
::
fill_n
(
out
,
spec
.
width_
-
1
,
fill
);
out
+=
spec
.
width_
-
1
;
...
...
@@ -914,7 +914,7 @@ void fmt::internal::PrintfFormatter<Char>::Format(
std
::
fill_n
(
out
+
1
,
spec
.
width_
-
1
,
fill
);
}
}
else
{
out
=
writer
.
GrowB
uffer
(
1
);
out
=
writer
.
grow_b
uffer
(
1
);
}
*
out
=
static_cast
<
Char
>
(
arg
.
int_value
);
break
;
...
...
@@ -1000,15 +1000,15 @@ const Char *fmt::BasicFormatter<Char>::format(
// Parse sign.
switch
(
*
s
)
{
case
'+'
:
CheckS
ign
(
s
,
arg
);
check_s
ign
(
s
,
arg
);
spec
.
flags_
|=
SIGN_FLAG
|
PLUS_FLAG
;
break
;
case
'-'
:
CheckS
ign
(
s
,
arg
);
check_s
ign
(
s
,
arg
);
spec
.
flags_
|=
MINUS_FLAG
;
break
;
case
' '
:
CheckS
ign
(
s
,
arg
);
check_s
ign
(
s
,
arg
);
spec
.
flags_
|=
SIGN_FLAG
;
break
;
}
...
...
@@ -1046,7 +1046,7 @@ const Char *fmt::BasicFormatter<Char>::format(
}
else
if
(
*
s
==
'{'
)
{
++
s
;
++
report_error_
.
num_open_braces
;
const
Arg
&
precision_arg
=
ParseArgI
ndex
(
s
);
const
Arg
&
precision_arg
=
parse_arg_i
ndex
(
s
);
ULongLong
value
=
0
;
switch
(
precision_arg
.
type
)
{
case
Arg
:
:
INT
:
...
...
@@ -1098,7 +1098,7 @@ const Char *fmt::BasicFormatter<Char>::format(
}
template
<
typename
Char
>
void
fmt
::
BasicFormatter
<
Char
>::
F
ormat
(
void
fmt
::
BasicFormatter
<
Char
>::
f
ormat
(
BasicStringRef
<
Char
>
format_str
,
const
ArgList
&
args
)
{
const
Char
*
s
=
start_
=
format_str
.
c_str
();
args_
=
args
;
...
...
@@ -1115,20 +1115,20 @@ void fmt::BasicFormatter<Char>::Format(
throw
FormatError
(
"unmatched '}' in format"
);
report_error_
.
num_open_braces
=
1
;
write
(
writer_
,
start_
,
s
-
1
);
Arg
arg
=
ParseArgI
ndex
(
s
);
Arg
arg
=
parse_arg_i
ndex
(
s
);
s
=
format
(
s
,
arg
);
}
write
(
writer_
,
start_
,
s
);
}
void
fmt
::
ReportSystemE
rror
(
void
fmt
::
report_system_e
rror
(
int
error_code
,
fmt
::
StringRef
message
)
FMT_NOEXCEPT
(
true
)
{
// FIXME: format_system_error may throw
ReportError
(
internal
::
format_system_error
,
error_code
,
message
);
}
#ifdef _WIN32
void
fmt
::
ReportWinE
rror
(
void
fmt
::
report_windows_e
rror
(
int
error_code
,
fmt
::
StringRef
message
)
FMT_NOEXCEPT
(
true
)
{
// FIXME: format_windows_error may throw
ReportError
(
internal
::
format_windows_error
,
error_code
,
message
);
...
...
@@ -1170,25 +1170,25 @@ void fmt::printf(StringRef format, const ArgList &args) {
// Explicit instantiations for char.
template
fmt
::
BasicWriter
<
char
>
::
CharPtr
fmt
::
BasicWriter
<
char
>::
FillP
adding
(
CharPtr
buffer
,
fmt
::
BasicWriter
<
char
>::
fill_p
adding
(
CharPtr
buffer
,
unsigned
total_size
,
std
::
size_t
content_size
,
wchar_t
fill
);
template
void
fmt
::
BasicFormatter
<
char
>
::
F
ormat
(
template
void
fmt
::
BasicFormatter
<
char
>
::
f
ormat
(
BasicStringRef
<
char
>
format
,
const
ArgList
&
args
);
template
void
fmt
::
internal
::
PrintfFormatter
<
char
>
::
F
ormat
(
template
void
fmt
::
internal
::
PrintfFormatter
<
char
>
::
f
ormat
(
BasicWriter
<
char
>
&
writer
,
BasicStringRef
<
char
>
format
,
const
ArgList
&
args
);
// Explicit instantiations for wchar_t.
template
fmt
::
BasicWriter
<
wchar_t
>
::
CharPtr
fmt
::
BasicWriter
<
wchar_t
>::
FillP
adding
(
CharPtr
buffer
,
fmt
::
BasicWriter
<
wchar_t
>::
fill_p
adding
(
CharPtr
buffer
,
unsigned
total_size
,
std
::
size_t
content_size
,
wchar_t
fill
);
template
void
fmt
::
BasicFormatter
<
wchar_t
>
::
F
ormat
(
template
void
fmt
::
BasicFormatter
<
wchar_t
>
::
f
ormat
(
BasicStringRef
<
wchar_t
>
format
,
const
ArgList
&
args
);
template
void
fmt
::
internal
::
PrintfFormatter
<
wchar_t
>
::
F
ormat
(
template
void
fmt
::
internal
::
PrintfFormatter
<
wchar_t
>
::
f
ormat
(
BasicWriter
<
wchar_t
>
&
writer
,
BasicStringRef
<
wchar_t
>
format
,
const
ArgList
&
args
);
...
...
format.h
View file @
4d049cf5
...
...
@@ -867,14 +867,14 @@ protected:
template
<
typename
Char
>
class
PrintfFormatter
:
private
FormatterBase
{
private:
void
ParseF
lags
(
FormatSpec
&
spec
,
const
Char
*&
s
);
void
parse_f
lags
(
FormatSpec
&
spec
,
const
Char
*&
s
);
// Parses argument index, flags and width and returns the parsed
// argument index.
unsigned
ParseH
eader
(
const
Char
*&
s
,
FormatSpec
&
spec
);
unsigned
parse_h
eader
(
const
Char
*&
s
,
FormatSpec
&
spec
);
public:
void
F
ormat
(
BasicWriter
<
Char
>
&
writer
,
void
f
ormat
(
BasicWriter
<
Char
>
&
writer
,
BasicStringRef
<
Char
>
format
,
const
ArgList
&
args
);
};
}
// namespace internal
...
...
@@ -888,16 +888,16 @@ private:
internal
::
FormatErrorReporter
<
Char
>
report_error_
;
// Parses argument index and returns an argument with this index.
const
internal
::
Arg
&
ParseArgI
ndex
(
const
Char
*&
s
);
const
internal
::
Arg
&
parse_arg_i
ndex
(
const
Char
*&
s
);
void
CheckS
ign
(
const
Char
*&
s
,
const
internal
::
Arg
&
arg
);
void
check_s
ign
(
const
Char
*&
s
,
const
internal
::
Arg
&
arg
);
public:
explicit
BasicFormatter
(
BasicWriter
<
Char
>
&
w
)
:
writer_
(
w
)
{}
BasicWriter
<
Char
>
&
writer
()
{
return
writer_
;
}
void
F
ormat
(
BasicStringRef
<
Char
>
format_str
,
const
ArgList
&
args
);
void
f
ormat
(
BasicStringRef
<
Char
>
format_str
,
const
ArgList
&
args
);
const
Char
*
format
(
const
Char
*
format_str
,
const
internal
::
Arg
&
arg
);
};
...
...
@@ -1299,33 +1299,34 @@ class BasicWriter {
typedef
typename
internal
::
CharTraits
<
Char
>::
CharPtr
CharPtr
;
#if _SECURE_SCL
static
Char
*
GetBase
(
CharPtr
p
)
{
return
p
.
base
();
}
// Returns pointer value.
static
Char
*
get
(
CharPtr
p
)
{
return
p
.
base
();
}
#else
static
Char
*
GetBase
(
Char
*
p
)
{
return
p
;
}
static
Char
*
get
(
Char
*
p
)
{
return
p
;
}
#endif
static
CharPtr
FillP
adding
(
CharPtr
buffer
,
static
CharPtr
fill_p
adding
(
CharPtr
buffer
,
unsigned
total_size
,
std
::
size_t
content_size
,
wchar_t
fill
);
// Grows the buffer by n characters and returns a pointer to the newly
// allocated area.
CharPtr
GrowB
uffer
(
std
::
size_t
n
)
{
CharPtr
grow_b
uffer
(
std
::
size_t
n
)
{
std
::
size_t
size
=
buffer_
.
size
();
buffer_
.
resize
(
size
+
n
);
return
internal
::
make_ptr
(
&
buffer_
[
size
],
n
);
}
// Prepare a buffer for integer formatting.
CharPtr
PrepareBufferForInt
(
unsigned
num_digits
,
CharPtr
prepare_int_buffer
(
unsigned
num_digits
,
const
EmptySpec
&
,
const
char
*
prefix
,
unsigned
prefix_size
)
{
unsigned
size
=
prefix_size
+
num_digits
;
CharPtr
p
=
GrowB
uffer
(
size
);
CharPtr
p
=
grow_b
uffer
(
size
);
std
::
copy
(
prefix
,
prefix
+
prefix_size
,
p
);
return
p
+
size
-
1
;
}
template
<
typename
Spec
>
CharPtr
PrepareBufferForInt
(
unsigned
num_digits
,
CharPtr
prepare_int_buffer
(
unsigned
num_digits
,
const
Spec
&
spec
,
const
char
*
prefix
,
unsigned
prefix_size
);
// Formats an integer.
...
...
@@ -1432,7 +1433,7 @@ class BasicWriter {
\endrst
*/
void
write
(
BasicStringRef
<
Char
>
format
,
const
ArgList
&
args
)
{
BasicFormatter
<
Char
>
(
*
this
).
F
ormat
(
format
,
args
);
BasicFormatter
<
Char
>
(
*
this
).
f
ormat
(
format
,
args
);
}
FMT_VARIADIC_VOID
(
write
,
fmt
::
BasicStringRef
<
Char
>
)
...
...
@@ -1519,18 +1520,18 @@ typename BasicWriter<Char>::CharPtr BasicWriter<Char>::write_str(
const
StrChar
*
s
,
std
::
size_t
size
,
const
AlignSpec
&
spec
)
{
CharPtr
out
=
CharPtr
();
if
(
spec
.
width
()
>
size
)
{
out
=
GrowB
uffer
(
spec
.
width
());
out
=
grow_b
uffer
(
spec
.
width
());
Char
fill
=
static_cast
<
Char
>
(
spec
.
fill
());
if
(
spec
.
align
()
==
ALIGN_RIGHT
)
{
std
::
fill_n
(
out
,
spec
.
width
()
-
size
,
fill
);
out
+=
spec
.
width
()
-
size
;
}
else
if
(
spec
.
align
()
==
ALIGN_CENTER
)
{
out
=
FillP
adding
(
out
,
spec
.
width
(),
size
,
fill
);
out
=
fill_p
adding
(
out
,
spec
.
width
(),
size
,
fill
);
}
else
{
std
::
fill_n
(
out
+
size
,
spec
.
width
()
-
size
,
fill
);
}
}
else
{
out
=
GrowB
uffer
(
size
);
out
=
grow_b
uffer
(
size
);
}
std
::
copy
(
s
,
s
+
size
,
out
);
return
out
;
...
...
@@ -1539,7 +1540,7 @@ typename BasicWriter<Char>::CharPtr BasicWriter<Char>::write_str(
template
<
typename
Char
>
template
<
typename
Spec
>
typename
fmt
::
BasicWriter
<
Char
>::
CharPtr
fmt
::
BasicWriter
<
Char
>::
PrepareBufferForInt
(
fmt
::
BasicWriter
<
Char
>::
prepare_int_buffer
(
unsigned
num_digits
,
const
Spec
&
spec
,
const
char
*
prefix
,
unsigned
prefix_size
)
{
unsigned
width
=
spec
.
width
();
...
...
@@ -1553,35 +1554,35 @@ typename fmt::BasicWriter<Char>::CharPtr
unsigned
number_size
=
prefix_size
+
spec
.
precision
();
AlignSpec
subspec
(
number_size
,
'0'
,
ALIGN_NUMERIC
);
if
(
number_size
>=
width
)
return
PrepareBufferForInt
(
num_digits
,
subspec
,
prefix
,
prefix_size
);
return
prepare_int_buffer
(
num_digits
,
subspec
,
prefix
,
prefix_size
);
buffer_
.
reserve
(
width
);
unsigned
fill_size
=
width
-
number_size
;
if
(
align
!=
ALIGN_LEFT
)
{
CharPtr
p
=
GrowB
uffer
(
fill_size
);
CharPtr
p
=
grow_b
uffer
(
fill_size
);
std
::
fill
(
p
,
p
+
fill_size
,
fill
);
}
CharPtr
result
=
PrepareBufferForInt
(
CharPtr
result
=
prepare_int_buffer
(
num_digits
,
subspec
,
prefix
,
prefix_size
);
if
(
align
==
ALIGN_LEFT
)
{
CharPtr
p
=
GrowB
uffer
(
fill_size
);
CharPtr
p
=
grow_b
uffer
(
fill_size
);
std
::
fill
(
p
,
p
+
fill_size
,
fill
);
}
return
result
;
}
unsigned
size
=
prefix_size
+
num_digits
;
if
(
width
<=
size
)
{
CharPtr
p
=
GrowB
uffer
(
size
);
CharPtr
p
=
grow_b
uffer
(
size
);
std
::
copy
(
prefix
,
prefix
+
prefix_size
,
p
);
return
p
+
size
-
1
;
}
CharPtr
p
=
GrowB
uffer
(
width
);
CharPtr
p
=
grow_b
uffer
(
width
);
CharPtr
end
=
p
+
width
;
if
(
align
==
ALIGN_LEFT
)
{
std
::
copy
(
prefix
,
prefix
+
prefix_size
,
p
);
p
+=
size
;
std
::
fill
(
p
,
end
,
fill
);
}
else
if
(
align
==
ALIGN_CENTER
)
{
p
=
FillP
adding
(
p
,
width
,
size
,
fill
);
p
=
fill_p
adding
(
p
,
width
,
size
,
fill
);
std
::
copy
(
prefix
,
prefix
+
prefix_size
,
p
);
p
+=
size
;
}
else
{
...
...
@@ -1617,9 +1618,9 @@ void BasicWriter<Char>::write_int(T value, const Spec &spec) {
switch
(
spec
.
type
())
{
case
0
:
case
'd'
:
{
unsigned
num_digits
=
internal
::
count_digits
(
abs_value
);
CharPtr
p
=
PrepareBufferForInt
(
CharPtr
p
=
prepare_int_buffer
(
num_digits
,
spec
,
prefix
,
prefix_size
)
+
1
-
num_digits
;
internal
::
format_decimal
(
GetBase
(
p
),
abs_value
,
num_digits
);
internal
::
format_decimal
(
get
(
p
),
abs_value
,
num_digits
);
break
;
}
case
'x'
:
case
'X'
:
{
...
...
@@ -1632,7 +1633,7 @@ void BasicWriter<Char>::write_int(T value, const Spec &spec) {
do
{
++
num_digits
;
}
while
((
n
>>=
4
)
!=
0
);
Char
*
p
=
GetBase
(
PrepareBufferForInt
(
Char
*
p
=
get
(
prepare_int_buffer
(
num_digits
,
spec
,
prefix
,
prefix_size
));
n
=
abs_value
;
const
char
*
digits
=
spec
.
type
()
==
'x'
?
...
...
@@ -1652,8 +1653,7 @@ void BasicWriter<Char>::write_int(T value, const Spec &spec) {
do
{
++
num_digits
;
}
while
((
n
>>=
1
)
!=
0
);
Char
*
p
=
GetBase
(
PrepareBufferForInt
(
num_digits
,
spec
,
prefix
,
prefix_size
));
Char
*
p
=
get
(
prepare_int_buffer
(
num_digits
,
spec
,
prefix
,
prefix_size
));
n
=
abs_value
;
do
{
*
p
--
=
'0'
+
(
n
&
1
);
...
...
@@ -1668,8 +1668,7 @@ void BasicWriter<Char>::write_int(T value, const Spec &spec) {
do
{
++
num_digits
;
}
while
((
n
>>=
3
)
!=
0
);
Char
*
p
=
GetBase
(
PrepareBufferForInt
(
num_digits
,
spec
,
prefix
,
prefix_size
));
Char
*
p
=
get
(
prepare_int_buffer
(
num_digits
,
spec
,
prefix
,
prefix_size
));
n
=
abs_value
;
do
{
*
p
--
=
'0'
+
(
n
&
7
);
...
...
@@ -1693,7 +1692,7 @@ void format(BasicFormatter<Char> &f, const Char *format_str, const T &value) {
// Reports a system error without throwing an exception.
// Can be used to report errors from destructors.
void
ReportSystemE
rror
(
int
error_code
,
StringRef
message
)
FMT_NOEXCEPT
(
true
);
void
report_system_e
rror
(
int
error_code
,
StringRef
message
)
FMT_NOEXCEPT
(
true
);
#ifdef _WIN32
...
...
@@ -1722,7 +1721,7 @@ class WindowsError : public SystemError {
// Reports a Windows error without throwing an exception.
// Can be used to report errors from destructors.
void
ReportWinE
rror
(
int
error_code
,
StringRef
message
)
FMT_NOEXCEPT
(
true
);
void
report_windows_e
rror
(
int
error_code
,
StringRef
message
)
FMT_NOEXCEPT
(
true
);
#endif
...
...
@@ -1803,7 +1802,7 @@ void print(std::ostream &os, StringRef format, const ArgList &args);
template
<
typename
Char
>
void
printf
(
BasicWriter
<
Char
>
&
w
,
BasicStringRef
<
Char
>
format
,
const
ArgList
&
args
)
{
internal
::
PrintfFormatter
<
Char
>
().
F
ormat
(
w
,
format
,
args
);
internal
::
PrintfFormatter
<
Char
>
().
f
ormat
(
w
,
format
,
args
);
}
inline
std
::
string
sprintf
(
StringRef
format
,
const
ArgList
&
args
)
{
...
...
posix.cc
View file @
4d049cf5
...
...
@@ -67,7 +67,7 @@ inline std::size_t convert_rwcount(std::size_t count) { return count; }
fmt
::
BufferedFile
::~
BufferedFile
()
FMT_NOEXCEPT
(
true
)
{
if
(
file_
&&
FMT_SYSTEM
(
fclose
(
file_
))
!=
0
)
fmt
::
ReportSystemE
rror
(
errno
,
"cannot close file"
);
fmt
::
report_system_e
rror
(
errno
,
"cannot close file"
);
}
void
fmt
::
BufferedFile
::
close
()
{
...
...
@@ -102,7 +102,7 @@ fmt::File::~File() FMT_NOEXCEPT(true) {
// Don't retry close in case of EINTR!
// See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
if
(
fd_
!=
-
1
&&
FMT_POSIX_CALL
(
close
(
fd_
))
!=
0
)
fmt
::
ReportSystemE
rror
(
errno
,
"cannot close file"
);
fmt
::
report_system_e
rror
(
errno
,
"cannot close file"
);
}
void
fmt
::
File
::
close
()
{
...
...
test/util-test.cc
View file @
4d049cf5
...
...
@@ -448,12 +448,6 @@ TEST(UtilTest, StrError) {
#endif
}
TEST
(
UtilTest
,
SystemError
)
{
fmt
::
SystemError
e
(
EDOM
,
"test"
);
EXPECT_EQ
(
fmt
::
format
(
"test: {}"
,
GetSystemErrorMessage
(
EDOM
)),
e
.
what
());
EXPECT_EQ
(
EDOM
,
e
.
error_code
());
}
typedef
void
(
*
FormatErrorMessage
)(
fmt
::
Writer
&
out
,
int
error_code
,
StringRef
message
);
...
...
@@ -478,7 +472,10 @@ TEST(UtilTest, FormatSystemError) {
GetSystemErrorMessage
(
EDOM
)),
message
.
str
());
}
TEST
(
UtilTest
,
ThrowSystemError
)
{
TEST
(
UtilTest
,
SystemError
)
{
fmt
::
SystemError
e
(
EDOM
,
"test"
);
EXPECT_EQ
(
fmt
::
format
(
"test: {}"
,
GetSystemErrorMessage
(
EDOM
)),
e
.
what
());
EXPECT_EQ
(
EDOM
,
e
.
error_code
());
CheckThrowError
<
fmt
::
SystemError
>
(
EDOM
,
fmt
::
internal
::
format_system_error
);
}
...
...
@@ -486,12 +483,12 @@ TEST(UtilTest, ReportSystemError) {
fmt
::
Writer
out
;
fmt
::
internal
::
format_system_error
(
out
,
EDOM
,
"test error"
);
out
<<
'\n'
;
EXPECT_WRITE
(
stderr
,
fmt
::
ReportSystemE
rror
(
EDOM
,
"test error"
),
out
.
str
());
EXPECT_WRITE
(
stderr
,
fmt
::
report_system_e
rror
(
EDOM
,
"test error"
),
out
.
str
());
}
#ifdef _WIN32
TEST
(
UtilTest
,
FormatWin
ErrorMessage
)
{
TEST
(
UtilTest
,
FormatWin
dowsError
)
{
LPWSTR
message
=
0
;
FormatMessageW
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
0
,
...
...
@@ -506,17 +503,17 @@ TEST(UtilTest, FormatWinErrorMessage) {
actual_message
.
str
());
}
TEST
(
UtilTest
,
ThrowWin
Error
)
{
TEST
(
UtilTest
,
Windows
Error
)
{
CheckThrowError
<
fmt
::
WindowsError
>
(
ERROR_FILE_EXISTS
,
fmt
::
internal
::
format_windows_error
);
}
TEST
(
UtilTest
,
ReportWinError
)
{
TEST
(
UtilTest
,
ReportWin
dows
Error
)
{
fmt
::
Writer
out
;
fmt
::
internal
::
format_windows_error
(
out
,
ERROR_FILE_EXISTS
,
"test error"
);
out
<<
'\n'
;
EXPECT_WRITE
(
stderr
,
fmt
::
ReportWinE
rror
(
ERROR_FILE_EXISTS
,
"test error"
),
out
.
str
());
fmt
::
report_windows_e
rror
(
ERROR_FILE_EXISTS
,
"test error"
),
out
.
str
());
}
#endif // _WIN32
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