Skip to content

Commit 66b310b

Browse files
Bin Zhangminggo
Bin Zhang
authored and
minggo
committed
Update rapid json to version 1.1.0. (#250)
1 parent 9d330c5 commit 66b310b

27 files changed

+8191
-6721
lines changed

json/allocators.h

+271-261
Large diffs are not rendered by default.

json/document.h

+2,575-2,014
Large diffs are not rendered by default.

json/encodedstream.h

+299-261
Large diffs are not rendered by default.

json/encodings.h

+716-625
Large diffs are not rendered by default.

json/error/en.h

+15-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1313
// specific language governing permissions and limitations under the License.
1414

15-
#ifndef RAPIDJSON_ERROR_EN_H__
16-
#define RAPIDJSON_ERROR_EN_H__
15+
#ifndef RAPIDJSON_ERROR_EN_H_
16+
#define RAPIDJSON_ERROR_EN_H_
1717

1818
#include "error.h"
1919

20+
#ifdef __clang__
21+
RAPIDJSON_DIAG_PUSH
22+
RAPIDJSON_DIAG_OFF(switch-enum)
23+
RAPIDJSON_DIAG_OFF(covered-switch-default)
24+
#endif
25+
2026
RAPIDJSON_NAMESPACE_BEGIN
2127

2228
//! Maps error code of parsing into error message.
@@ -32,7 +38,7 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro
3238
case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error.");
3339

3440
case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty.");
35-
case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not follow by other values.");
41+
case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values.");
3642

3743
case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value.");
3844

@@ -55,11 +61,14 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro
5561
case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
5662
case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
5763

58-
default:
59-
return RAPIDJSON_ERROR_STRING("Unknown error.");
64+
default: return RAPIDJSON_ERROR_STRING("Unknown error.");
6065
}
6166
}
6267

6368
RAPIDJSON_NAMESPACE_END
6469

65-
#endif // RAPIDJSON_ERROR_EN_H__
70+
#ifdef __clang__
71+
RAPIDJSON_DIAG_POP
72+
#endif
73+
74+
#endif // RAPIDJSON_ERROR_EN_H_

json/error/error.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1313
// specific language governing permissions and limitations under the License.
1414

15-
#ifndef RAPIDJSON_ERROR_ERROR_H__
16-
#define RAPIDJSON_ERROR_ERROR_H__
15+
#ifndef RAPIDJSON_ERROR_ERROR_H_
16+
#define RAPIDJSON_ERROR_ERROR_H_
1717

1818
#include "../rapidjson.h"
1919

20+
#ifdef __clang__
21+
RAPIDJSON_DIAG_PUSH
22+
RAPIDJSON_DIAG_OFF(padded)
23+
#endif
24+
2025
/*! \file error.h */
2126

