From b2e8cccbc6ed7561219d7770153262b5d141817b Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Sun, 1 May 2011 16:27:55 +0000 Subject: [PATCH] Renamed Reader::getFormatedErrorMessages() to getFormattedErrorMessages. Bug #3023708 (Formatted has 2 't'). The old member function is deprecated but still present for backward compatibility. --- NEWS.txt | 8 +++++++- doc/jsoncpp.dox | 2 +- include/json/config.h | 8 ++++++++ include/json/reader.h | 9 +++++++++ src/jsontestrunner/main.cpp | 2 +- src/lib_json/json_reader.cpp | 10 +++++++++- src/lib_json/json_value.cpp | 3 ++- 7 files changed, 37 insertions(+), 5 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index b53f4db..3f75156 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -64,6 +64,12 @@ float (avoid lost of precision warning caused by used of asDouble() to initialize a float). +* Reader + + - Renamed Reader::getFormatedErrorMessages() to getFormattedErrorMessages. + Bug #3023708 (Formatted has 2 't'). The old member function is deprecated + but still present for backward compatibility. + * Tests - Added test to ensure that the escape sequence "\/" is corrected handled @@ -76,7 +82,7 @@ - Bug #3139678: stack buffer overflow when parsing a double with a length of 32 characters. - + * License - See file LICENSE for details. Basically JsonCpp is now licensed under diff --git a/doc/jsoncpp.dox b/doc/jsoncpp.dox index 04fc165..97cc108 100644 --- a/doc/jsoncpp.dox +++ b/doc/jsoncpp.dox @@ -46,7 +46,7 @@ if ( !parsingSuccessful ) { // report to the user the failure and their locations in the document. std::cout << "Failed to parse configuration\n" - << reader.getFormatedErrorMessages(); + << reader.getFormattedErrorMessages(); return; } diff --git a/include/json/config.h b/include/json/config.h index 55f0583..8e69b7a 100644 --- a/include/json/config.h +++ b/include/json/config.h @@ -55,6 +55,14 @@ #define JSON_USE_INT64_DOUBLE_CONVERSION 1 #endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6 +#if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008 +/// Indicates that the following function is deprecated. +# define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) +#endif + +#if !defined(JSONCPP_DEPRECATED) +# define JSONCPP_DEPRECATED(message) +#endif // if !defined(JSONCPP_DEPRECATED) namespace Json { typedef int Int; diff --git a/include/json/reader.h b/include/json/reader.h index 62232ea..2cd94eb 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -72,9 +72,18 @@ namespace Json { * \return Formatted error message with the list of errors with their location in * the parsed document. An empty string is returned if no error occurred * during parsing. + * \deprecated Use getFormattedErrorMessages() instead (typo fix). */ + JSONCPP_DEPRECATED("Use getFormattedErrorMessages instead") std::string getFormatedErrorMessages() const; + /** \brief Returns a user friendly string that list errors in the parsed document. + * \return Formatted error message with the list of errors with their location in + * the parsed document. An empty string is returned if no error occurred + * during parsing. + */ + std::string getFormattedErrorMessages() const; + private: enum TokenType { diff --git a/src/jsontestrunner/main.cpp b/src/jsontestrunner/main.cpp index 2da3ede..dfb6150 100644 --- a/src/jsontestrunner/main.cpp +++ b/src/jsontestrunner/main.cpp @@ -105,7 +105,7 @@ parseAndSaveValueTree( const std::string &input, { printf( "Failed to parse %s file: \n%s\n", kind.c_str(), - reader.getFormatedErrorMessages().c_str() ); + reader.getFormattedErrorMessages().c_str() ); return 1; } diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 8bc75e3..0d59c46 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -839,8 +839,16 @@ Reader::getLocationLineAndColumn( Location location ) const } +// Deprecated. Preserved for backward compatibility std::string Reader::getFormatedErrorMessages() const +{ + return getFormattedErrorMessages(); +} + + +std::string +Reader::getFormattedErrorMessages() const { std::string formattedMessage; for ( Errors::const_iterator itError = errors_.begin(); @@ -862,7 +870,7 @@ std::istream& operator>>( std::istream &sin, Value &root ) Json::Reader reader; bool ok = reader.parse(sin, root, true); //JSON_ASSERT( ok ); - if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages()); + if (!ok) throw std::runtime_error(reader.getFormattedErrorMessages()); return sin; } diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 218c127..ce1dec3 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -54,6 +54,7 @@ duplicateStringValue( const char *value, if ( length == unknown ) length = (unsigned int)strlen(value); char *newString = static_cast( malloc( length + 1 ) ); + JSON_ASSERT_MESSAGE( newString != 0, "Failed to allocate string value buffer" ); memcpy( newString, value, length ); newString[length] = 0; return newString; @@ -112,7 +113,7 @@ Value::CommentInfo::setComment( const char *text ) { if ( comment_ ) releaseStringValue( comment_ ); - JSON_ASSERT( text ); + JSON_ASSERT( text != 0 ); JSON_ASSERT_MESSAGE( text[0]=='\0' || text[0]=='/', "Comments must start with /"); // It seems that /**/ style comments are acceptable as well. comment_ = duplicateStringValue( text );