Skip to content

Commit

Permalink
📝 added documentation wrt. UTF-8 strings #406
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jan 4, 2017
1 parent cdd3b5a commit 4765070
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ Thanks a lot for helping out!
- Other encodings such as Latin-1, UTF-16, or UTF-32 are not supported and will yield parse errors.
- [Unicode noncharacters](http://www.unicode.org/faq/private_use.html#nonchar1) will not be replaced by the library.
- Invalid surrogates (e.g., incomplete pairs such as `\uDEAD`) will yield parse errors.
- The strings stored in the library are UTF-8 encoded. When using the default string type (`std::string`), note that its length/size functions return the number of stored bytes rather than the number of characters or glyphs.


## Execute unit tests
Expand Down
9 changes: 7 additions & 2 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ class basic_json
std::string
@endcode
#### Encoding
Strings are stored in UTF-8 encoding. Therefore, functions like
`std::string::size()` or `std::string::length()` return the number of
bytes in the string rather than the number of characters or glyphs.
#### String comparison
[RFC 7159](http://rfc7159.net/rfc7159) states:
Expand Down Expand Up @@ -7515,7 +7521,6 @@ class basic_json

case 0xf9: // Half-Precision Float (two-byte IEEE 754)
{
check_length(v.size(), 2, 1);
idx += 2; // skip two content bytes

// code from RFC 7049, Appendix D, Figure 3:
Expand All @@ -7525,7 +7530,7 @@ class basic_json
// include at least decoding support for them even without such
// support. An example of a small decoder for half-precision
// floating-point numbers in the C language is shown in Fig. 3.
const int half = (v[current_idx + 1] << 8) + v[current_idx + 2];
const int half = (v.at(current_idx + 1) << 8) + v.at(current_idx + 2);
const int exp = (half >> 10) & 0x1f;
const int mant = half & 0x3ff;
double val;
Expand Down
6 changes: 6 additions & 0 deletions src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ class basic_json
std::string
@endcode

#### Encoding

Strings are stored in UTF-8 encoding. Therefore, functions like
`std::string::size()` or `std::string::length()` return the number of
bytes in the string rather than the number of characters or glyphs.

#### String comparison

[RFC 7159](http://rfc7159.net/rfc7159) states:
Expand Down

0 comments on commit 4765070

Please sign in to comment.