rapidjson 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/CODE_OF_CONDUCT.md +84 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +110 -0
  5. data/Rakefile +20 -0
  6. data/ext/rapidjson/buffer.hh +66 -0
  7. data/ext/rapidjson/cext.cc +77 -0
  8. data/ext/rapidjson/cext.hh +20 -0
  9. data/ext/rapidjson/encoder.hh +150 -0
  10. data/ext/rapidjson/extconf.rb +19 -0
  11. data/ext/rapidjson/parser.hh +149 -0
  12. data/ext/rapidjson/rapidjson/include/rapidjson/allocators.h +692 -0
  13. data/ext/rapidjson/rapidjson/include/rapidjson/cursorstreamwrapper.h +78 -0
  14. data/ext/rapidjson/rapidjson/include/rapidjson/document.h +3027 -0
  15. data/ext/rapidjson/rapidjson/include/rapidjson/encodedstream.h +299 -0
  16. data/ext/rapidjson/rapidjson/include/rapidjson/encodings.h +716 -0
  17. data/ext/rapidjson/rapidjson/include/rapidjson/error/en.h +122 -0
  18. data/ext/rapidjson/rapidjson/include/rapidjson/error/error.h +216 -0
  19. data/ext/rapidjson/rapidjson/include/rapidjson/filereadstream.h +99 -0
  20. data/ext/rapidjson/rapidjson/include/rapidjson/filewritestream.h +104 -0
  21. data/ext/rapidjson/rapidjson/include/rapidjson/fwd.h +151 -0
  22. data/ext/rapidjson/rapidjson/include/rapidjson/internal/biginteger.h +297 -0
  23. data/ext/rapidjson/rapidjson/include/rapidjson/internal/clzll.h +71 -0
  24. data/ext/rapidjson/rapidjson/include/rapidjson/internal/diyfp.h +261 -0
  25. data/ext/rapidjson/rapidjson/include/rapidjson/internal/dtoa.h +249 -0
  26. data/ext/rapidjson/rapidjson/include/rapidjson/internal/ieee754.h +78 -0
  27. data/ext/rapidjson/rapidjson/include/rapidjson/internal/itoa.h +308 -0
  28. data/ext/rapidjson/rapidjson/include/rapidjson/internal/meta.h +186 -0
  29. data/ext/rapidjson/rapidjson/include/rapidjson/internal/pow10.h +55 -0
  30. data/ext/rapidjson/rapidjson/include/rapidjson/internal/regex.h +739 -0
  31. data/ext/rapidjson/rapidjson/include/rapidjson/internal/stack.h +232 -0
  32. data/ext/rapidjson/rapidjson/include/rapidjson/internal/strfunc.h +83 -0
  33. data/ext/rapidjson/rapidjson/include/rapidjson/internal/strtod.h +293 -0
  34. data/ext/rapidjson/rapidjson/include/rapidjson/internal/swap.h +46 -0
  35. data/ext/rapidjson/rapidjson/include/rapidjson/istreamwrapper.h +128 -0
  36. data/ext/rapidjson/rapidjson/include/rapidjson/memorybuffer.h +70 -0
  37. data/ext/rapidjson/rapidjson/include/rapidjson/memorystream.h +71 -0
  38. data/ext/rapidjson/rapidjson/include/rapidjson/msinttypes/inttypes.h +316 -0
  39. data/ext/rapidjson/rapidjson/include/rapidjson/msinttypes/stdint.h +300 -0
  40. data/ext/rapidjson/rapidjson/include/rapidjson/ostreamwrapper.h +81 -0
  41. data/ext/rapidjson/rapidjson/include/rapidjson/pointer.h +1482 -0
  42. data/ext/rapidjson/rapidjson/include/rapidjson/prettywriter.h +277 -0
  43. data/ext/rapidjson/rapidjson/include/rapidjson/rapidjson.h +741 -0
  44. data/ext/rapidjson/rapidjson/include/rapidjson/reader.h +2246 -0
  45. data/ext/rapidjson/rapidjson/include/rapidjson/schema.h +2795 -0
  46. data/ext/rapidjson/rapidjson/include/rapidjson/stream.h +223 -0
  47. data/ext/rapidjson/rapidjson/include/rapidjson/stringbuffer.h +121 -0
  48. data/ext/rapidjson/rapidjson/include/rapidjson/uri.h +481 -0
  49. data/ext/rapidjson/rapidjson/include/rapidjson/writer.h +710 -0
  50. data/lib/rapidjson/json_gem.rb +36 -0
  51. data/lib/rapidjson/version.rb +5 -0
  52. data/lib/rapidjson.rb +9 -0
  53. metadata +98 -0
