675 Commits

Author SHA1 Message Date
Aaron Jacobs
9fa4e849a1 Ran clang-format over all .h and .cpp files.
clang-format -i $(find . -name '*.h' -or -name '*.cpp')
2014-07-01 08:48:54 +10:00
Christopher Dunn
6764059395 fix stdexcept
https://sourceforge.net/p/jsoncpp/bugs/68/
2014-05-13 09:49:25 +00:00
Aaron Jacobs
5d32295a6e Fixed a test that causes a crash when exceptions are disabled.
While I was at it, corrected whitespace too.
2014-04-23 23:57:59 +00:00
Aaron Jacobs
68db655347 Added structured error reporting to Reader.
This allows applications for interactively viewing or editing JSON to do
a better job of highlighting errors. Also added offset accessors to
Value, offering the same sort of functionality even for non-errors.

Thanks to Zach Clifford (zacharyc@google.com) for the patch.
2014-04-23 23:41:12 +00:00
Aaron Jacobs
642befc836 Added features that allow the reader to accept common non-standard JSON.
This is a version of patch #17, from Clay Wood:

    http://sourceforge.net/p/jsoncpp/patches/17/
2014-04-23 23:28:23 +00:00
Christopher Dunn
77cd83890d vim modeline
http://vim.wikia.com/wiki/Modeline_magic
2014-04-19 21:41:03 +00:00
Christopher Dunn
09439b7bc7 Comment reading/write improvements
This patch fixes some aspects of reading and writing comments:
- Multiple C++-style comments before a Json value had extra newlines appended to them. This patch removes the addition of those newlines.
- Comments written before Json values in the StyledWriter were not indented to match the indentation level of the value. This patch adds indentation to comments.
- Fixed inconsistency in newlines following C- and C++-style comments being saved as part of the comment. All newlines at the end of a comment are now removed.
- Added an additional test of comments.

https://sourceforge.net/p/jsoncpp/patches/25/
2014-04-19 21:19:24 +00:00
Christopher Dunn
ea0797351f JSON_ASSERT -> JSON_ASSERT_MESSAGE
This way, assertions can produce exceptions.
https://sourceforge.net/p/jsoncpp/bugs/67/
2014-04-19 06:37:23 +00:00
Aaron Jacobs
94d17e9fdf Added missing includes for std::istream.
Thanks to Quentin Fiard for the report.
2014-01-29 00:13:38 +00:00
Baptiste Lepilleur
a3f19c23a0 Fixed broken build on VS 2012 2013-09-23 14:10:39 +00:00
Aaron Jacobs
d2618806ba Fixed some snprintf-related build breakages in Visual Studio. 2013-08-08 23:08:28 +00:00
Aaron Jacobs
36400ac0c1 Updated two calls to sprintf that I missed in r269. 2013-08-08 00:39:32 +00:00
Aaron Jacobs
32ffb931e7 Replaced the complex implementation of valueToString(double).
The previous one was confusing and prone to buffer overflows, and didn't
work correctly with 16-decimal-digit numbers. The new one simply uses
snprintf with a standard format string.

