Skip to content

Line continuation #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/hjson_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ static std::string _readString(Parser *p, bool allowML) {
uffff = uffff * 16 + hex;
}
_toUtf8(res, uffff);
} else if (p->ch == '\n') {
// Escaped line feed is ignored (line continuation is allowed).
} else if (p->ch == '\r' && _peek(p, 0) == '\n') {
// Escaped line feed is ignored (line continuation is allowed).
_next(p);
} else if ((ech = _escapee(p->ch))) {
res.push_back(ech);
} else {
Expand Down
3 changes: 3 additions & 0 deletions test/assets/JSON28_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
linebreak
]
3 changes: 3 additions & 0 deletions test/assets/JSON28_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"linebreak"
]
File renamed without changes.
3 changes: 3 additions & 0 deletions test/assets/comments/JSON28_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
linebreak
]
4 changes: 4 additions & 0 deletions test/assets/comments/strings4_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
# escaped \n
key: Look, Mom! No \n's!
}
4 changes: 4 additions & 0 deletions test/assets/comments/strings5_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
# escaped \r\n
key: Look, Mom! No \n's!
}
8 changes: 8 additions & 0 deletions test/assets/comments/strings6_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
# escaped \n should not cause line continuation in multiline string
key:
'''
Look, Mom! \
No \\n's!
'''
}
3 changes: 3 additions & 0 deletions test/assets/comments2/JSON28_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
linebreak
]
4 changes: 4 additions & 0 deletions test/assets/comments2/strings4_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
# escaped \n
key: Look, Mom! No \n's!
}
4 changes: 4 additions & 0 deletions test/assets/comments2/strings5_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
# escaped \r\n
key: Look, Mom! No \n's!
}
8 changes: 8 additions & 0 deletions test/assets/comments2/strings6_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
# escaped \n should not cause line continuation in multiline string
key:
'''
Look, Mom! \
No \\n's!
'''
}
5 changes: 5 additions & 0 deletions test/assets/failStr10a_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
# escaped \n should not cause line continuation in quoteless string
key: Look, Mom! \
No \\n's!
}
4 changes: 4 additions & 0 deletions test/assets/failStr9a_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
# escaped \r
key: "Look, Mom! \No \\n's!"
}
Expand Down
3 changes: 3 additions & 0 deletions test/assets/sorted/JSON28_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
linebreak
]
3 changes: 3 additions & 0 deletions test/assets/sorted/JSON28_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"linebreak"
]
3 changes: 3 additions & 0 deletions test/assets/sorted/strings4_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
key: Look, Mom! No \n's!
}
3 changes: 3 additions & 0 deletions test/assets/sorted/strings4_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! No \\n's!"
}
3 changes: 3 additions & 0 deletions test/assets/sorted/strings5_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
key: Look, Mom! No \n's!
}
3 changes: 3 additions & 0 deletions test/assets/sorted/strings5_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! No \\n's!"
}
7 changes: 7 additions & 0 deletions test/assets/sorted/strings6_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
key:
'''
Look, Mom! \
No \\n's!
'''
}
3 changes: 3 additions & 0 deletions test/assets/sorted/strings6_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! \\\nNo \\\\n's!"
}
3 changes: 3 additions & 0 deletions test/assets/strings4_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
key: Look, Mom! No \n's!
}
3 changes: 3 additions & 0 deletions test/assets/strings4_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! No \\n's!"
}
5 changes: 5 additions & 0 deletions test/assets/strings4_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
# escaped \n
key: "Look, Mom! \
No \\n's!"
}
3 changes: 3 additions & 0 deletions test/assets/strings5_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
key: Look, Mom! No \n's!
}
3 changes: 3 additions & 0 deletions test/assets/strings5_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! No \\n's!"
}
5 changes: 5 additions & 0 deletions test/assets/strings5_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
# escaped \r\n
key: "Look, Mom! \
No \\n's!"
}
7 changes: 7 additions & 0 deletions test/assets/strings6_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
key:
'''
Look, Mom! \
No \\n's!
'''
}
3 changes: 3 additions & 0 deletions test/assets/strings6_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"key": "Look, Mom! \\\nNo \\\\n's!"
}
8 changes: 8 additions & 0 deletions test/assets/strings6_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
# escaped \n should not cause line continuation in multiline string
key:
'''
Look, Mom! \
No \\n's!
'''
}
7 changes: 6 additions & 1 deletion test/assets/testlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ failJSON21_test.json
failJSON22_test.json
failJSON23_test.json
failJSON26_test.json
failJSON28_test.json
failJSON29_test.json
failJSON30_test.json
failJSON31_test.json
Expand Down Expand Up @@ -69,7 +68,10 @@ failStr6c_test.hjson
failStr6d_test.hjson
failStr7a_test.hjson
failStr8a_test.hjson
failStr9a_test.hjson
failStr10a_test.hjson
int64_test.hjson
JSON28_test.json
kan_test.hjson
keys_test.hjson
mltabs_test.json
Expand All @@ -84,6 +86,9 @@ root_test.hjson
stringify1_test.hjson
strings2_test.hjson
strings3_test.hjson
strings4_test.hjson
strings5_test.hjson
strings6_test.hjson
strings_test.hjson
trail_test.hjson
windowseol_test.hjson