@@ -0,0 +1,151 @@
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.
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_FWD_H_
16
+ #define RAPIDJSON_FWD_H_
17
+
18
+ #include "rapidjson.h"
19
+
20
+ RAPIDJSON_NAMESPACE_BEGIN
21
+
22
+ // encodings.h
23
+
24
+ template<typename CharType> struct UTF8;
25
+ template<typename CharType> struct UTF16;
26
+ template<typename CharType> struct UTF16BE;
27
+ template<typename CharType> struct UTF16LE;
28
+ template<typename CharType> struct UTF32;
29
+ template<typename CharType> struct UTF32BE;
30
+ template<typename CharType> struct UTF32LE;
31
+ template<typename CharType> struct ASCII;
32
+ template<typename CharType> struct AutoUTF;
33
+
34
+ template<typename SourceEncoding, typename TargetEncoding>
35
+ struct Transcoder;
36
+
37
+ // allocators.h
38
+
39
+ class CrtAllocator;
40
+
41
+ template <typename BaseAllocator>
42
+ class MemoryPoolAllocator;
43
+
44
+ // stream.h
45
+
46
+ template <typename Encoding>
47
+ struct GenericStringStream;
48
+
49
+ typedef GenericStringStream<UTF8<char> > StringStream;
50
+
51
+ template <typename Encoding>
52
+ struct GenericInsituStringStream;
53
+
54
+ typedef GenericInsituStringStream<UTF8<char> > InsituStringStream;
55
+
56
+ // stringbuffer.h
57
+
58
+ template <typename Encoding, typename Allocator>
59
+ class GenericStringBuffer;
60
+
61
+ typedef GenericStringBuffer<UTF8<char>, CrtAllocator> StringBuffer;
62
+
63
+ // filereadstream.h
64
+
65
+ class FileReadStream;
66
+
67
+ // filewritestream.h
68
+
69
+ class FileWriteStream;
70
+
71
+ // memorybuffer.h
72
+
73
+ template <typename Allocator>
74
+ struct GenericMemoryBuffer;
75
+
76
+ typedef GenericMemoryBuffer<CrtAllocator> MemoryBuffer;
77
+
78
+ // memorystream.h
79
+
80
+ struct MemoryStream;
81
+
82
+ // reader.h
83
+
84
+ template<typename Encoding, typename Derived>
85
+ struct BaseReaderHandler;
86
+
87
+ template <typename SourceEncoding, typename TargetEncoding, typename StackAllocator>
88
+ class GenericReader;
89
+
90
+ typedef GenericReader<UTF8<char>, UTF8<char>, CrtAllocator> Reader;
91
+
92
+ // writer.h
93
+
94
+ template<typename OutputStream, typename SourceEncoding, typename TargetEncoding, typename StackAllocator, unsigned writeFlags>
95
+ class Writer;
96
+
97
+ // prettywriter.h
98
+
99
+ template<typename OutputStream, typename SourceEncoding, typename TargetEncoding, typename StackAllocator, unsigned writeFlags>
100
+ class PrettyWriter;
101
+
102
+ // document.h
103
+
104
+ template <typename Encoding, typename Allocator>
105
+ class GenericMember;
106
+
107
+ template <bool Const, typename Encoding, typename Allocator>
108
+ class GenericMemberIterator;
109
+
110
+ template<typename CharType>
111
+ struct GenericStringRef;
112
+
113
+ template <typename Encoding, typename Allocator>
114
+ class GenericValue;
115
+
116
+ typedef GenericValue<UTF8<char>, MemoryPoolAllocator<CrtAllocator> > Value;
117
+
118
+ template <typename Encoding, typename Allocator, typename StackAllocator>
119
+ class GenericDocument;
120
+
121
+ typedef GenericDocument<UTF8<char>, MemoryPoolAllocator<CrtAllocator>, CrtAllocator> Document;
122
+
123
+ // pointer.h
124
+
125
+ template <typename ValueType, typename Allocator>
126
+ class GenericPointer;
127
+
128
+ typedef GenericPointer<Value, CrtAllocator> Pointer;
129
+
130
+ // schema.h
131
+
132
+ template <typename SchemaDocumentType>
133
+ class IGenericRemoteSchemaDocumentProvider;
134
+
135
+ template <typename ValueT, typename Allocator>
136
+ class GenericSchemaDocument;
137
+
138
+ typedef GenericSchemaDocument<Value, CrtAllocator> SchemaDocument;
139
+ typedef IGenericRemoteSchemaDocumentProvider<SchemaDocument> IRemoteSchemaDocumentProvider;
140
+
141
+ template <
142
+ typename SchemaDocumentType,
143
+ typename OutputHandler,
144
+ typename StateAllocator>
145
+ class GenericSchemaValidator;
146
+
147
+ typedef GenericSchemaValidator<SchemaDocument, BaseReaderHandler<UTF8<char>, void>, CrtAllocator> SchemaValidator;
148
+
149
+ RAPIDJSON_NAMESPACE_END
150
+
151
+ #endif // RAPIDJSON_RAPIDJSONFWD_H_
@@ -0,0 +1,297 @@
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.
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_BIGINTEGER_H_
16
+ #define RAPIDJSON_BIGINTEGER_H_
17
+
18
+ #include "../rapidjson.h"
19
+
20
+ #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && defined(_M_AMD64)
21
+ #include <intrin.h> // for _umul128
22
+ #if !defined(_ARM64EC_)
23
+ #pragma intrinsic(_umul128)
24
+ #else
25
+ #pragma comment(lib,"softintrin")
26
+ #endif
27
+ #endif
28
+
29
+ RAPIDJSON_NAMESPACE_BEGIN
30
+ namespace internal {
31
+
32
+ class BigInteger {
33
+ public:
34
+ typedef uint64_t Type;
35
+
36
+ BigInteger(const BigInteger& rhs) : count_(rhs.count_) {
37
+ std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type));
38
+ }
39
+
40
+ explicit BigInteger(uint64_t u) : count_(1) {
41
+ digits_[0] = u;
42
+ }
43
+
44
+ template<typename Ch>
45
+ BigInteger(const Ch* decimals, size_t length) : count_(1) {
46
+ RAPIDJSON_ASSERT(length > 0);
47
+ digits_[0] = 0;
48
+ size_t i = 0;
49
+ const size_t kMaxDigitPerIteration = 19; // 2^64 = 18446744073709551616 > 10^19
50
+ while (length >= kMaxDigitPerIteration) {
51
+ AppendDecimal64(decimals + i, decimals + i + kMaxDigitPerIteration);
52
+ length -= kMaxDigitPerIteration;
53
+ i += kMaxDigitPerIteration;
54
+ }
55
+
56
+ if (length > 0)
57
+ AppendDecimal64(decimals + i, decimals + i + length);
58
+ }
59
+
60
+ BigInteger& operator=(const BigInteger &rhs)
61
+ {
62
+ if (this != &rhs) {
63
+ count_ = rhs.count_;
64
+ std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type));
65
+ }
66
+ return *this;
67
+ }
68
+
69
+ BigInteger& operator=(uint64_t u) {
70
+ digits_[0] = u;
71
+ count_ = 1;
72
+ return *this;
73
+ }
74
+
75
+ BigInteger& operator+=(uint64_t u) {
76
+ Type backup = digits_[0];
77
+ digits_[0] += u;
78
+ for (size_t i = 0; i < count_ - 1; i++) {
79
+ if (digits_[i] >= backup)
80
+ return *this; // no carry
81
+ backup = digits_[i + 1];
82
+ digits_[i + 1] += 1;
83
+ }
84
+
85
+ // Last carry
86
+ if (digits_[count_ - 1] < backup)
87
+ PushBack(1);
88
+
89
+ return *this;
90
+ }
91
+
92
+ BigInteger& operator*=(uint64_t u) {
93
+ if (u == 0) return *this = 0;
94
+ if (u == 1) return *this;
95
+ if (*this == 1) return *this = u;
96
+
97
+ uint64_t k = 0;
98
+ for (size_t i = 0; i < count_; i++) {
99
+ uint64_t hi;
100
+ digits_[i] = MulAdd64(digits_[i], u, k, &hi);
101
+ k = hi;
102
+ }
103
+
104
+ if (k > 0)
105
+ PushBack(k);
106
+
107
+ return *this;
108
+ }
109
+
110
+ BigInteger& operator*=(uint32_t u) {
111
+ if (u == 0) return *this = 0;
112
+ if (u == 1) return *this;
113
+ if (*this == 1) return *this = u;
114
+
115
+ uint64_t k = 0;
116
+ for (size_t i = 0; i < count_; i++) {
117
+ const uint64_t c = digits_[i] >> 32;
118
+ const uint64_t d = digits_[i] & 0xFFFFFFFF;
119
+ const uint64_t uc = u * c;
120
+ const uint64_t ud = u * d;
121
+ const uint64_t p0 = ud + k;
122
+ const uint64_t p1 = uc + (p0 >> 32);
123
+ digits_[i] = (p0 & 0xFFFFFFFF) | (p1 << 32);
124
+ k = p1 >> 32;
125
+ }
126
+
127
+ if (k > 0)
128
+ PushBack(k);
129
+
130
+ return *this;
131
+ }
132
+
133
+ BigInteger& operator<<=(size_t shift) {
134
+ if (IsZero() || shift == 0) return *this;
135
+
136
+ size_t offset = shift / kTypeBit;
137
+ size_t interShift = shift % kTypeBit;
138
+ RAPIDJSON_ASSERT(count_ + offset <= kCapacity);
139
+
140
+ if (interShift == 0) {
141
+ std::memmove(digits_ + offset, digits_, count_ * sizeof(Type));
142
+ count_ += offset;
143
+ }
144
+ else {
145
+ digits_[count_] = 0;
146
+ for (size_t i = count_; i > 0; i--)
147
+ digits_[i + offset] = (digits_[i] << interShift) | (digits_[i - 1] >> (kTypeBit - interShift));
148
+ digits_[offset] = digits_[0] << interShift;
149
+ count_ += offset;
150
+ if (digits_[count_])
151
+ count_++;
152
+ }
153
+
154
+ std::memset(digits_, 0, offset * sizeof(Type));
155
+
156
+ return *this;
157
+ }
158
+
159
+ bool operator==(const BigInteger& rhs) const {
160
+ return count_ == rhs.count_ && std::memcmp(digits_, rhs.digits_, count_ * sizeof(Type)) == 0;
161
+ }
162
+
163
+ bool operator==(const Type rhs) const {
164
+ return count_ == 1 && digits_[0] == rhs;
165
+ }
166
+
167
+ BigInteger& MultiplyPow5(unsigned exp) {
168
+ static const uint32_t kPow5[12] = {
169
+ 5,
170
+ 5 * 5,
171
+ 5 * 5 * 5,
172
+ 5 * 5 * 5 * 5,
173
+ 5 * 5 * 5 * 5 * 5,
174
+ 5 * 5 * 5 * 5 * 5 * 5,
175
+ 5 * 5 * 5 * 5 * 5 * 5 * 5,
176
+ 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
177
+ 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
178
+ 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
179
+ 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
180
+ 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5
181
+ };
182
+ if (exp == 0) return *this;
183
+ for (; exp >= 27; exp -= 27) *this *= RAPIDJSON_UINT64_C2(0X6765C793, 0XFA10079D); // 5^27
184
+ for (; exp >= 13; exp -= 13) *this *= static_cast<uint32_t>(1220703125u); // 5^13
185
+ if (exp > 0) *this *= kPow5[exp - 1];
186
+ return *this;
187
+ }
188
+
189
+ // Compute absolute difference of this and rhs.
190
+ // Assume this != rhs
191
+ bool Difference(const BigInteger& rhs, BigInteger* out) const {
192
+ int cmp = Compare(rhs);
193
+ RAPIDJSON_ASSERT(cmp != 0);
194
+ const BigInteger *a, *b; // Makes a > b
195
+ bool ret;
196
+ if (cmp < 0) { a = &rhs; b = this; ret = true; }
197
+ else { a = this; b = &rhs; ret = false; }
198
+
199
+ Type borrow = 0;
200
+ for (size_t i = 0; i < a->count_; i++) {
201
+ Type d = a->digits_[i] - borrow;
202
+ if (i < b->count_)
203
+ d -= b->digits_[i];
204
+ borrow = (d > a->digits_[i]) ? 1 : 0;
205
+ out->digits_[i] = d;
206
+ if (d != 0)
207
+ out->count_ = i + 1;
208
+ }
209
+
210
+ return ret;
211
+ }
212
+
213
+ int Compare(const BigInteger& rhs) const {
214
+ if (count_ != rhs.count_)
215
+ return count_ < rhs.count_ ? -1 : 1;
216
+
217
+ for (size_t i = count_; i-- > 0;)
218
+ if (digits_[i] != rhs.digits_[i])
219
+ return digits_[i] < rhs.digits_[i] ? -1 : 1;
220
+
221
+ return 0;
222
+ }
223
+
224
+ size_t GetCount() const { return count_; }
225
+ Type GetDigit(size_t index) const { RAPIDJSON_ASSERT(index < count_); return digits_[index]; }
226
+ bool IsZero() const { return count_ == 1 && digits_[0] == 0; }
227
+
228
+ private:
229
+ template<typename Ch>
230
+ void AppendDecimal64(const Ch* begin, const Ch* end) {
231
+ uint64_t u = ParseUint64(begin, end);
232
+ if (IsZero())
233
+ *this = u;
234
+ else {
235
+ unsigned exp = static_cast<unsigned>(end - begin);
236
+ (MultiplyPow5(exp) <<= exp) += u; // *this = *this * 10^exp + u
237
+ }
238
+ }
239
+
240
+ void PushBack(Type digit) {
241
+ RAPIDJSON_ASSERT(count_ < kCapacity);
242
+ digits_[count_++] = digit;
243
+ }
244
+
245
+ template<typename Ch>
246
+ static uint64_t ParseUint64(const Ch* begin, const Ch* end) {
247
+ uint64_t r = 0;
248
+ for (const Ch* p = begin; p != end; ++p) {
249
+ RAPIDJSON_ASSERT(*p >= Ch('0') && *p <= Ch('9'));
250
+ r = r * 10u + static_cast<unsigned>(*p - Ch('0'));
251
+ }
252
+ return r;
253
+ }
254
+
255
+ // Assume a * b + k < 2^128
256
+ static uint64_t MulAdd64(uint64_t a, uint64_t b, uint64_t k, uint64_t* outHigh) {
257
+ #if defined(_MSC_VER) && defined(_M_AMD64)
258
+ uint64_t low = _umul128(a, b, outHigh) + k;
259
+ if (low < k)
260
+ (*outHigh)++;
261
+ return low;
262
+ #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
263
+ __extension__ typedef unsigned __int128 uint128;
264
+ uint128 p = static_cast<uint128>(a) * static_cast<uint128>(b);
265
+ p += k;
266
+ *outHigh = static_cast<uint64_t>(p >> 64);
267
+ return static_cast<uint64_t>(p);
268
+ #else
269
+ const uint64_t a0 = a & 0xFFFFFFFF, a1 = a >> 32, b0 = b & 0xFFFFFFFF, b1 = b >> 32;
270
+ uint64_t x0 = a0 * b0, x1 = a0 * b1, x2 = a1 * b0, x3 = a1 * b1;
271
+ x1 += (x0 >> 32); // can't give carry
272
+ x1 += x2;
273
+ if (x1 < x2)
274
+ x3 += (static_cast<uint64_t>(1) << 32);
275
+ uint64_t lo = (x1 << 32) + (x0 & 0xFFFFFFFF);
276
+ uint64_t hi = x3 + (x1 >> 32);
277
+
278
+ lo += k;
279
+ if (lo < k)
280
+ hi++;
281
+ *outHigh = hi;
282
+ return lo;
283
+ #endif
284
+ }
285
+
286
+ static const size_t kBitCount = 3328; // 64bit * 54 > 10^1000
287
+ static const size_t kCapacity = kBitCount / sizeof(Type);
288
+ static const size_t kTypeBit = sizeof(Type) * 8;
289
+
290
+ Type digits_[kCapacity];
291
+ size_t count_;
292
+ };
293
+
294
+ } // namespace internal
295
+ RAPIDJSON_NAMESPACE_END
296
+
297
+ #endif // RAPIDJSON_BIGINTEGER_H_
@@ -0,0 +1,71 @@
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.
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_CLZLL_H_
16
+ #define RAPIDJSON_CLZLL_H_
17
+
18
+ #include "../rapidjson.h"
19
+
20
+ #if defined(_MSC_VER) && !defined(UNDER_CE)
21
+ #include <intrin.h>
22
+ #if defined(_WIN64)
23
+ #pragma intrinsic(_BitScanReverse64)
24
+ #else
25
+ #pragma intrinsic(_BitScanReverse)
26
+ #endif
27
+ #endif
28
+
29
+ RAPIDJSON_NAMESPACE_BEGIN
30
+ namespace internal {
31
+
32
+ inline uint32_t clzll(uint64_t x) {
33
+ // Passing 0 to __builtin_clzll is UB in GCC and results in an
34
+ // infinite loop in the software implementation.
35
+ RAPIDJSON_ASSERT(x != 0);
36
+
37
+ #if defined(_MSC_VER) && !defined(UNDER_CE)
38
+ unsigned long r = 0;
39
+ #if defined(_WIN64)
40
+ _BitScanReverse64(&r, x);
41
+ #else
42
+ // Scan the high 32 bits.
43
+ if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32)))
44
+ return 63 - (r + 32);
45
+
46
+ // Scan the low 32 bits.
47
+ _BitScanReverse(&r, static_cast<uint32_t>(x & 0xFFFFFFFF));
48
+ #endif // _WIN64
49
+
50
+ return 63 - r;
51
+ #elif (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll)
52
+ // __builtin_clzll wrapper
53
+ return static_cast<uint32_t>(__builtin_clzll(x));
54
+ #else
55
+ // naive version
56
+ uint32_t r = 0;
57
+ while (!(x & (static_cast<uint64_t>(1) << 63))) {
58
+ x <<= 1;
59
+ ++r;
60
+ }
61
+
62
+ return r;
63
+ #endif // _MSC_VER
64
+ }
65
+
66
+ #define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll
67
+
68
+ } // namespace internal
69
+ RAPIDJSON_NAMESPACE_END
70
+
71
+ #endif // RAPIDJSON_CLZLL_H_