2227
/*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */
@@ -99,7 +104,7 @@ enum ParseErrorCode {
99104
\see GenericReader::Parse, GenericDocument::Parse
100105
*/
101106
struct ParseResult {
102-
107+
public:
103108
//! Default constructor, no error.
104109
ParseResult() : code_(kParseErrorNone), offset_(0) {}
105110
//! Constructor to set an error.
@@ -143,4 +148,8 @@ typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode);
143148

144149
RAPIDJSON_NAMESPACE_END
145150

146-
#endif // RAPIDJSON_ERROR_ERROR_H__
151+
#ifdef __clang__
152+
RAPIDJSON_DIAG_POP
153+
#endif
154+
155+
#endif // RAPIDJSON_ERROR_ERROR_H_

json/filereadstream.h

+99-88
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,99 @@
1-
// Tencent is pleased to support the open source community by making RapidJSON available.
2-
//
3-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4-
//
5-
// Licensed under the MIT License (the "License"); you may not use this file except
6-
// in compliance with the License. You may obtain a copy of the License at
7-
//
8-
// http://opensource.org/licenses/MIT
9-
//
10-
// Unless required by applicable law or agreed to in writing, software distributed
11-
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12-
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13-
// specific language governing permissions and limitations under the License.
14-
15-
#ifndef RAPIDJSON_FILEREADSTREAM_H_
16-
#define RAPIDJSON_FILEREADSTREAM_H_
17-
18-
#include "rapidjson.h"
19-
#include <cstdio>
20-
21-
RAPIDJSON_NAMESPACE_BEGIN
22-
23-
//! File byte stream for input using fread().
24-
/*!
25-
\note implements Stream concept
26-
*/
27-
class FileReadStream {
28-
public:
29-
typedef char Ch; //!< Character type (byte).
30-
31-
//! Constructor.
32-
/*!
33-
\param fp File pointer opened for read.
34-
\param buffer user-supplied buffer.
35-
\param bufferSize size of buffer in bytes. Must >=4 bytes.
36-
*/
37-
FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
38-
RAPIDJSON_ASSERT(fp_ != 0);
39-
RAPIDJSON_ASSERT(bufferSize >= 4);
40-
Read();
41-
}
42-
43-
Ch Peek() const { return *current_; }
44-
Ch Take() { Ch c = *current_; Read(); return c; }
45-
size_t Tell() const { return count_ + static_cast<size_t>(current_ - buffer_); }
46-
47-
// Not implemented
48-
void Put(Ch) { RAPIDJSON_ASSERT(false); }
49-
void Flush() { RAPIDJSON_ASSERT(false); }
50-
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
51-
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
52-
53-
// For encoding detection only.
54-
const Ch* Peek4() const {
55-
return (current_ + 4 <= bufferLast_) ? current_ : 0;
56-
}
57-
58-
private:
59-
void Read() {
60-
if (current_ < bufferLast_)
61-
++current_;
62-
else if (!eof_) {
63-
count_ += readCount_;
64-
readCount_ = fread(buffer_, 1, bufferSize_, fp_);
65-
bufferLast_ = buffer_ + readCount_ - 1;
66-
current_ = buffer_;
67-
68-
if (readCount_ < bufferSize_) {
69-
buffer_[readCount_] = '\0';
70-
++bufferLast_;
71-
eof_ = true;
72-
}
73-
}
74-
}
75-
76-
std::FILE* fp_;
77-
Ch *buffer_;
78-
size_t bufferSize_;
79-
Ch *bufferLast_;
80-
Ch *current_;
81-
size_t readCount_;
82-
size_t count_; //!< Number of characters read
83-
bool eof_;
84-
};
85-
86-
RAPIDJSON_NAMESPACE_END
87-
88-
#endif // RAPIDJSON_FILESTREAM_H_
1+
// Tencent is pleased to support the open source community by making RapidJSON available.
2+
//
3+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4+
//
5+
// Licensed under the MIT License (the "License"); you may not use this file except
6+
// in compliance with the License. You may obtain a copy of the License at
7+
//
8+
// http://opensource.org/licenses/MIT
9+
//
10+
// Unless required by applicable law or agreed to in writing, software distributed
11+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
// specific language governing permissions and limitations under the License.
14+
15+
#ifndef RAPIDJSON_FILEREADSTREAM_H_
16+
#define RAPIDJSON_FILEREADSTREAM_H_
17+
18+
#include "stream.h"
19+
#include <cstdio>
20+
21+
#ifdef __clang__
22+
RAPIDJSON_DIAG_PUSH
23+
RAPIDJSON_DIAG_OFF(padded)
24+
RAPIDJSON_DIAG_OFF(unreachable-code)
25+
RAPIDJSON_DIAG_OFF(missing-noreturn)
26+
#endif
27+
28+
RAPIDJSON_NAMESPACE_BEGIN
29+
30+
//! File byte stream for input using fread().
31+
/*!
32+
\note implements Stream concept
33+
*/
34+
class FileReadStream {
35+
public:
36+
typedef char Ch; //!< Character type (byte).
37+
38+
//! Constructor.
39+
/*!
40+
\param fp File pointer opened for read.
41+
\param buffer user-supplied buffer.
42+
\param bufferSize size of buffer in bytes. Must >=4 bytes.
43+
*/
44+
FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
45+
RAPIDJSON_ASSERT(fp_ != 0);
46+
RAPIDJSON_ASSERT(bufferSize >= 4);
47+
Read();
48+
}
49+
50+
Ch Peek() const { return *current_; }
51+
Ch Take() { Ch c = *current_; Read(); return c; }
52+
size_t Tell() const { return count_ + static_cast<size_t>(current_ - buffer_); }
53+
54+
// Not implemented
55+
void Put(Ch) { RAPIDJSON_ASSERT(false); }
56+
void Flush() { RAPIDJSON_ASSERT(false); }
57+
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
58+
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
59+
60+
// For encoding detection only.
61+
const Ch* Peek4() const {
62+
return (current_ + 4 <= bufferLast_) ? current_ : 0;
63+
}
64+
65+
private:
66+
void Read() {
67+
if (current_ < bufferLast_)
68+
++current_;
69+
else if (!eof_) {
70+
count_ += readCount_;
71+
readCount_ = fread(buffer_, 1, bufferSize_, fp_);
72+
bufferLast_ = buffer_ + readCount_ - 1;
73+
current_ = buffer_;
74+
75+
if (readCount_ < bufferSize_) {
76+
buffer_[readCount_] = '\0';
77+
++bufferLast_;
78+
eof_ = true;
79+
}
80+
}
81+
}
82+
83+
std::FILE* fp_;
84+
Ch *buffer_;
85+
size_t bufferSize_;
86+
Ch *bufferLast_;
87+
Ch *current_;
88+
size_t readCount_;
89+
size_t count_; //!< Number of characters read
90+
bool eof_;
91+
};
92+
93+
RAPIDJSON_NAMESPACE_END
94+
95+
#ifdef __clang__
96+
RAPIDJSON_DIAG_POP
97+
#endif
98+
99+
#endif // RAPIDJSON_FILESTREAM_H_

json/filestream.h

-73
This file was deleted.

0 commit comments

Comments
 (0)