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
af2c7377
Commit
af2c7377
authored
Jun 02, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement parsing of string_views
parent
9df0e2d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
12 deletions
+40
-12
test/scan-test.cc
test/scan-test.cc
+40
-12
No files found.
test/scan-test.cc
View file @
af2c7377
...
...
@@ -14,25 +14,40 @@
FMT_BEGIN_NAMESPACE
namespace
internal
{
enum
class
scan_type
{
none_type
,
int_type
,
uint_type
,
long_long_type
,
ulong_long_type
,
string_type
,
string_view_type
};
struct
scan_arg
{
type
arg_type
;
scan_
type
arg_type
;
union
{
int
*
int_value
;
unsigned
*
uint_value
;
long
long
*
long_long_value
;
unsigned
long
long
*
ulong_long_value
;
std
::
string
*
string
;
fmt
::
string_view
*
string_view
;
// TODO: more types
};
scan_arg
()
:
arg_type
(
none_type
)
{}
scan_arg
(
int
&
value
)
:
arg_type
(
int_type
),
int_value
(
&
value
)
{}
scan_arg
(
unsigned
&
value
)
:
arg_type
(
uint_type
),
uint_value
(
&
value
)
{}
scan_arg
()
:
arg_type
(
scan_type
::
none_type
)
{}
scan_arg
(
int
&
value
)
:
arg_type
(
scan_type
::
int_type
),
int_value
(
&
value
)
{}
scan_arg
(
unsigned
&
value
)
:
arg_type
(
scan_type
::
uint_type
),
uint_value
(
&
value
)
{}
scan_arg
(
long
long
&
value
)
:
arg_type
(
long_long_type
),
long_long_value
(
&
value
)
{}
:
arg_type
(
scan_type
::
long_long_type
),
long_long_value
(
&
value
)
{}
scan_arg
(
unsigned
long
long
&
value
)
:
arg_type
(
ulong_long_type
),
ulong_long_value
(
&
value
)
{}
scan_arg
(
std
::
string
&
value
)
:
arg_type
(
string_type
),
string
(
&
value
)
{}
:
arg_type
(
scan_type
::
ulong_long_type
),
ulong_long_value
(
&
value
)
{}
scan_arg
(
std
::
string
&
value
)
:
arg_type
(
scan_type
::
string_type
),
string
(
&
value
)
{}
scan_arg
(
fmt
::
string_view
&
value
)
:
arg_type
(
scan_type
::
string_view_type
),
string_view
(
&
value
)
{}
};
}
// namespace internal
...
...
@@ -102,22 +117,28 @@ struct scan_handler : error_handler {
void
on_replacement_field
(
const
char
*
)
{
switch
(
arg_
.
arg_type
)
{
case
int_type
:
case
scan_type
:
:
int_type
:
*
arg_
.
int_value
=
read_int
();
break
;
case
uint_type
:
case
scan_type
:
:
uint_type
:
*
arg_
.
uint_value
=
read_uint
();
break
;
case
long_long_type
:
case
scan_type
:
:
long_long_type
:
*
arg_
.
long_long_value
=
read_int
<
long
long
>
();
break
;
case
ulong_long_type
:
case
scan_type
:
:
ulong_long_type
:
*
arg_
.
ulong_long_value
=
read_uint
<
unsigned
long
long
>
();
break
;
case
s
tring_type
:
{
case
s
can_type
:
:
string_type
:
while
(
begin_
!=
end_
&&
*
begin_
!=
' '
)
arg_
.
string
->
push_back
(
*
begin_
++
);
break
;
case
scan_type
:
:
string_view_type
:
{
auto
s
=
begin_
;
while
(
begin_
!=
end_
&&
*
begin_
!=
' '
)
++
begin_
;
*
arg_
.
string_view
=
fmt
::
string_view
(
s
,
begin_
-
s
);
break
;
}
default:
assert
(
false
);
...
...
@@ -185,12 +206,19 @@ TEST(ScanTest, ReadULongLong) {
EXPECT_THROW_MSG
(
fmt
::
scan
(
"-42"
,
"{}"
,
n
),
fmt
::
format_error
,
"invalid input"
);
}
TEST
(
ScanTest
,
ReadString
)
{
std
::
string
s
;
fmt
::
scan
(
"foo"
,
"{}"
,
s
);
EXPECT_EQ
(
s
,
"foo"
);
}
TEST
(
ScanTest
,
ReadStringView
)
{
fmt
::
string_view
s
;
fmt
::
scan
(
"foo"
,
"{}"
,
s
);
EXPECT_EQ
(
s
,
"foo"
);
}
TEST
(
ScanTest
,
InvalidFormat
)
{
EXPECT_THROW_MSG
(
fmt
::
scan
(
""
,
"{}"
),
fmt
::
format_error
,
"argument index out of range"
);
...
...
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