Skip to content

Commit cd737fb

Browse files
committed
Improve documentation
Signed-off-by: Saurabh Charde <[email protected]>
1 parent 25fa7a1 commit cd737fb

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

doc/stream.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stream
22

3-
In RapidJSON, `rapidjson::Stream` is a concept for reading/writing JSON. Here we first show how to use streams provided. And then see how to create a custom stream.
3+
In RapidJSON, `rapidjson::Stream` is a concept for reading/writing JSON. Here we'll first show you how to use provided streams. And then see how to create a custom stream.
44

55
[TOC]
66

@@ -51,7 +51,7 @@ d.Accept(writer);
5151
const char* output = buffer.GetString();
5252
~~~~~~~~~~
5353
54-
When the buffer is full, it will increases the capacity automatically. The default capacity is 256 characters (256 bytes for UTF8, 512 bytes for UTF16, etc.). User can provide an allocator and a initial capacity.
54+
When the buffer is full, it will increases the capacity automatically. The default capacity is 256 characters (256 bytes for UTF8, 512 bytes for UTF16, etc.). User can provide an allocator and an initial capacity.
5555
5656
~~~~~~~~~~cpp
5757
StringBuffer buffer1(0, 1024); // Use its allocator, initial size = 1024
@@ -89,7 +89,7 @@ d.ParseStream(is);
8989
fclose(fp);
9090
~~~~~~~~~~
9191
92-
Different from string streams, `FileReadStream` is byte stream. It does not handle encodings. If the file is not UTF-8, the byte stream can be wrapped in a `EncodedInputStream`. It will be discussed very soon.
92+
Different from string streams, `FileReadStream` is byte stream. It does not handle encodings. If the file is not UTF-8, the byte stream can be wrapped in a `EncodedInputStream`. We will discuss more about this later in this tutorial.
9393
9494
Apart from reading file, user can also use `FileReadStream` to read `stdin`.
9595
@@ -119,11 +119,11 @@ d.Accept(writer);
119119
fclose(fp);
120120
~~~~~~~~~~
121121

122-
It can also directs the output to `stdout`.
122+
It can also redirect the output to `stdout`.
123123

124124
# iostream Wrapper {#iostreamWrapper}
125125

126-
Due to users' requests, RapidJSON provided official wrappers for `std::basic_istream` and `std::basic_ostream`. However, please note that the performance will be much lower than the other streams above.
126+
Due to users' requests, RapidJSON also provides official wrappers for `std::basic_istream` and `std::basic_ostream`. However, please note that the performance will be much lower than the other streams above.
127127

128128
## IStreamWrapper {#IStreamWrapper}
129129

@@ -181,7 +181,7 @@ As mentioned above, UTF-8 byte streams can be read directly. However, UTF-16 and
181181

