Permalink
Browse files

📝 added documentation wrt. UTF-8 strings #406

  • Loading branch information...
1 parent cdd3b5a commit 476507031890fd6effb7b447a156168803b0bd37 @nlohmann committed Jan 4, 2017
Showing with 14 additions and 2 deletions.
  1. +1 −0 README.md
  2. +7 −2 src/json.hpp
  3. +6 −0 src/json.hpp.re2c
View
@@ -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
View
@@ -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:
@@ -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:
@@ -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;
View
@@ -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:

0 comments on commit 4765070

Please sign in to comment.