Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
a887399c
Commit
a887399c
authored
Feb 01, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support unquoted strings in read_string
parent
3283051e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
8 deletions
+16
-8
libcaf_core/caf/detail/parser/read_string.hpp
libcaf_core/caf/detail/parser/read_string.hpp
+7
-3
libcaf_core/test/read_string.cpp
libcaf_core/test/read_string.cpp
+9
-5
No files found.
libcaf_core/caf/detail/parser/read_string.hpp
View file @
a887399c
...
@@ -23,7 +23,6 @@
...
@@ -23,7 +23,6 @@
#include "caf/config.hpp"
#include "caf/config.hpp"
#include "caf/detail/parser/chars.hpp"
#include "caf/detail/parser/chars.hpp"
#include "caf/detail/parser/is_char.hpp"
#include "caf/detail/parser/state.hpp"
#include "caf/detail/parser/state.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/pec.hpp"
#include "caf/pec.hpp"
...
@@ -36,8 +35,8 @@ namespace caf {
...
@@ -36,8 +35,8 @@ namespace caf {
namespace
detail
{
namespace
detail
{
namespace
parser
{
namespace
parser
{
/// Reads a
number, i.e., on success produces either an `int64_t` or a
/// Reads a
quoted or unquoted string. Quoted strings allow escaping, while
///
`double`
.
///
unquoted strings may only include alphanumeric characters
.
template
<
class
Iterator
,
class
Sentinel
,
class
Consumer
>
template
<
class
Iterator
,
class
Sentinel
,
class
Consumer
>
void
read_string
(
state
<
Iterator
,
Sentinel
>&
ps
,
Consumer
&
consumer
)
{
void
read_string
(
state
<
Iterator
,
Sentinel
>&
ps
,
Consumer
&
consumer
)
{
std
::
string
res
;
std
::
string
res
;
...
@@ -49,6 +48,7 @@ void read_string(state<Iterator, Sentinel>& ps, Consumer& consumer) {
...
@@ -49,6 +48,7 @@ void read_string(state<Iterator, Sentinel>& ps, Consumer& consumer) {
state
(
init
)
{
state
(
init
)
{
transition
(
init
,
"
\t
"
)
transition
(
init
,
"
\t
"
)
transition
(
read_chars
,
'"'
)
transition
(
read_chars
,
'"'
)
transition
(
read_unquoted_chars
,
alphanumeric_chars
,
res
+=
ch
)
}
}
state
(
read_chars
)
{
state
(
read_chars
)
{
transition
(
escape
,
'\\'
)
transition
(
escape
,
'\\'
)
...
@@ -64,6 +64,10 @@ void read_string(state<Iterator, Sentinel>& ps, Consumer& consumer) {
...
@@ -64,6 +64,10 @@ void read_string(state<Iterator, Sentinel>& ps, Consumer& consumer) {
transition
(
read_chars
,
'"'
,
res
+=
'"'
)
transition
(
read_chars
,
'"'
,
res
+=
'"'
)
error_transition
(
pec
::
illegal_escape_sequence
)
error_transition
(
pec
::
illegal_escape_sequence
)
}
}
term_state
(
read_unquoted_chars
)
{
transition
(
read_unquoted_chars
,
alphanumeric_chars
,
res
+=
ch
)
epsilon
(
done
)
}
term_state
(
done
)
{
term_state
(
done
)
{
transition
(
done
,
"
\t
"
)
transition
(
done
,
"
\t
"
)
}
}
...
...
libcaf_core/test/read_string.cpp
View file @
a887399c
...
@@ -77,25 +77,29 @@ CAF_TEST(empty string) {
...
@@ -77,25 +77,29 @@ CAF_TEST(empty string) {
CAF_CHECK_EQUAL
(
p
(
"
\t
\"\"
\t\t\t
"
),
""
_s
);
CAF_CHECK_EQUAL
(
p
(
"
\t
\"\"
\t\t\t
"
),
""
_s
);
}
}
CAF_TEST
(
non
-
empty
string
)
{
CAF_TEST
(
non
-
empty
quoted
string
)
{
CAF_CHECK_EQUAL
(
p
(
R"("abc")"
),
"abc"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("abc")"
),
"abc"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("a b c")"
),
"a b c"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("a b c")"
),
"a b c"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"( "abcdefABCDEF" )"
),
"abcdefABCDEF"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"( "abcdefABCDEF" )"
),
"abcdefABCDEF"
_s
);
}
}
CAF_TEST
(
string
with
escaped
characters
)
{
CAF_TEST
(
quoted
string
with
escaped
characters
)
{
CAF_CHECK_EQUAL
(
p
(
R"("a\tb\tc")"
),
"a
\t
b
\t
c"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("a\tb\tc")"
),
"a
\t
b
\t
c"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("a\nb\r\nc")"
),
"a
\n
b
\r\n
c"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("a\nb\r\nc")"
),
"a
\n
b
\r\n
c"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("a\\b")"
),
"a
\\
b"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"("a\\b")"
),
"a
\\
b"
_s
);
//CAF_CHECK_EQUAL(p(R"("foo = \"bar\"")"), "foo = \"bar\""_s);
}
CAF_TEST
(
unquoted
strings
)
{
CAF_CHECK_EQUAL
(
p
(
R"(foo)"
),
"foo"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"( foo )"
),
"foo"
_s
);
CAF_CHECK_EQUAL
(
p
(
R"( 123 )"
),
"123"
_s
);
}
}
CAF_TEST
(
invalid
strings
)
{
CAF_TEST
(
invalid
strings
)
{
CAF_CHECK_EQUAL
(
p
(
R"("abc)"
),
pec
::
unexpected_eof
);
CAF_CHECK_EQUAL
(
p
(
R"("abc)"
),
pec
::
unexpected_eof
);
CAF_CHECK_EQUAL
(
p
(
"
\"
ab
\n
c
\"
"
),
pec
::
unexpected_newline
);
CAF_CHECK_EQUAL
(
p
(
"
\"
ab
\n
c
\"
"
),
pec
::
unexpected_newline
);
CAF_CHECK_EQUAL
(
p
(
R"("foo \i bar")"
),
pec
::
illegal_escape_sequence
);
CAF_CHECK_EQUAL
(
p
(
R"(foo)"
),
pec
::
unexpected_character
);
CAF_CHECK_EQUAL
(
p
(
R"("abc" def)"
),
pec
::
trailing_character
);
CAF_CHECK_EQUAL
(
p
(
R"("abc" def)"
),
pec
::
trailing_character
);
CAF_CHECK_EQUAL
(
p
(
R"( 123, )"
),
pec
::
trailing_character
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
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