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
1287f030
Commit
1287f030
authored
Jan 10, 2015
by
Raphael Isemann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code point are two words, and so the "P" should be capital
parent
5a54e467
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
31 deletions
+31
-31
src/json.cc
src/json.cc
+28
-28
src/json.h
src/json.h
+3
-3
No files found.
src/json.cc
View file @
1287f030
...
...
@@ -2151,13 +2151,13 @@ Turns a code point into it's UTF-8 representation.
You should only pass numbers < 0x10ffff into this function
(everything else is a invalid code point).
@return the UTF-8 representation of the given codepoint
@return the UTF-8 representation of the given code
point
@pre This method isn't accessing the members of the parser
@post This method isn't accessing the members of the parser
*/
std
::
string
json
::
parser
::
code
pointToUTF8
(
unsigned
int
codep
oint
)
std
::
string
json
::
parser
::
code
PointToUTF8
(
unsigned
int
codeP
oint
)
{
// this method contains a lot of bit manipulations to
// build the bytes for UTF-8.
...
...
@@ -2171,49 +2171,49 @@ std::string json::parser::codepointToUTF8(unsigned int codepoint)
// (e.g. 1 to 4 bytes) to save the reallocations.
if
(
code
p
oint
<=
0x7f
)
if
(
code
P
oint
<=
0x7f
)
{
// it's just a ASCII compatible code
p
oint,
// it's just a ASCII compatible code
P
oint,
// so we just interpret the point as a character
// and return ASCII
return
std
::
string
(
1
,
static_cast
<
char
>
(
code
p
oint
));
return
std
::
string
(
1
,
static_cast
<
char
>
(
code
P
oint
));
}
// if true, we need two bytes to encode this as UTF-8
else
if
(
code
p
oint
<=
0x7ff
)
else
if
(
code
P
oint
<=
0x7ff
)
{
// the 0xC0 enables the two most significant two bits
// to make this a two-byte UTF-8 character.
std
::
string
result
(
2
,
static_cast
<
char
>
(
0xC0
|
((
code
p
oint
>>
6
)
&
0x1F
)));
result
[
1
]
=
static_cast
<
char
>
(
0x80
|
(
code
p
oint
&
0x3F
));
std
::
string
result
(
2
,
static_cast
<
char
>
(
0xC0
|
((
code
P
oint
>>
6
)
&
0x1F
)));
result
[
1
]
=
static_cast
<
char
>
(
0x80
|
(
code
P
oint
&
0x3F
));
return
result
;
}
// if true, now we need three bytes to encode this as UTF-8
else
if
(
code
p
oint
<=
0xffff
)
else
if
(
code
P
oint
<=
0xffff
)
{
// the 0xE0 enables the three most significant two bits
// to make this a three-byte UTF-8 character.
std
::
string
result
(
3
,
static_cast
<
char
>
(
0xE0
|
((
code
p
oint
>>
12
)
&
0x0F
)));
result
[
1
]
=
static_cast
<
char
>
(
0x80
|
((
code
p
oint
>>
6
)
&
0x3F
));
result
[
2
]
=
static_cast
<
char
>
(
0x80
|
(
code
p
oint
&
0x3F
));
std
::
string
result
(
3
,
static_cast
<
char
>
(
0xE0
|
((
code
P
oint
>>
12
)
&
0x0F
)));
result
[
1
]
=
static_cast
<
char
>
(
0x80
|
((
code
P
oint
>>
6
)
&
0x3F
));
result
[
2
]
=
static_cast
<
char
>
(
0x80
|
(
code
P
oint
&
0x3F
));
return
result
;
}
// if true, we need maximal four bytes to encode this as UTF-8
else
if
(
code
p
oint
<=
0x10ffff
)
else
if
(
code
P
oint
<=
0x10ffff
)
{
// the 0xE0 enables the four most significant two bits
// to make this a three-byte UTF-8 character.
std
::
string
result
(
4
,
static_cast
<
char
>
(
0xF0
|
((
code
p
oint
>>
18
)
&
0x07
)));
result
[
1
]
=
static_cast
<
char
>
(
0x80
|
((
code
p
oint
>>
12
)
&
0x3F
));
result
[
2
]
=
static_cast
<
char
>
(
0x80
|
((
code
p
oint
>>
6
)
&
0x3F
));
result
[
3
]
=
static_cast
<
char
>
(
0x80
|
(
code
p
oint
&
0x3F
));
std
::
string
result
(
4
,
static_cast
<
char
>
(
0xF0
|
((
code
P
oint
>>
18
)
&
0x07
)));
result
[
1
]
=
static_cast
<
char
>
(
0x80
|
((
code
P
oint
>>
12
)
&
0x3F
));
result
[
2
]
=
static_cast
<
char
>
(
0x80
|
((
code
P
oint
>>
6
)
&
0x3F
));
result
[
3
]
=
static_cast
<
char
>
(
0x80
|
(
code
P
oint
&
0x3F
));
return
result
;
}
else
{
// Can't be tested without direct access to this private method.
std
::
string
errorMessage
=
"Invalid code
p
oint: "
;
errorMessage
+=
code
p
oint
;
std
::
string
errorMessage
=
"Invalid code
P
oint: "
;
errorMessage
+=
code
P
oint
;
error
(
errorMessage
);
}
}
...
...
@@ -2227,7 +2227,7 @@ Parses 4 hexadecimal characters as a number.
@post pos_ is pointing to the character after the 4 hexadecimal characters.
*/
unsigned
int
json
::
parser
::
parse4HexCode
p
oint
()
unsigned
int
json
::
parser
::
parse4HexCode
P
oint
()
{
const
auto
startPos
=
pos_
;
...
...
@@ -2285,10 +2285,10 @@ std::string json::parser::parseUnicodeEscape()
// jump to the first hex value
pos_
++
;
// parse the hex first hex values
unsigned
int
firstCode
point
=
parse4HexCodep
oint
();
unsigned
int
firstCode
Point
=
parse4HexCodeP
oint
();
if
(
firstCode
point
>=
0xD800
&&
firstCodep
oint
<=
0xDBFF
)
if
(
firstCode
Point
>=
0xD800
&&
firstCodeP
oint
<=
0xDBFF
)
{
// we found invalid code points, which means we either have a malformed input
// or we found a high surrogate.
...
...
@@ -2299,29 +2299,29 @@ std::string json::parser::parseUnicodeEscape()
pos_
+=
2
;
// try to parse the next hex values.
// the method does boundary checking for us, so no need to do that here
unsigned
secondCode
point
=
parse4HexCodep
oint
();
unsigned
secondCode
Point
=
parse4HexCodeP
oint
();
// ok, we have a low surrogate, check if it is a valid one
if
(
secondCode
point
>=
0xDC00
&&
secondCodep
oint
<=
0xDFFF
)
if
(
secondCode
Point
>=
0xDC00
&&
secondCodeP
oint
<=
0xDFFF
)
{
// calculate the final code point from the pair according to the spec
unsigned
int
finalCodePoint
=
// high surrogate occupies the most significant 22 bits
(
firstCode
p
oint
<<
10
)
(
firstCode
P
oint
<<
10
)
// low surrogate occupies the least significant 15 bits
+
secondCode
p
oint
+
secondCode
P
oint
// there is still the 0xD800, 0xDC00 and 0x10000 noise in the result
// so we have to substract with (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
-
0x35FDC00
;
// we transform the calculated point into UTF-8
return
code
p
ointToUTF8
(
finalCodePoint
);
return
code
P
ointToUTF8
(
finalCodePoint
);
}
else
error
(
"missing low surrogate"
);
}
// We have Form 1, so we just interpret the XXXX as a code point
return
code
pointToUTF8
(
firstCodep
oint
);
return
code
PointToUTF8
(
firstCodeP
oint
);
}
...
...
src/json.h
View file @
1287f030
...
...
@@ -419,9 +419,9 @@ class json
/// parse a quoted string
inline
std
::
string
parseString
();
/// transforms a unicode codepoint to it's UTF-8 presentation
inline
std
::
string
code
pointToUTF8
(
unsigned
int
codep
oint
);
/// parses 4 hex characters that represent a unicode codepoint
inline
unsigned
int
parse4HexCode
p
oint
();
inline
std
::
string
code
PointToUTF8
(
unsigned
int
codeP
oint
);
/// parses 4 hex characters that represent a unicode code
point
inline
unsigned
int
parse4HexCode
P
oint
();
/// parses \uXXXX[\uXXXX] unicode escape characters
inline
std
::
string
parseUnicodeEscape
();
/// parse a Boolean "true"
...
...
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