95 Commits

Author SHA1 Message Date
Milo Yip
5a186104f4 Fixes warnings 2014-07-03 00:59:35 +08:00
Milo Yip
10924e389c Fixes parsing small floating point values underflow
https://code.google.com/p/rapidjson/issues/detail?id=75

The modification is slightly different from dlbattle123 to improve
speed.
2014-06-30 21:26:43 +08:00
miloyip
a9356c09c0 Fixes IBM XL C/C++ for AIX issue
Move rapidjson::GenericValue::Member to rapidjson::GenericMember

https://code.google.com/p/rapidjson/issues/detail?id=64
2014-06-30 19:07:58 +08:00
miloyip
a1ce06a187 Fixes vs2010 warning about INT64_C() 2014-06-30 10:18:14 +08:00
miloyip
389fe87cd8 Merge branch 'master' into issue23errorcode
Conflicts:
	example/condense/condense.cpp
	include/rapidjson/reader.h
	test/unittest/readertest.cpp
2014-06-30 09:44:24 +08:00
Milo Yip
8e76a9dcce Fixes compilation error
need ‘typename’ before
‘rapidjson::StreamTraits<InputStream>::StreamCopyType
2014-06-29 21:24:15 +08:00
Milo Yip
789761ae1b Fixes compilation error
‘>>’ should be ‘> >’ within a nested template argument list
2014-06-29 21:18:31 +08:00
Milo Yip
bcf7cee788 Add stream copying optimization switch depending stream type.
An unit test is added
2014-06-29 20:59:01 +08:00
Milo Yip
1d14748bc9 Added overloaded functions for default parseFlags
Can write d.Parse(...) instead of d.Parse<0>(...)
Hope to reduce strangeness and confusion for beginner.
2014-06-29 15:03:38 +08:00
Milo Yip
c14c5ff236 Documentation on error related files and include dependent header. 2014-06-27 22:43:21 +08:00
Milo Yip
69ca7487bc Manually merge the segfault fix from main branch and fix several unit tests about error code 2014-06-27 22:27:18 +08:00
Milo Yip
b0059483c8 Error can only be assigned once 2014-06-27 22:13:02 +08:00
Philipp A. Hartmann
0277ebdc3c document.h: avoid casting away const
Another instance of casting away constness via C-style cast
has been missed (introduced by #20).
2014-06-27 10:27:35 +02:00
Philipp A. Hartmann
be01d3d7cc fix build on travis-ci.org
Some early returns were missing after the removal of longjmp in #22.
This has led to segfaults on Linux (confirmed locally).
2014-06-27 10:26:37 +02:00
Milo Yip
b4df717675 Fixes grammar mistakes in error messages. 2014-06-27 16:13:54 +08:00
Milo Yip
3693d61f5a Add parse error codes and API for converting error code to text.
Parse errors is represented as enum type `ParseErrorCode`.
Error texts are optional for user.
Added  `GetParseError_En()` in `error/en.h`, user can localize this file
into other files. User may dynamically change the locale in runtime.
2014-06-27 01:53:56 +08:00
Milo Yip
813eaf4e03 Merge pull request #25 from miloyip/issue22setjmp
Removal of setjmp()/longjmp()
2014-06-26 23:48:29 +08:00
Milo Yip
a1a8abd0d9 Add safe checks in parsing compound types.
Compound types (object and array) call ParseString() and ParseValue()
for key and values. If there is parse errors inside those calls, it
should stop continue parsing. Otherwise, it may be possible to continue
parsing and calling handler incorrectly.
For example, in ["a\u,","b"], \u generates an error (it should follow
but 4 hex digits), the parser continues to treat the first comma as
element separator, and treat "," as a JSON string and call the handler.
It may be unacceptable in the application code.
2014-06-26 23:35:13 +08:00
Milo Yip
3d9dd745a1 Remove setjmp header and jmpbuf member variable 2014-06-26 23:24:16 +08:00
Milo Yip
188b99b471 Clear the stack after parsing and fixes indentation. 2014-06-26 23:14:05 +08:00
Milo Yip
74a24377a8 Remove setjmp()/longjmp() 2014-06-26 22:31:54 +08:00
Philipp A. Hartmann
cc8833506c document.h: define __STDC_CONSTANT_MACROS
The C++ standard does not include the C99 macros used to set the (U)INT64
constants in document.h and reader.h (see adf66292 and ce1fece2).

Many implementations include their definition when the
__STDC_CONSTANT_MACROS preprocessor symbol is defined.

See e.g. http://www.cprogramdevelop.com/5272623/,
needed to successfully build in travis-ci.org's environment.
2014-06-26 16:06:15 +02:00
Milo Yip
d5add05c9a Merge pull request #19 from pah/feature/double-precision
User-defined double output precision
2014-06-26 10:33:24 +08:00
Philipp A. Hartmann
8bde3be116 GenericValue: add copy constructor and CopyFrom
To allow deep copying from an existing GenericValue, an
explicit "copy constructor" (with required Allocator param)
and an "CopyFrom" assignment function are added.

  Document d; Document::AllocatorType& a = d.GetAllocator();
  Value v1("foo");
  // Value v2(v1); // not allowed

  Value v2(v1,a);                             // make a copy
  RAPIDJSON_ASSERT(v1.IsString());            // v1 untouched
  d.SetArray().PushBack(v1,a).PushBack(v2,a);
  RAPIDJSON_ASSERT(v1.Empty() && v2.Empty());

  v2.CopyFrom(d,a);                           // copy whole document
  RAPIDJSON_ASSERT(d.IsArray() && d.Size());  // d untouched
  v1.SetObject().AddMember( "array", v2, a );
  d.PushBack(v1,a);

Additionally, the Handler implementation in GenericDocument is made
private again, restricting access to GenericReader and GenericValue.
2014-06-25 18:09:26 +02:00
Philipp A. Hartmann
a0e5e68fdb GenericDocument::Accept: deep-copy strings, if needed
Instead of always just shallowly referencing the potentially allocated
strings when calling the Handler::String function, request a copy in
case the string has been allocated from an Allocator before.

This is necessary to avoid double free()s of the string memory,
especially when using the Handler to create a deep copy of a Value.

The explicit comparison against '0' is done to suppress the warning
C4800 on MSVC, see pah/rapidjson#5.
2014-06-25 18:09:26 +02:00
Philipp A. Hartmann
c9c2d06b9b Writer: add Double(d,precision) for one-shot double output
As proposed in other patches, it is convenient to pass a user-defined
precision for the (programmatic) output of a single double value
to an OutputStream.

This patch adds an additional overload with an explicit precision
argument to the (Pretty)Writer class templates.
2014-06-25 18:09:16 +02:00
Philipp A. Hartmann
0ccc51fbae Writer: add SetDoublePrecision to control number of significant digits
Writing a double to an OutputStream current prints at most 6 significant
digits (according to the C standard).

The function SetDoublePrecision(), added to the Writer classes
can be used to fluently set the precision, i.e. the number of
significant digits to use for writing the double:

  Writer<...> writer(...);
  d.Accept(writer.SetDoublePrecision(12));
2014-06-25 18:09:16 +02:00
Milo Yip
60b8c11909 Merge branch 'master' of https://github.com/miloyip/rapidjson 2014-06-25 23:57:04 +08:00
Milo Yip
ce1fece245 Use thirdparty stdint.h for Visual Studio 2014-06-25 23:40:12 +08:00
Milo Yip
f1a2c28ac7 Merge pull request #14 from pah/fixes/misc
some minor fixes
2014-06-25 23:23:12 +08:00
Milo Yip
a56a051737 Merge pull request #13 from pah/fixes/107
GenericDocument::ParseStream: make SourceEncoding optional
2014-06-25 23:23:00 +08:00
Milo Yip
87770399a1 Merge pull request #12 from pah/fixes/72
GenericDocument: forward allocator to GenericReader
2014-06-25 23:22:47 +08:00
Milo Yip
9b92a9781b Merge pull request #11 from pah/fixes/70
GenericValue: explicit constructors
2014-06-25 23:22:00 +08:00
Milo Yip
fc80636c6d Merge pull request #10 from pah/fixes/57
GenericValue: fixup construction from NumberType
2014-06-25 23:20:49 +08:00
Milo Yip
609381fc2e Fixed some clang -Weverything warnings. 2014-06-25 23:14:32 +08:00
Milo Yip
adf6629223 Fixed VC which doesn't have INT64_C()/UINT64_C macros. 2014-06-25 22:38:18 +08:00
Milo Yip
208d2bd7a8 Separate the RAPIDJSON_FORCEINLINE from RAPIDJSON_NO_INT64DEFINE 2014-06-25 22:30:21 +08:00
Philipp A. Hartmann
16029e6b33 FileStream: avoid warning about missing initialisation
FileStream::current_ is now explicitly initialized in the constructor.
Avoids reading the garbage value in case of an empty file.
2014-06-25 13:57:04 +02:00
Philipp A. Hartmann
4b32a30593 MemoryPoolAllocator: prohibit copying and assignment
The MemoryPoolAllocator implementation cannot and should not be
copied (Rule of Three).  Declare copy constructor and copy-assignment
operator as private.
2014-06-25 13:57:04 +02:00
Philipp A. Hartmann
72de00f672 GenericValue/GenericDocument: fix alloctaor/Alloactor typos
This patch fixes some misspellings of "allocator" in document.h.
Fixes the Doxygen documentation of GenericDocument as well.
2014-06-25 13:57:04 +02:00
Philipp A. Hartmann
7fb82c2528 GenericDocument::ParseStream: make SourceEncoding optional
The ParseStream() function current requires explicitly passing
the SourceEncoding parameter as explicit template argument
while the other Parse*() functions provide overloads to omit
this parameter and use the document's own encoding by default.

This patch adds the corresponding overload for ParseStream(),
enabling the simple usage again:

  rapidjson::FileStream is(fp);
  rapidjson::Document   d;
  d.ParseStream<0>(is);
2014-06-25 13:56:07 +02:00
Philipp A. Hartmann
37b3acf40c GenericDocument: forward allocator to GenericReader
Fixes http://code.google.com/p/rapidjson/issues/detail?id=72.
2014-06-25 13:56:06 +02:00
Philipp A. Hartmann
e1a97561ba GenericValue: explicit constructors
In case of overloaded functions taking either a GenericValue or another
class that can also be constructed from the same primitive types
(e.g. std::string, which can be constructed from const char*), the
overloading becomes ambiguous:

  void foo( const std::string& );
  void foo( const rapidjson::Value & );

Declaring the GenericValue constructors taking primitive types as
'explicit' avoids this problem.  This should not have any negative
side-effects, since a GenericValue can't be copied or implicitly
converted to other types.

Fixes http://code.google.com/p/rapidjson/issues/detail?id=70.
2014-06-25 13:56:06 +02:00
Philipp A. Hartmann
d4ff956b2d GenericValue: fixup construction from NumberType
Constructing an empty GenericValue with a specific Type has failed
for any kNumberType (Int, Int64, Double...) due to incomplete definition
of the corresponding default flag value.

This patch adds a new constant kNumberAnyFlag to the flags enumeration
in GenericValue to cover this case.

This fixes http://code.google.com/p/rapidjson/issues/detail?id=57
2014-06-25 13:56:06 +02:00
Milo Yip
be8433737f Fixed some clang -Weverything warnings. 2014-06-25 19:21:17 +08:00
Milo Yip
f930d9e2e5 Revert "Remove some clang -Weverything warnings."
This reverts commit e4ffa48a7563e892047c27f0a50fdeb6f71e6b8b.
2014-06-25 16:07:44 +08:00
Milo Yip
7ab36cf1a8 Revert "Merge branch 'master' into dev"
This reverts commit d4cb506d4b3c29dba1b4f27fa109b80b33bd6d1b, reversing
changes made to dfe201e3c1e9f184a3967719dbb0e59ef12ed54b.
2014-06-25 16:06:45 +08:00
Milo Yip
d4cb506d4b Merge branch 'master' into dev 2014-06-25 16:06:05 +08:00
Milo Yip
e4ffa48a75 Remove some clang -Weverything warnings. 2014-06-25 16:06:00 +08:00
Milo Yip
dfe201e3c1 Revert "Adds GenericDocument::ParseStream() overload to make SourceEncoding optional"
This reverts commit 84f64ba58a73a0898ad78ea239323942b63c6d51.
2014-06-25 01:06:04 +08:00