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
f1dfd59a
Commit
f1dfd59a
authored
Jul 16, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HandleArgIndex -> handle_arg_index. Use error_ instead of a local.
parent
f86c812e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
33 deletions
+27
-33
format.cc
format.cc
+25
-31
format.h
format.h
+2
-2
No files found.
format.cc
View file @
f1dfd59a
...
@@ -681,10 +681,9 @@ inline const Arg
...
@@ -681,10 +681,9 @@ inline const Arg
"cannot switch from automatic to manual argument indexing"
);
"cannot switch from automatic to manual argument indexing"
);
}
}
next_arg_index_
=
-
1
;
next_arg_index_
=
-
1
;
const
char
*
error
=
0
;
arg_index
=
ParseNonnegativeInt
(
s
,
error_
);
arg_index
=
ParseNonnegativeInt
(
s
,
error
);
if
(
error_
)
if
(
error
)
report_error_
(
s
,
error_
);
// TODO: don't use report_error_
report_error_
(
s
,
error
);
// TODO
if
(
arg_index
>=
args_
.
size
())
if
(
arg_index
>=
args_
.
size
())
report_error_
(
s
,
"argument index is out of range in format"
);
report_error_
(
s
,
"argument index is out of range in format"
);
return
args_
[
arg_index
];
return
args_
[
arg_index
];
...
@@ -719,25 +718,21 @@ const Arg &fmt::internal::FormatterBase::next_arg() {
...
@@ -719,25 +718,21 @@ const Arg &fmt::internal::FormatterBase::next_arg() {
return
DUMMY_ARG
;
return
DUMMY_ARG
;
}
}
const
Arg
&
fmt
::
internal
::
FormatterBase
::
HandleArgIndex
(
const
Arg
&
fmt
::
internal
::
FormatterBase
::
handle_arg_index
(
unsigned
arg_index
)
{
unsigned
arg_index
,
const
char
*&
error
)
{
if
(
arg_index
!=
UINT_MAX
)
{
if
(
arg_index
!=
UINT_MAX
)
{
if
(
next_arg_index_
<=
0
)
{
if
(
next_arg_index_
<=
0
)
{
next_arg_index_
=
-
1
;
next_arg_index_
=
-
1
;
--
arg_index
;
--
arg_index
;
}
else
if
(
!
error
)
{
}
else
if
(
!
error
_
)
{
error
=
"cannot switch from automatic to manual argument indexing"
;
error
_
=
"cannot switch from automatic to manual argument indexing"
;
}
}
}
else
if
(
next_arg_index_
>=
0
)
{
if
(
arg_index
<
args_
.
size
())
arg_index
=
next_arg_index_
++
;
return
args_
[
arg_index
];
}
else
if
(
!
error
)
{
if
(
!
error_
)
error
=
"cannot switch from manual to automatic argument indexing"
;
error_
=
"argument index is out of range in format"
;
return
DUMMY_ARG
;
}
}
if
(
arg_index
<
args_
.
size
())
return
next_arg
();
return
args_
[
arg_index
];
if
(
!
error
)
error
=
"argument index is out of range in format"
;
return
DUMMY_ARG
;
}
}
template
<
typename
Char
>
template
<
typename
Char
>
...
@@ -769,13 +764,13 @@ void fmt::internal::PrintfFormatter<Char>::ParseFlags(
...
@@ -769,13 +764,13 @@ void fmt::internal::PrintfFormatter<Char>::ParseFlags(
template
<
typename
Char
>
template
<
typename
Char
>
unsigned
fmt
::
internal
::
PrintfFormatter
<
Char
>::
ParseHeader
(
unsigned
fmt
::
internal
::
PrintfFormatter
<
Char
>::
ParseHeader
(
const
Char
*&
s
,
FormatSpec
&
spec
,
const
char
*&
error
)
{
const
Char
*&
s
,
FormatSpec
&
spec
)
{
unsigned
arg_index
=
UINT_MAX
;
unsigned
arg_index
=
UINT_MAX
;
Char
c
=
*
s
;
Char
c
=
*
s
;
if
(
c
>=
'0'
&&
c
<=
'9'
)
{
if
(
c
>=
'0'
&&
c
<=
'9'
)
{
// Parse an argument index (if followed by '$') or a width possibly
// Parse an argument index (if followed by '$') or a width possibly
// preceded with '0' flag(s).
// preceded with '0' flag(s).
unsigned
value
=
ParseNonnegativeInt
(
s
,
error
);
unsigned
value
=
ParseNonnegativeInt
(
s
,
error
_
);
if
(
*
s
==
'$'
)
{
// value is an argument index
if
(
*
s
==
'$'
)
{
// value is an argument index
++
s
;
++
s
;
arg_index
=
value
;
arg_index
=
value
;
...
@@ -793,10 +788,10 @@ unsigned fmt::internal::PrintfFormatter<Char>::ParseHeader(
...
@@ -793,10 +788,10 @@ unsigned fmt::internal::PrintfFormatter<Char>::ParseHeader(
ParseFlags
(
spec
,
s
);
ParseFlags
(
spec
,
s
);
// Parse width.
// Parse width.
if
(
*
s
>=
'0'
&&
*
s
<=
'9'
)
{
if
(
*
s
>=
'0'
&&
*
s
<=
'9'
)
{
spec
.
width_
=
ParseNonnegativeInt
(
s
,
error
);
spec
.
width_
=
ParseNonnegativeInt
(
s
,
error
_
);
}
else
if
(
*
s
==
'*'
)
{
}
else
if
(
*
s
==
'*'
)
{
++
s
;
++
s
;
spec
.
width_
=
WidthHandler
(
spec
).
visit
(
HandleArgIndex
(
UINT_MAX
,
error
));
spec
.
width_
=
WidthHandler
(
spec
).
visit
(
handle_arg_index
(
UINT_MAX
));
}
}
return
arg_index
;
return
arg_index
;
}
}
...
@@ -826,33 +821,32 @@ void fmt::internal::PrintfFormatter<Char>::Format(
...
@@ -826,33 +821,32 @@ void fmt::internal::PrintfFormatter<Char>::Format(
// completely parsed. This is done to avoid potentially confusing
// completely parsed. This is done to avoid potentially confusing
// error messages for incomplete format strings. For example, in
// error messages for incomplete format strings. For example, in
// sprintf("%2$", 42);
// sprintf("%2$", 42);
// the format specification is incomplete. In naive approach we
// the format specification is incomplete. In
a
naive approach we
// would parse 2 as an argument index and report an error that the
// would parse 2 as an argument index and report an error that the
// index is out of range which would be rather confusing if the
// index is out of range which would be rather confusing if the
// use meant "%2d$" rather than "%2$d". If we delay an error, the
// use meant "%2d$" rather than "%2$d". If we delay an error, the
// user will get an error that the format string is invalid which
// user will get an error that the format string is invalid which
// is OK for both cases.
// is OK for both cases.
const
char
*
error
=
0
;
// Parse argument index, flags and width.
// Parse argument index, flags and width.
unsigned
arg_index
=
ParseHeader
(
s
,
spec
,
error
);
unsigned
arg_index
=
ParseHeader
(
s
,
spec
);
// Parse precision.
// Parse precision.
if
(
*
s
==
'.'
)
{
if
(
*
s
==
'.'
)
{
++
s
;
++
s
;
if
(
'0'
<=
*
s
&&
*
s
<=
'9'
)
{
if
(
'0'
<=
*
s
&&
*
s
<=
'9'
)
{
spec
.
precision_
=
ParseNonnegativeInt
(
s
,
error
);
spec
.
precision_
=
ParseNonnegativeInt
(
s
,
error
_
);
}
else
if
(
*
s
==
'*'
)
{
}
else
if
(
*
s
==
'*'
)
{
++
s
;
++
s
;
const
Arg
&
arg
=
HandleArgIndex
(
UINT_MAX
,
error
);
const
Arg
&
arg
=
handle_arg_index
(
UINT_MAX
);
if
(
arg
.
type
<=
Arg
::
LAST_INTEGER_TYPE
)
if
(
arg
.
type
<=
Arg
::
LAST_INTEGER_TYPE
)
spec
.
precision_
=
static_cast
<
int
>
(
GetIntValue
(
arg
));
// TODO: check for overflow
spec
.
precision_
=
static_cast
<
int
>
(
GetIntValue
(
arg
));
// TODO: check for overflow
else
if
(
!
error
)
else
if
(
!
error
_
)
error
=
"precision is not integer"
;
error
_
=
"precision is not integer"
;
}
}
}
}
const
Arg
&
arg
=
HandleArgIndex
(
arg_index
,
error
);
const
Arg
&
arg
=
handle_arg_index
(
arg_index
);
if
(
spec
.
hash_flag
()
&&
GetIntValue
(
arg
)
==
0
)
if
(
spec
.
hash_flag
()
&&
GetIntValue
(
arg
)
==
0
)
spec
.
flags_
&=
~
HASH_FLAG
;
spec
.
flags_
&=
~
HASH_FLAG
;
if
(
spec
.
fill_
==
'0'
)
{
if
(
spec
.
fill_
==
'0'
)
{
...
@@ -879,8 +873,8 @@ void fmt::internal::PrintfFormatter<Char>::Format(
...
@@ -879,8 +873,8 @@ void fmt::internal::PrintfFormatter<Char>::Format(
// Parse type.
// Parse type.
if
(
!*
s
)
if
(
!*
s
)
throw
FormatError
(
"invalid format string"
);
throw
FormatError
(
"invalid format string"
);
if
(
error
)
if
(
error
_
)
throw
FormatError
(
error
);
throw
FormatError
(
error
_
);
spec
.
type_
=
static_cast
<
char
>
(
*
s
++
);
spec
.
type_
=
static_cast
<
char
>
(
*
s
++
);
start
=
s
;
start
=
s
;
...
...
format.h
View file @
f1dfd59a
...
@@ -851,7 +851,7 @@ protected:
...
@@ -851,7 +851,7 @@ protected:
const
Arg
&
next_arg
();
const
Arg
&
next_arg
();
const
Arg
&
HandleArgIndex
(
unsigned
arg_index
,
const
char
*&
error
);
const
Arg
&
handle_arg_index
(
unsigned
arg_index
);
// TODO
// TODO
};
};
...
@@ -864,7 +864,7 @@ class PrintfFormatter : private FormatterBase {
...
@@ -864,7 +864,7 @@ class PrintfFormatter : private FormatterBase {
// Parses argument index, flags and width and returns the parsed
// Parses argument index, flags and width and returns the parsed
// argument index.
// argument index.
unsigned
ParseHeader
(
const
Char
*&
s
,
FormatSpec
&
spec
,
const
char
*&
error
);
unsigned
ParseHeader
(
const
Char
*&
s
,
FormatSpec
&
spec
);
public:
public:
void
Format
(
BasicWriter
<
Char
>
&
writer
,
void
Format
(
BasicWriter
<
Char
>
&
writer
,
...
...
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