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
c523dd58
Commit
c523dd58
authored
Nov 19, 2017
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use error handler to report errors
parent
5a32e64b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
28 deletions
+14
-28
include/fmt/format.h
include/fmt/format.h
+7
-15
include/fmt/printf.h
include/fmt/printf.h
+3
-12
test/format-test.cc
test/format-test.cc
+3
-0
test/printf-test.cc
test/printf-test.cc
+1
-1
No files found.
include/fmt/format.h
View file @
c523dd58
...
@@ -2018,18 +2018,18 @@ class context_base : public parse_context<Char>{
...
@@ -2018,18 +2018,18 @@ class context_base : public parse_context<Char>{
basic_args
<
Context
>
args
()
const
{
return
args_
;
}
basic_args
<
Context
>
args
()
const
{
return
args_
;
}
// Returns the argument with specified index.
// Returns the argument with specified index.
format_arg
do_get_arg
(
unsigned
arg_index
,
const
char
*&
error
)
{
format_arg
do_get_arg
(
unsigned
arg_index
)
{
format_arg
arg
=
args_
[
arg_index
];
format_arg
arg
=
args_
[
arg_index
];
if
(
!
arg
&&
!
error
)
if
(
!
arg
)
error
=
"argument index out of range"
;
this
->
on_error
(
"argument index out of range"
)
;
return
arg
;
return
arg
;
}
}
// Checks if manual indexing is used and returns the argument with
// Checks if manual indexing is used and returns the argument with
// specified index.
// specified index.
format_arg
get_arg
(
unsigned
arg_index
,
const
char
*&
error
)
{
format_arg
get_arg
(
unsigned
arg_index
)
{
return
this
->
check_no_auto_index
()
?
return
this
->
check_no_auto_index
()
?
this
->
do_get_arg
(
arg_index
,
error
)
:
format_arg
();
this
->
do_get_arg
(
arg_index
)
:
format_arg
();
}
}
public:
public:
...
@@ -2751,19 +2751,11 @@ class basic_context :
...
@@ -2751,19 +2751,11 @@ class basic_context :
:
Base
(
format_str
,
args
)
{}
:
Base
(
format_str
,
args
)
{}
format_arg
next_arg
()
{
format_arg
next_arg
()
{
const
char
*
error
=
0
;
return
this
->
do_get_arg
(
this
->
next_arg_index
());
format_arg
arg
=
this
->
do_get_arg
(
this
->
next_arg_index
(),
error
);
if
(
error
)
FMT_THROW
(
format_error
(
error
));
return
arg
;
}
}
format_arg
get_arg
(
unsigned
arg_index
)
{
format_arg
get_arg
(
unsigned
arg_index
)
{
const
char
*
error
=
0
;
return
this
->
do_get_arg
(
arg_index
);
format_arg
arg
=
this
->
do_get_arg
(
arg_index
,
error
);
if
(
error
)
FMT_THROW
(
format_error
(
error
));
return
arg
;
}
}
// Checks if manual indexing is used and returns the argument with
// Checks if manual indexing is used and returns the argument with
...
...
include/fmt/printf.h
View file @
c523dd58
...
@@ -367,18 +367,9 @@ template <typename Char, typename AF>
...
@@ -367,18 +367,9 @@ template <typename Char, typename AF>
typename
printf_context
<
Char
,
AF
>::
format_arg
printf_context
<
Char
,
AF
>::
get_arg
(
typename
printf_context
<
Char
,
AF
>::
format_arg
printf_context
<
Char
,
AF
>::
get_arg
(
iterator
it
,
unsigned
arg_index
)
{
iterator
it
,
unsigned
arg_index
)
{
(
void
)
it
;
(
void
)
it
;
const
char
*
error
=
0
;
if
(
arg_index
==
std
::
numeric_limits
<
unsigned
>::
max
())
format_arg
arg
;
return
this
->
do_get_arg
(
this
->
next_arg_index
());
if
(
arg_index
==
std
::
numeric_limits
<
unsigned
>::
max
())
{
return
Base
::
get_arg
(
arg_index
-
1
);
arg_index
=
this
->
next_arg_index
();
if
(
!
error
)
arg
=
this
->
do_get_arg
(
arg_index
,
error
);
}
else
{
arg
=
Base
::
get_arg
(
arg_index
-
1
,
error
);
}
if
(
error
)
FMT_THROW
(
format_error
(
!*
it
?
"invalid format string"
:
error
));
return
arg
;
}
}
template
<
typename
Char
,
typename
AF
>
template
<
typename
Char
,
typename
AF
>
...
...
test/format-test.cc
View file @
c523dd58
...
@@ -1906,4 +1906,7 @@ TEST(FormatTest, FormatStringErrors) {
...
@@ -1906,4 +1906,7 @@ TEST(FormatTest, FormatStringErrors) {
EXPECT_ERROR
(
"{1}{}"
,
EXPECT_ERROR
(
"{1}{}"
,
"cannot switch from manual to automatic argument indexing"
,
"cannot switch from manual to automatic argument indexing"
,
int
,
int
);
int
,
int
);
EXPECT_ERROR
(
"{}{1}"
,
"cannot switch from automatic to manual argument indexing"
,
int
,
int
);
}
}
test/printf-test.cc
View file @
c523dd58
...
@@ -116,7 +116,7 @@ TEST(PrintfTest, InvalidArgIndex) {
...
@@ -116,7 +116,7 @@ TEST(PrintfTest, InvalidArgIndex) {
format_error
,
"argument index out of range"
);
format_error
,
"argument index out of range"
);
EXPECT_THROW_MSG
(
fmt
::
sprintf
(
"%2$"
,
42
),
EXPECT_THROW_MSG
(
fmt
::
sprintf
(
"%2$"
,
42
),
format_error
,
"
invalid format string
"
);
format_error
,
"
argument index out of range
"
);
EXPECT_THROW_MSG
(
fmt
::
sprintf
(
format
(
"%{}$d"
,
BIG_NUM
),
42
),
EXPECT_THROW_MSG
(
fmt
::
sprintf
(
format
(
"%{}$d"
,
BIG_NUM
),
42
),
format_error
,
"number is too big"
);
format_error
,
"number is too big"
);
}
}
...
...
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