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
5debb2aa
Commit
5debb2aa
authored
Aug 29, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor error reporting to reduce duplication.
parent
605d2600
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
13 deletions
+14
-13
format.cc
format.cc
+12
-11
format.h
format.h
+2
-2
No files found.
format.cc
View file @
5debb2aa
...
...
@@ -175,13 +175,17 @@ int parse_nonnegative_int(const Char *&s) {
return
value
;
}
inline
void
require_numeric_argument
(
const
Arg
&
arg
,
char
spec
)
{
if
(
arg
.
type
>
Arg
::
LAST_NUMERIC_TYPE
)
{
throw
fmt
::
FormatError
(
fmt
::
format
(
"format specifier '{}' requires numeric argument"
,
spec
));
}
}
template
<
typename
Char
>
void
check_sign
(
const
Char
*&
s
,
const
Arg
&
arg
)
{
char
sign
=
static_cast
<
char
>
(
*
s
);
if
(
arg
.
type
>
Arg
::
LAST_NUMERIC_TYPE
)
{
throw
fmt
::
FormatError
(
fmt
::
format
(
"format specifier '{}' requires numeric argument"
,
sign
));
}
require_numeric_argument
(
arg
,
sign
);
if
(
arg
.
type
==
Arg
::
UINT
||
arg
.
type
==
Arg
::
ULONG_LONG
)
{
throw
fmt
::
FormatError
(
fmt
::
format
(
"format specifier '{}' requires signed argument"
,
sign
));
...
...
@@ -1059,8 +1063,8 @@ const Char *fmt::BasicFormatter<Char>::format(
s
+=
2
;
spec
.
fill_
=
c
;
}
else
++
s
;
if
(
spec
.
align_
==
ALIGN_NUMERIC
&&
arg
.
type
>
Arg
::
LAST_NUMERIC_TYPE
)
throw
FormatError
(
"format specifier '=' requires numeric argument"
);
if
(
spec
.
align_
==
ALIGN_NUMERIC
)
require_numeric_argument
(
arg
,
'='
);
break
;
}
}
while
(
--
p
>=
s
);
...
...
@@ -1083,9 +1087,7 @@ const Char *fmt::BasicFormatter<Char>::format(
}
if
(
*
s
==
'#'
)
{
if
(
arg
.
type
>
Arg
::
LAST_NUMERIC_TYPE
)
// TODO: make FormatError accept arguments
throw
FormatError
(
"format specifier '#' requires numeric argument"
);
require_numeric_argument
(
arg
,
'#'
);
spec
.
flags_
|=
HASH_FLAG
;
++
s
;
}
...
...
@@ -1093,8 +1095,7 @@ const Char *fmt::BasicFormatter<Char>::format(
// Parse width and zero flag.
if
(
'0'
<=
*
s
&&
*
s
<=
'9'
)
{
if
(
*
s
==
'0'
)
{
if
(
arg
.
type
>
Arg
::
LAST_NUMERIC_TYPE
)
throw
FormatError
(
"format specifier '0' requires numeric argument"
);
require_numeric_argument
(
arg
,
'0'
);
spec
.
align_
=
ALIGN_NUMERIC
;
spec
.
fill_
=
'0'
;
}
...
...
format.h
View file @
5debb2aa
...
...
@@ -215,8 +215,8 @@ typedef BasicStringRef<wchar_t> WStringRef;
*/
class
FormatError
:
public
std
::
runtime_error
{
public:
explicit
FormatError
(
const
std
::
string
&
message
)
:
std
::
runtime_error
(
message
)
{}
explicit
FormatError
(
StringRef
message
)
:
std
::
runtime_error
(
message
.
c_str
()
)
{}
};
namespace
internal
{
...
...
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