Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
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
json
Commits
5a54e467
Commit
5a54e467
authored
Jan 10, 2015
by
Raphael Isemann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fully implemented the JSON spec
parent
222aacc2
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
224 additions
and
54 deletions
+224
-54
src/json.cc
src/json.cc
+182
-48
src/json.h
src/json.h
+4
-2
test/json_unit.cc
test/json_unit.cc
+38
-4
No files found.
src/json.cc
View file @
5a54e467
This diff is collapsed.
Click to expand it.
src/json.h
View file @
5a54e467
...
...
@@ -419,8 +419,10 @@ class json
/// parse a quoted string
inline
std
::
string
parseString
();
/// transforms a unicode codepoint to it's UTF-8 presentation
inline
std
::
string
unicodeToUTF8
(
unsigned
int
codepoint
);
/// parses a unicode escape sequence
inline
std
::
string
codepointToUTF8
(
unsigned
int
codepoint
);
/// parses 4 hex characters that represent a unicode codepoint
inline
unsigned
int
parse4HexCodepoint
();
/// parses \uXXXX[\uXXXX] unicode escape characters
inline
std
::
string
parseUnicodeEscape
();
/// parse a Boolean "true"
inline
void
parseTrue
();
...
...
test/json_unit.cc
View file @
5a54e467
...
...
@@ -1652,10 +1652,6 @@ TEST_CASE("Parser")
CHECK
(
json
::
parse
(
"
\"
a
\\
nz
\"
"
)
==
json
(
"a
\n
z"
));
CHECK
(
json
::
parse
(
"
\"\\
n
\"
"
)
==
json
(
"
\n
"
));
// escape unicode characters
CHECK
(
json
::
parse
(
"
\"\\
u002F
\"
"
)
==
json
(
"/"
));
CHECK
(
json
::
parse
(
"
\"\\
u00E4
\"
"
)
==
json
(
u8"\u00E4"
));
// escaping senseless stuff
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
z
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
\"
"
),
std
::
invalid_argument
);
...
...
@@ -1665,6 +1661,44 @@ TEST_CASE("Parser")
CHECK_THROWS_AS
(
json
::
parse
(
"
\"
"
),
std
::
invalid_argument
);
}
SECTION
(
"unicode_escaping"
)
{
// two tests for uppercase and lowercase hex
// normal forward slash in ASCII range
CHECK
(
json
::
parse
(
"
\"\\
u002F
\"
"
)
==
json
(
"/"
));
CHECK
(
json
::
parse
(
"
\"\\
u002f
\"
"
)
==
json
(
"/"
));
// german a umlaut
CHECK
(
json
::
parse
(
"
\"\\
u00E4
\"
"
)
==
json
(
u8"\u00E4"
));
CHECK
(
json
::
parse
(
"
\"\\
u00e4
\"
"
)
==
json
(
u8"\u00E4"
));
// weird d
CHECK
(
json
::
parse
(
"
\"\\
u0111
\"
"
)
==
json
(
u8"\u0111"
));
// unicode arrow left
CHECK
(
json
::
parse
(
"
\"\\
u2190
\"
"
)
==
json
(
u8"\u2190"
));
// pleasing osiris by testing hieroglyph support
CHECK
(
json
::
parse
(
"
\"\\
uD80C
\\
uDC60
\"
"
)
==
json
(
u8"\U00013060"
));
CHECK
(
json
::
parse
(
"
\"\\
ud80C
\\
udc60
\"
"
)
==
json
(
u8"\U00013060"
));
// no hex numbers behind the \u
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
uD80v
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
uD80 A
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
uD8v
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
uDv
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
uv
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
u
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
u
\\
u
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"
a
\\
uD80vAz
\"
"
),
std
::
invalid_argument
);
// missing part of a surrogate pair
CHECK_THROWS_AS
(
json
::
parse
(
"
\"
bla
\\
uD80C bla
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
uD80C bla bla
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"
bla bla
\\
uD80C bla bla
\"
"
),
std
::
invalid_argument
);
// senseless surrogate pair
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
uD80C
\\
uD80C
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
uD80C
\\
u0000
\"
"
),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parse
(
"
\"\\
uD80C
\\
uFFFF
\"
"
),
std
::
invalid_argument
);
}
SECTION
(
"boolean"
)
{
// accept the exact values
...
...
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