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
9df0e2d1
Commit
9df0e2d1
authored
Jun 02, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement string parsing
parent
5b7bbf88
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
test/scan-test.cc
test/scan-test.cc
+20
-0
No files found.
test/scan-test.cc
View file @
9df0e2d1
...
@@ -21,6 +21,7 @@ struct scan_arg {
...
@@ -21,6 +21,7 @@ struct scan_arg {
unsigned
*
uint_value
;
unsigned
*
uint_value
;
long
long
*
long_long_value
;
long
long
*
long_long_value
;
unsigned
long
long
*
ulong_long_value
;
unsigned
long
long
*
ulong_long_value
;
std
::
string
*
string
;
// TODO: more types
// TODO: more types
};
};
...
@@ -31,6 +32,7 @@ struct scan_arg {
...
@@ -31,6 +32,7 @@ struct scan_arg {
:
arg_type
(
long_long_type
),
long_long_value
(
&
value
)
{}
:
arg_type
(
long_long_type
),
long_long_value
(
&
value
)
{}
scan_arg
(
unsigned
long
long
&
value
)
scan_arg
(
unsigned
long
long
&
value
)
:
arg_type
(
ulong_long_type
),
ulong_long_value
(
&
value
)
{}
:
arg_type
(
ulong_long_type
),
ulong_long_value
(
&
value
)
{}
scan_arg
(
std
::
string
&
value
)
:
arg_type
(
string_type
),
string
(
&
value
)
{}
};
};
}
// namespace internal
}
// namespace internal
...
@@ -112,6 +114,11 @@ struct scan_handler : error_handler {
...
@@ -112,6 +114,11 @@ struct scan_handler : error_handler {
case
ulong_long_type
:
case
ulong_long_type
:
*
arg_
.
ulong_long_value
=
read_uint
<
unsigned
long
long
>
();
*
arg_
.
ulong_long_value
=
read_uint
<
unsigned
long
long
>
();
break
;
break
;
case
string_type
:
{
while
(
begin_
!=
end_
&&
*
begin_
!=
' '
)
arg_
.
string
->
push_back
(
*
begin_
++
);
break
;
}
default:
default:
assert
(
false
);
assert
(
false
);
}
}
...
@@ -178,6 +185,11 @@ TEST(ScanTest, ReadULongLong) {
...
@@ -178,6 +185,11 @@ TEST(ScanTest, ReadULongLong) {
EXPECT_THROW_MSG
(
fmt
::
scan
(
"-42"
,
"{}"
,
n
),
fmt
::
format_error
,
EXPECT_THROW_MSG
(
fmt
::
scan
(
"-42"
,
"{}"
,
n
),
fmt
::
format_error
,
"invalid input"
);
"invalid input"
);
}
}
TEST
(
ScanTest
,
ReadString
)
{
std
::
string
s
;
fmt
::
scan
(
"foo"
,
"{}"
,
s
);
EXPECT_EQ
(
s
,
"foo"
);
}
TEST
(
ScanTest
,
InvalidFormat
)
{
TEST
(
ScanTest
,
InvalidFormat
)
{
EXPECT_THROW_MSG
(
fmt
::
scan
(
""
,
"{}"
),
fmt
::
format_error
,
EXPECT_THROW_MSG
(
fmt
::
scan
(
""
,
"{}"
),
fmt
::
format_error
,
...
@@ -185,3 +197,11 @@ TEST(ScanTest, InvalidFormat) {
...
@@ -185,3 +197,11 @@ TEST(ScanTest, InvalidFormat) {
EXPECT_THROW_MSG
(
fmt
::
scan
(
""
,
"{"
),
fmt
::
format_error
,
EXPECT_THROW_MSG
(
fmt
::
scan
(
""
,
"{"
),
fmt
::
format_error
,
"invalid format string"
);
"invalid format string"
);
}
}
TEST
(
ScanTest
,
Example
)
{
std
::
string
key
;
int
value
;
fmt
::
scan
(
"answer = 42"
,
"{} = {}"
,
key
,
value
);
EXPECT_EQ
(
key
,
"answer"
);
EXPECT_EQ
(
value
,
42
);
}
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