The major change is that we don't always print a decimal point now.
Fortunately, JSON doesn't distinguish between integers and reals.
2013-08-08 00:39:12 +00:00
Aaron Jacobs
bb53cd0899 Added more floating point tests.
The first demonstrates a bug that I will soon fix.
2013-08-08 00:37:39 +00:00
Aaron Jacobs
4c531bb584 Added further floating point tests. 2013-08-08 00:13:10 +00:00
Aaron Jacobs
42d918b7aa Switched away from sprintf, which is prone to buffer overflows.
Most reasonable platforms have this function. If you're here because
this broke the build for you, consider adding an ifdef for your platform
and using sprintf there (but not on other platforms).
2013-08-06 23:12:56 +00:00
Baptiste Lepilleur
700b38020e - CMake: added option to turn fail compilation if warning occurs, and warning level 4 with MSVC.
- Fixed some warnings
2013-05-09 18:42:33 +00:00
Baptiste Lepilleur
58b6541478 Added missing source file to CMakeLists.txt. 2013-05-09 15:21:06 +00:00
Baptiste Lepilleur
eafd702a17 - New CMake based build system. Based in part on contribution from
Igor Okulist and Damien Buhl (Patch #14). Added support for running
tests and building with DLL on Windows.
- added missing JSON_API
- Visual Studio DLL: suppressed warning "C4251: <data member>: <type> 
needs to have dll-interface to be used by..." via pragma push/pop
in json-cpp headers.
- New header json/version.h now contains version number macros
(JSONCPP_VERSION_MAJOR, JSONCPP_VERSION_MINOR, JSONCPP_VERSION_PATCH
and JSONCPP_VERSION_HEXA). While this header is generated by CMake,
it is committed to ease build with alternate build system 
(CMake only update the file when it changes avoid issues with VCS).
2013-05-08 20:21:11 +00:00
Baptiste Lepilleur
f92ace5e82 Patch #3600941: Missing field copy in Json::Value::iterator causing infinite loop when using experimental internal map (#define JSON_VALUE_USE_INTERNAL_MAP) (contributed by Ming-Lin Kao). 2013-04-12 13:26:23 +00:00
Baptiste Lepilleur
3f124172ce Patch #3539678: Copy constructor does not initialize allocated_ for stringValue (contributed by rmongia). 2013-04-12 13:11:14 +00:00
Baptiste Lepilleur
f8715856f3 Fix gcc -Wall warnings (patch from Matt McCormick) 2013-02-18 15:53:47 +00:00
Baptiste Lepilleur
42321f24a6 Fixed warning(error?) on #if testing value of _MSC_VER without checking that it was defined. 2012-12-20 10:08:50 +00:00
Aaron Jacobs
ae3c7a7aab Made it possible to drop null placeholders from array output.
This can be used when it's clear that the consumer is able to deal with
this, as web browsers are. Thanks to Yatin Chawathe for the patch.
2012-03-12 04:53:57 +00:00
Aaron Jacobs
2b853c4067 Got rid of several unnecessary includes of <iostream>.
Including <iostream> causes the file to be polluted with a static
initializer for the __ioinit symbol. This can harm binary startup time.
For more info, see here:

    http://neugierig.org/software/chromium/notes/2011/08/static-initializers.html
2011-12-22 03:18:24 +00:00
Christopher Dunn
3b3540d9ef bug#2407932: strpbrk() could fail for NULL pointer. 2011-06-22 21:04:41 +00:00
Christopher Dunn
9d317c3794 bug#3306345: minor typo in Path::resolve() -- missing bang. 2011-06-22 08:30:21 +00:00
Christopher Dunn
c9f91dd929 More missing constructor initializers found by Coverity. 2011-06-21 23:02:06 +00:00
Christopher Dunn
2ba3bc3252 Another simple addition for constructor initialization, PathArgument. 2011-06-21 22:08:49 +00:00
Christopher Dunn
ac5df77bbc Simple changes to Reader initialization, from Chromium folks. (I do not think this was submitted as a bug.) 2011-06-21 21:56:54 +00:00
Baptiste Lepilleur
d496e044b1 Fixed unit tests execution on MSVC 6 by removing usage of std::numeric_limits. It was returning 0 value in some max cases. Fixed Value::asFloat() to use integerToDouble(). 2011-05-27 08:12:41 +00:00
Baptiste Lepilleur
f587e6a420 Fixed compilation issues with MSVC 6: replace usage of ostringstream with valueToString to support 64 bits integer and high precision floating point conversion to string. Replace usage of ULL and LL literal with UInt64(expr) and Int64(expr). Introduced helper function uint64ToDouble() to work-around missing conversion. Unit tests do not pass yet. 2011-05-26 22:55:24 +00:00
Baptiste Lepilleur
f0b24e705f Fixed MSVS 2003, 2005 and 2008 tests execution by normalizing floating-point string representation using helper normalizeFloatingPointStr(). 2011-05-26 20:14:32 +00:00
Baptiste Lepilleur
e807a7640e Fixed unit test failure on IBM AIX xlC by hard-coding the maxUInt64AsDouble as double constant instead of relying on double(Value::maxUInt64) which produces an incorrect value. 2011-05-26 17:14:26 +00:00
Baptiste Lepilleur
d3cd9a7fc5 - Fixed unit test compilation on MSVS 2003, 2005 and 2008.
- Worked-around unit test failure with MSVS* by "forcing" all floating-point numbers to be loaded from memory instead of FPU registers.
2011-05-26 07:32:36 +00:00
Aaron Jacobs
a2fb7fb918 Fixed some test bugs that show up when 64-bit mode is disabled. 2011-05-26 06:58:52 +00:00
Aaron Jacobs
c649badb95 Another round of attempting to fix VC++ errors... 2011-05-26 03:44:02 +00:00
Aaron Jacobs
a9eb1eccc0 Fixed more default cases. 2011-05-26 03:32:11 +00:00
Aaron Jacobs
6ffff91c54 Got rid of some unreachable code. 2011-05-26 03:27:44 +00:00
Aaron Jacobs
acdefb0869 Fixed a double -> float compilation warning/error. 2011-05-26 03:04:01 +00:00
Aaron Jacobs
c025697ea5 Reworked the type conversion system again, so that:A
*  isFoo methods determine exact representability.
 *  asFoo methods cause casting when safe.
 *  isConvertibleTo indicates whether casting is safe.

See NEWS.txt for details.
2011-05-26 02:46:28 +00:00
Aaron Jacobs
b0ec41c3e3 Made the unit test's output more readable, adding to jsontest's
capabilities (and simplifying its implementation) in the process.
2011-05-26 00:30:39 +00:00
Aaron Jacobs
2a2b5cf3ad Made jsontest work with 64-bit integers, and fixed an error. 2011-05-26 00:12:48 +00:00
Aaron Jacobs
b6620e2801 Removed some out of date TODOs. 2011-05-25 23:26:58 +00:00
Aaron Jacobs
ccde848fd1 Fixed test failures with 64-bit support disabled. 2011-05-25 05:53:59 +00:00
Aaron Jacobs
e082248001 Fixed a 'comparison between signed and unsigned' error. 2011-05-25 05:50:13 +00:00
Aaron Jacobs
e91a68cb9e Fixed a compilation warning/error. 2011-05-25 04:34:57 +00:00
Aaron Jacobs
1b138e8544 Gave a more consistent behavior to the Value::isFoo methods. See
NEWS.txt for more details.
2011-05-25 04:19:17 +00:00
Aaron Jacobs
4f081b50e6 Fixed bugs in asInt64 and asUInt64. 2011-05-25 03:16:49 +00:00
Aaron Jacobs
3c9fdeb859 Added tests for default numeric values. 2011-05-25 02:54:11 +00:00
Aaron Jacobs
4b79fd1a00 Fixed a test bug. 2011-05-25 01:51:30 +00:00
Aaron Jacobs
e12d84ebaa Made tests more comprehensive. 2011-05-25 01:46:50 +00:00
Aaron Jacobs
078e0d7c37 Gave tests more general names in preparation for making them much more
comprehensive.
2011-05-25 01:24:23 +00:00
Aaron Jacobs
fee49b1a37 Fixed some whitespace. 2011-05-25 01:23:47 +00:00
Aaron Jacobs
22eede44c1 Added tests for 64-bit integers. 2011-05-25 01:23:08 +00:00
Aaron Jacobs
d9ec234fc2 Greatly fleshed out numeric type tests. 2011-05-25 01:04:07 +00:00
Aaron Jacobs
3e5b347f75 Added some missing checks. 2011-05-25 01:03:29 +00:00
Aaron Jacobs
96408a30e1 Renamed test cases to make more sense with the upcoming new behavior of
isFoo methods.
2011-05-25 00:39:55 +00:00
Aaron Jacobs
1d648f089a Fixed a whitespace problem. 2011-05-25 00:39:17 +00:00
Aaron Jacobs
f40c880585 Fixed a "comparison between signed and unsigned" warning/error. 2011-05-24 23:08:59 +00:00
Aaron Jacobs
ae9ffb5443 Fixed a parsing bug in decodeNumber, updating the failing test cases to be
correct in the process. (The test cases incorrectly used exact integers instead
of scientific notation.)
2011-05-24 03:59:24 +00:00
Aaron Jacobs
f1053e7acb Fixed a bunch of compilation errors when JSON_HAS_INT64 is set. 2011-05-24 03:18:02 +00:00
Aaron Jacobs
e3d0eca9f4 Centralized assertion macros and made them obey JSON_USE_EXCEPTION. 2011-05-24 01:03:22 +00:00
Aaron Jacobs
a77a803c85 Made two security fixes. 2011-05-24 00:43:59 +00:00
Aaron Jacobs
785ba2675d Updated a cast to use a more appropriate type. 2011-05-24 00:43:30 +00:00
Aaron Jacobs
3b556ec633 Fixed constructor initializer list order warnings/errors. 2011-05-24 00:42:58 +00:00
Aaron Jacobs
5fb0f09cbb Removed an unused typedef. 2011-05-24 00:42:15 +00:00
Aaron Jacobs
73911f2e33 Fixed a hard to debug crash on OS X related to sscanf format strings.
See here for more info:
    http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html
2011-05-24 00:41:12 +00:00
Baptiste Lepilleur
eadc478e50 Fixed typo: amalga*ma*te. Replaced macro JSON_IS_AMALGATED with JSON_IS_AMALGAMATION 2011-05-02 21:09:30 +00:00
Baptiste Lepilleur
1837a1c508 Value::compare() is now const and has an actual implementation with unit tests. 2011-05-02 20:11:48 +00:00
Baptiste Lepilleur
e3cc0f004b Untabified some sources 2011-05-02 18:41:01 +00:00
Baptiste Lepilleur
fb17080142 - Added unit tests for comparison operators (except compare())
- Fixed Value::operator <= implementation (had the semantic of operator >=). Found when addigin unit tests for comparison operators.
2011-05-02 16:53:10 +00:00
Baptiste Lepilleur
e0e1fd37cd - Bug #3200841: removed "warning C4127: conditional expression is constant" concerning infinite loop by replacing while (true) with for (;;). Added new JSON_FAIL macro. Commented unused parameters. 2011-05-02 16:51:48 +00:00
Baptiste Lepilleur
d0a9f3d98d Bug #3200841: removed "warning C4127: conditional expression is constant" concerning infinite loop by replacing while (true) with for (;;). 2011-05-02 09:54:49 +00:00
Baptiste Lepilleur
64e40aafe5 Added support for amalgated source and header generation (a la sqlite). Refer to README.txt section "Generating amalgated source and header" for detail.
The amalgated sources are generated by concatenating JsonCpp source in the correct order and defining macro JSON_IS_AMALGATED to prevent inclusion of other headers. Sources and header has been modified to prevent any inclusion when this macro is defined.

The script amalgate.py handle the generation.
2011-05-01 20:13:40 +00:00
Baptiste Lepilleur
b2e8cccbc6 Renamed Reader::getFormatedErrorMessages() to getFormattedErrorMessages. Bug #3023708 (Formatted has 2 't'). The old member function is deprecated but still present for backward compatibility. 2011-05-01 16:27:55 +00:00
Baptiste Lepilleur
99043b32b5 Fixed bug #3139678: stack buffer overflow when parsing a double with a length of 32 characters. 2011-05-01 15:47:38 +00:00
Baptiste Lepilleur
9c98f2277b Fixed bug #3139677: JSON [1 2 3] was incorrectly parsed as [1, 3]. Error is now correctly detected.
Modified runjsontests.py to allow test that expect failure in jsoncpp test suite.
2011-05-01 15:40:47 +00:00
Baptiste Lepilleur
842e9ac54b Major rework of 64 integer support: 64 bits integer are only returned when explicitly request via Json::Value::asInt64(), unlike previous implementation where Json::Value::asInt() returned a 64 bits integer.
This eases porting portable code and does not break compatibility with the previous release.

Json::Value::asLargestInt() has also be added to ease writing portable code independent of 64 bits integer support. It is typically used to implement writers.
2010-12-27 17:45:23 +00:00
Baptiste Lepilleur
b96aed0f3e Added float Json::Value::asFloat() to obtain a floating point value as a float (avoid lost of precision warning caused by used of asDouble() to initialize a float). 2010-12-24 19:30:06 +00:00
Baptiste Lepilleur
fa130ef871 - Array index can be passed as int to operator[], allowing use of literal:
Json::Value array;
  array.append( 1234 );
  int value = array[0].asInt();  // did not compile previously
2010-12-24 12:47:14 +00:00
Baptiste Lepilleur
7469f1d014 JsonCpp is now licensed under MIT license, or public domain if desired and recognized in your jurisdiction. 2010-04-20 21:35:19 +00:00
Baptiste Lepilleur
201fb2cf0d - Moved definition of Json::Int and Json::UInt to config.h which compiler detection logic to define them to 64 bits integer if JSON_NO_INT64 is not defined.
- Added Json::ArrayIndex as an unsigned int to forwards.h
- Modified Json::Value to consistently use Json::ArrayIndex.
- Added int/unsigned int constructor overload to Json::Value to avoid ambiguous constructor call.
- Modified jsontestrunner/main.cpp to use Json::valueToString for Value::asInt() conversion to string.
- Modified Json::Reader to only overflow to double when the number is too large (previous code relied on the fact that an int fitted in a double without precision loss).
- Generalized uintToString() helpers and buffer size to automatically adapt to the precision of Json::UInt.
- Added specific conversion logic for UInt to double conversion on Microsoft Visual Studio 6 which only support __int64 to double conversion (unsigned __int64 conversion is not supported)
- Added test for 64 bits parsing/writing. Notes: those will fail when compiled with JSON_NO_INT64 (more dev required to adapt).
2010-04-19 07:37:41 +00:00
Baptiste Lepilleur
afd9cef928 Removed experimental ValueAllocator, it caused static initialization/destruction order issues (bug #2934500). The DefaultValueAllocator has been inlined in code. 2010-03-13 13:10:27 +00:00
Baptiste Lepilleur
d38ba2a2cb - extracted some utility functions out-of reader and parser. 2010-03-13 12:24:38 +00:00
Baptiste Lepilleur
fcf145ecd4 - changed SVN EOL properties so that HTML file are in Unix format, Visual Studio solution are always in Windows format, and sources are in native format. 2010-02-23 08:23:41 +00:00
Baptiste Lepilleur
8d3790d217 - added missing virtual destructor to TestCase. 2010-02-21 14:28:54 +00:00
Baptiste Lepilleur
3a1b93be1c - added Int/UInt typedef in Json namespace. Modified Value::Int and Value::UInt to be typedef on those. Modified code to use Json::Int instead of Value::Int.
- added Value constructor taking begin/end pointer to initialize the Value with a non-zero terminated string.
2010-02-21 14:08:17 +00:00
Baptiste Lepilleur
4a5e58c4f4 Integrated part of Patch #2839016, fixing default iterator initialization when using internal map. 2010-01-15 14:56:59 +00:00
Baptiste Lepilleur
56c0401a90 Fixed compilation with Sun Studio 12 (avoid usage of std::distance) 2009-11-24 17:43:58 +00:00
Baptiste Lepilleur
a1d6c9e66a Fixed iteration bug over null values. 2009-11-23 22:33:30 +00:00
Baptiste Lepilleur
45c499d310 - added mini unit testing framework
- added unit tests for Value.isXYZ() and iteration over Value members to compute size
2009-11-21 18:07:09 +00:00
Baptiste Lepilleur
f73d4b9a6b Fixed compilation issue with vs2005 2009-11-19 19:13:18 +00:00
Baptiste Lepilleur
2a787ec8e6 Moved Visual Studio projects file under makefiles/vs71 to allow usage of multiple versions on the same source tree. 2009-11-19 13:29:25 +00:00
Baptiste Lepilleur
f179a180bd Fixed comment after value in object value signaled by Frederic Surleau. 2009-11-18 22:25:34 +00:00
Baptiste Lepilleur
8868147835 - added Features class that describes allowed extension for Reader, to allow for strict configuration
- added tests from json.org jsonchecker and modified jsontestrunner to use strict parsing mode when executing them
2009-11-18 21:38:54 +00:00
Malay Shah
617270bfaa Fixing string index issue when checking for control characters 2009-11-18 17:40:22 +00:00
Baptiste Lepilleur
5d0ed235c6 Fixed default constructor initialization. 2009-11-18 17:12:24 +00:00
Baptiste Lepilleur
eda47b61b5 Fixed bug introduced by utf-8 patch with fix provided by Henry Ludemann. All unit tests are now passing. 2009-11-18 17:01:09 +00:00
Baptiste Lepilleur
b0ab79bc5b Added patch for mingw from Sebastien Vincent 2009-11-15 22:49:54 +00:00
Malay Shah
ee4b4dab54 Implementing support for reading and writing Unicode escape sequences. 2009-11-13 04:21:14 +00:00
Christopher Dunn
8f5ddcfa8d Added cstring for memcpy(), as suggested by sebastien.vincent@turnserver.org . This allows gcc-4 to compile. Removed doxygen from SConstruct, since it is now broken; I have been unable to get it to work with either scons 0.97 or scons 2.1; hopefully someone else can get that working again. 2009-05-11 20:04:10 +00:00
Christopher Dunn
2083c9e3bf Forgot to add # to %g modifier for sprintf in valueToString for floats. Otherwise no decimal point appears when only zeroes would follow, which changes the type to integer. 2008-01-24 20:21:11 +00:00
Christopher Dunn
ed971e180e Changed valueToString for floats so that zeroes after a decimal are truncated -- saves file size esp. for StyledStreamWriter which uses tabs instead of spaces. 2008-01-24 20:09:48 +00:00
Baptiste Lepilleur
e1aad35ae5 Fixed compilation issue on windows (avoid using cstring and use string.h instead). 2008-01-20 16:55:26 +00:00
Christopher Dunn
e1f8a4799a added dependency 2007-06-14 22:01:40 +00:00
Christopher Dunn
f986423955 Stripped carriage return and added eol-style native prop. 2007-06-14 21:01:26 +00:00
Christopher Dunn
9f8abcb258 Indentation is not perfect, but pretty good. Not sure how to perfect, given the difficulty of testing the last char written. 2007-06-13 17:02:01 +00:00
Christopher Dunn
605cd7e902 Added StyledStreamWriter, which has no reason to derive from Writer, since its write() method does cannot return a string and must take a stream. 2007-06-13 15:55:50 +00:00
Christopher Dunn
b2f720456e Added prop svn:eol-style native. Stripped carriage-returns on unix. Hopefully, this will work for Windows too now. 2007-06-13 15:48:30 +00:00
Christopher Dunn
a44cffb342 Fixed compilation warnings. Added -Wall to linux-gcc compilation. JSON_ASSERT_MESSAGE now throws exception (but JSON_ASSERT does not). 2007-05-09 19:35:15 +00:00
Christopher Dunn
f153eaaed0 Fixed 2.95.3 header probs 2007-03-23 10:19:49 +00:00
Christopher Dunn
56a1d6cbf5 Added istream/ostream funcs/operators 2007-03-23 09:57:01 +00:00
Christopher Dunn
2370789d67 Renamed buildLibary to buildLibrary and added SharedLibrary rule. 2007-03-23 08:57:57 +00:00
Christopher Dunn
208a781e47 Added empty() operator-bang and isNull() 2007-03-23 08:55:25 +00:00
Christopher Dunn
1aa20f9e58 Added removeMember() and altered a few comments. 2007-03-23 08:30:20 +00:00
Christopher Dunn
0c498695a7 fixed compiler warning 2007-03-23 07:16:59 +00:00
Christopher Dunn
ca21256395 setComment() will assert if comment does not start with / (or if it were NULL, which would have seg-faulted before). 2007-03-23 07:05:19 +00:00
Christopher Dunn
5674738668 [1611376]by reserving the max string-size when escaped chars exist, we should save some runtime. 2007-03-23 06:12:28 +00:00
Christopher Dunn
ce1f32981b [1611376]writer now escapes special characters. When no special chars are present, old behavior is retained. New method might have a performance penalty b/c of operator new inside std::string. (This would not exist if the whole thing operated on ostream instead, I think.) 2007-03-23 05:56:39 +00:00
Christopher Dunn
fe536c0631 [1587188]Fixed parsing of comment at tail of object. 2007-03-23 05:04:38 +00:00
Christopher Dunn
3ffbf208a0 Fixed gcc 2.95.3 problem. Bug: 1570919 2007-03-23 04:55:07 +00:00
Christopher Dunn
baca6c23c2 Added newline b/c of gcc--warning: no newline at end of file 2007-03-23 03:31:35 +00:00
Baptiste Lepilleur
2d4dd281f1 - Made FastWriter output more compact.
- fixed bug in runjsontests.py script.
2007-03-17 22:14:59 +00:00
Baptiste Lepilleur
4cd8bae331 - reorganized repository to match standard layout 2007-03-15 22:11:38 +00:00