diff --git a/.gitignore b/.gitignore index 4b721f0..c869151 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,6 @@ jsoncpp_lib_static.dir/ .project .cproject /.settings/ + +# DS_Store +.DS_Store diff --git a/include/json/config.h b/include/json/config.h index b2bfb29..c83e78a 100644 --- a/include/json/config.h +++ b/include/json/config.h @@ -120,6 +120,9 @@ #endif #ifdef __clang__ +# if __has_extension(attribute_deprecated_with_message) +# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) +# endif #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) # define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) diff --git a/include/json/reader.h b/include/json/reader.h index 5ee962a..82859fd 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -32,7 +32,7 @@ namespace Json { * * \deprecated Use CharReader and CharReaderBuilder. */ -class JSON_API Reader { +class JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead") JSON_API Reader { public: typedef char Char; typedef const Char* Location; @@ -230,6 +230,9 @@ private: void addComment(Location begin, Location end, CommentPlacement placement); void skipCommentTokens(Token& token); + static bool containsNewLine(Location begin, Location end); + static JSONCPP_STRING normalizeEOL(Location begin, Location end); + typedef std::stack Nodes; Nodes nodes_; Errors errors_; diff --git a/include/json/value.h b/include/json/value.h index 2da9559..ebca175 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -518,10 +518,12 @@ Json::Value obj_value(Json::objectValue); // {} /// \pre type() is objectValue or nullValue /// \post type() is unchanged /// \deprecated + JSONCPP_DEPRECATED("") Value removeMember(const char* key); /// Same as removeMember(const char*) /// \param key may contain embedded nulls. /// \deprecated + JSONCPP_DEPRECATED("") Value removeMember(const JSONCPP_STRING& key); /// Same as removeMember(const char* begin, const char* end, Value* removed), /// but 'key' is null-terminated. diff --git a/include/json/writer.h b/include/json/writer.h index 8a1279b..f258cbf 100644 --- a/include/json/writer.h +++ b/include/json/writer.h @@ -140,7 +140,7 @@ public: /** \brief Abstract class for writers. * \deprecated Use StreamWriter. (And really, this is an implementation detail.) */ -class JSON_API Writer { +class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer { public: virtual ~Writer(); @@ -156,7 +156,7 @@ public: * \sa Reader, Value * \deprecated Use StreamWriterBuilder. */ -class JSON_API FastWriter : public Writer { +class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter : public Writer { public: FastWriter(); @@ -209,7 +209,7 @@ private: * \sa Reader, Value, Value::setComment() * \deprecated Use StreamWriterBuilder. */ -class JSON_API StyledWriter : public Writer { +class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledWriter : public Writer { public: StyledWriter(); ~StyledWriter() JSONCPP_OVERRIDE {} @@ -267,12 +267,14 @@ private: * If the Value have comments then they are outputed according to their #CommentPlacement. * - * \param indentation Each level will be indented by this amount extra. * \sa Reader, Value, Value::setComment() * \deprecated Use StreamWriterBuilder. */ -class JSON_API StyledStreamWriter { +class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledStreamWriter { public: +/** + * \param indentation Each level will be indented by this amount extra. + */ StyledStreamWriter(JSONCPP_STRING indentation = "\t"); ~StyledStreamWriter() {} diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 23d732c..8850d2e 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -81,7 +81,7 @@ Features Features::strictMode() { // Implementation of class Reader // //////////////////////////////// -static bool containsNewLine(Reader::Location begin, Reader::Location end) { +bool Reader::containsNewLine(Reader::Location begin, Reader::Location end) { for (; begin < end; ++begin) if (*begin == '\n' || *begin == '\r') return true; @@ -370,7 +370,7 @@ bool Reader::readComment() { return true; } -static JSONCPP_STRING normalizeEOL(Reader::Location begin, Reader::Location end) { +JSONCPP_STRING Reader::normalizeEOL(Reader::Location begin, Reader::Location end) { JSONCPP_STRING normalized; normalized.reserve(static_cast(end - begin)); Reader::Location current = begin; @@ -1019,6 +1019,9 @@ private: void addComment(Location begin, Location end, CommentPlacement placement); void skipCommentTokens(Token& token); + static JSONCPP_STRING normalizeEOL(Location begin, Location end); + static bool containsNewLine(Location begin, Location end); + typedef std::stack Nodes; Nodes nodes_; Errors errors_; @@ -1036,6 +1039,13 @@ private: // complete copy of Read impl, for OurReader +bool OurReader::containsNewLine(OurReader::Location begin, OurReader::Location end) { + for (; begin < end; ++begin) + if (*begin == '\n' || *begin == '\r') + return true; + return false; +} + OurReader::OurReader(OurFeatures const& features) : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(), lastValue_(), commentsBefore_(), @@ -1345,6 +1355,25 @@ bool OurReader::readComment() { return true; } +JSONCPP_STRING OurReader::normalizeEOL(OurReader::Location begin, OurReader::Location end) { + JSONCPP_STRING normalized; + normalized.reserve(static_cast(end - begin)); + OurReader::Location current = begin; + while (current != end) { + char c = *current++; + if (c == '\r') { + if (current != end && *current == '\n') + // convert dos EOL + ++current; + // convert Mac EOL + normalized += '\n'; + } else { + normalized += c; + } + } + return normalized; +} + void OurReader::addComment(Location begin, Location end, CommentPlacement placement) { assert(collectComments_); diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 791176e..2a53138 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1453,8 +1453,13 @@ ptrdiff_t Value::getOffsetStart() const { return start_; } ptrdiff_t Value::getOffsetLimit() const { return limit_; } JSONCPP_STRING Value::toStyledString() const { - StyledWriter writer; - return writer.write(*this); + StreamWriterBuilder builder; + + JSONCPP_STRING out = this->hasComment(commentBefore) ? "\n" : ""; + out += Json::writeString(builder, *this); + out += "\n"; + + return out; } Value::const_iterator Value::begin() const {