182182
Besides, it also need to handle [byte order mark (BOM)](http://en.wikipedia.org/wiki/Byte_order_mark). When reading from a byte stream, it is needed to detect or just consume the BOM if exists. When writing to a byte stream, it can optionally write BOM.
183183

184-
If the encoding of stream is known in compile-time, you may use `EncodedInputStream` and `EncodedOutputStream`. If the stream can be UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE JSON, and it is only known in runtime, you may use `AutoUTFInputStream` and `AutoUTFOutputStream`. These streams are defined in `rapidjson/encodedstream.h`.
184+
If the encoding of stream is known during compile-time, you may use `EncodedInputStream` and `EncodedOutputStream`. If the stream can be UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE JSON, and it is only known in runtime, you may use `AutoUTFInputStream` and `AutoUTFOutputStream`. These streams are defined in `rapidjson/encodedstream.h`.
185185

186186
Note that, these encoded streams can be applied to streams other than file. For example, you may have a file in memory, or a custom byte stream, be wrapped in encoded streams.
187187

doc/tutorial.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Each JSON value is stored in a type called `Value`. A `Document`, representing t
1212

1313
# Query Value {#QueryValue}
1414

15-
In this section, we will use excerpt of `example/tutorial/tutorial.cpp`.
15+
In this section, we will use excerpt from `example/tutorial/tutorial.cpp`.
1616

1717
Assume we have the following JSON stored in a C string (`const char* json`):
1818
~~~~~~~~~~js
@@ -85,7 +85,7 @@ assert(document["i"].IsNumber());
8585
// In this case, IsUint()/IsInt64()/IsUint64() also return true.
8686
assert(document["i"].IsInt());
8787
printf("i = %d\n", document["i"].GetInt());
88-
// Alternative (int)document["i"]
88+
// Alternatively (int)document["i"]
8989

9090
assert(document["pi"].IsNumber());
9191
assert(document["pi"].IsDouble());
@@ -113,7 +113,7 @@ a[2] = 3
113113
a[3] = 4
114114
~~~~~~~~~~
115115

116-
Note that, RapidJSON does not automatically convert values between JSON types. If a value is a string, it is invalid to call `GetInt()`, for example. In debug mode it will fail an assertion. In release mode, the behavior is undefined.
116+
Note that, RapidJSON does not automatically convert values between JSON types. For example, if a value is a string, it is invalid to call `GetInt()`. In debug mode it will fail on assertion. In release mode, the behavior is undefined.
117117

118118
In the following sections we discuss details about querying individual types.
119119

@@ -168,9 +168,9 @@ Type of member pi is Number
168168
Type of member a is Array
169169
~~~~~~~~~~
170170
171-
Note that, when `operator[](const char*)` cannot find the member, it will fail an assertion.
171+
Note that, when `operator[](const char*)` cannot find the member, it will fail on assertion.
172172
173-
If we are unsure whether a member exists, we need to call `HasMember()` before calling `operator[](const char*)`. However, this incurs two lookup. A better way is to call `FindMember()`, which can check the existence of member and obtain its value at once:
173+
If we are unsure whether a member exists, we need to call `HasMember()` before calling `operator[](const char*)`. However, this incurs two lookup. A better way is to call `FindMember()`, which can check the existence of a member and obtain its value at once:
174174
175175
~~~~~~~~~~cpp
176176
Value::ConstMemberIterator itr = document.FindMember("hello");
@@ -221,18 +221,18 @@ When obtaining the numeric values, `GetDouble()` will convert internal integer r
221221
222222
## Query String {#QueryString}
223223
224-
In addition to `GetString()`, the `Value` class also contains `GetStringLength()`. Here explains why.
224+
In addition to `GetString()`, the `Value` class also contains `GetStringLength()`. Here explains why:
225225
226-
According to RFC 4627, JSON strings can contain Unicode character `U+0000`, which must be escaped as `"\u0000"`. The problem is that, C/C++ often uses null-terminated string, which treats ``\0'` as the terminator symbol.
226+
According to RFC 4627, JSON strings can contain Unicode character `U+0000`, which must be escaped as `"\u0000"`. The problem is that, C/C++ often uses null-terminated string, which treats `\0` as the terminator symbol.
227227
228-
To conform RFC 4627, RapidJSON supports string containing `U+0000`. If you need to handle this, you can use `GetStringLength()` to obtain the correct string length.
228+
To conform with RFC 4627, RapidJSON supports string containing `U+0000` character. If you need to handle this, you can use `GetStringLength()` to obtain the correct string length.
229229
230-
For example, after parsing a the following JSON to `Document d`:
230+
For example, after parsing the following JSON to `Document d`:
231231
232232
~~~~~~~~~~js
233233
{ "s" : "a\u0000b" }
234234
~~~~~~~~~~
235-
The correct length of the value `"a\u0000b"` is 3. But `strlen()` returns 1.
235+
The correct length of the string `"a\u0000b"` is 3, as returned by `GetStringLength()`. But `strlen()` returns 1.
236236

237237
`GetStringLength()` can also improve performance, as user may often need to call `strlen()` for allocating buffer.
238238

@@ -246,7 +246,7 @@ which accepts the length of string as parameter. This constructor supports stori
246246
247247
## Comparing values
248248
249-
You can use `==` and `!=` to compare values. Two values are equal if and only if they are have same type and contents. You can also compare values with primitive types. Here is an example.
249+
You can use `==` and `!=` to compare values. Two values are equal if and only if they have same type and contents. You can also compare values with primitive types. Here is an example:
250250
251251
~~~~~~~~~~cpp
252252
if (document["hello"] == document["n"]) /*...*/; // Compare values
@@ -264,7 +264,7 @@ Note that, currently if an object contains duplicated named member, comparing eq
264264
There are several ways to create values. After a DOM tree is created and/or modified, it can be saved as JSON again using `Writer`.
265265

266266
## Change Value Type {#ChangeValueType}
267-
When creating a Value or Document by default constructor, its type is Null. To change its type, call `SetXXX()` or assignment operator, for example:
267+
When creating a `Value` or `Document` by default constructor, its type is Null. To change its type, call `SetXXX()` or assignment operator, for example:
268268

269269
~~~~~~~~~~cpp
270270
Document d; // Null
@@ -285,7 +285,7 @@ Value u(123u); // calls Value(unsigned)
285285
Value d(1.5); // calls Value(double)
286286
~~~~~~~~~~
287287
288-
To create empty object or array, you may use `SetObject()`/`SetArray()` after default constructor, or using the `Value(Type)` in one shot:
288+
To create empty object or array, you may use `SetObject()`/`SetArray()` after default constructor, or using the `Value(Type)` in one call:
289289
290290
~~~~~~~~~~cpp
291291
Value o(kObjectType);
@@ -299,7 +299,7 @@ A very special decision during design of RapidJSON is that, assignment of value
299299
~~~~~~~~~~cpp
300300
Value a(123);
301301
Value b(456);
302-
b = a; // a becomes a Null value, b becomes number 123.
302+
a = b; // b becomes a Null value, a becomes number 456.
303303
~~~~~~~~~~
304304
305305
![Assignment with move semantics.](diagram/move1.png)
@@ -367,7 +367,7 @@ RapidJSON provides two strategies for storing string.
367367

368368
Copy-string is always safe because it owns a copy of the data. Const-string can be used for storing a string literal, and for in-situ parsing which will be mentioned in the DOM section.
369369

370-
To make memory allocation customizable, RapidJSON requires users to pass an instance of allocator, whenever an operation may require allocation. This design is needed to prevent storing a allocator (or Document) pointer per Value.
370+
To make memory allocation customizable, RapidJSON requires users to pass an instance of allocator, whenever an operation may require allocation. This design is needed to prevent storing an allocator (or Document) pointer per Value.
371371

372372
Therefore, when we assign a copy-string, we call this overloaded `SetString()` with allocator:
373373

0 commit comments

Comments
 (0)