Skip to content

Commit 1fcd268

Browse files
committed
Better documentation.
1 parent bbeb64a commit 1fcd268

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

include/jsonparser/jsoncharutils.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ uint32_t hex_to_u32_nocheck(const u8 *src) {
7979
// and clz and table lookups, but JSON documents
8080
// have few escaped code points, and the following
8181
// function looks cheap.
82+
//
83+
// Note: we assume that surrogates are treated separately
84+
//
8285
inline size_t codepoint_to_utf8(uint32_t cp, u8 *c) {
8386
if (cp <= 0x7F) {
8487
c[0] = cp;
@@ -87,8 +90,9 @@ inline size_t codepoint_to_utf8(uint32_t cp, u8 *c) {
8790
c[0] = (cp >> 6) + 192;
8891
c[1] = (cp & 63) + 128;
8992
return 2; // universal plane
90-
} else if (0xd800 <= cp && cp <= 0xdfff) {
91-
return 0; // surrogates // could put assert here
93+
// Surrogates are treated elsewhere...
94+
//} //else if (0xd800 <= cp && cp <= 0xdfff) {
95+
// return 0; // surrogates // could put assert here
9296
} else if (cp <= 0xFFFF) {
9397
c[0] = (cp >> 12) + 224;
9498
c[1] = ((cp >> 6) & 63) + 128;
@@ -101,6 +105,7 @@ inline size_t codepoint_to_utf8(uint32_t cp, u8 *c) {
101105
c[3] = (cp & 63) + 128;
102106
return 4;
103107
}
104-
return 0; // bad // could put assert her
108+
// will return 0 when the code point was too large.
109+
return 0; // bad r
105110
}
106111

0 commit comments

Comments
 (0)