Skip to content

Fixing warnings. Added JSONCPP_DEPRECATED definition for clang. Also … #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ jsoncpp_lib_static.dir/
.project
.cproject
/.settings/

# DS_Store
.DS_Store
3 changes: 3 additions & 0 deletions include/json/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
5 changes: 4 additions & 1 deletion include/json/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -230,6 +230,9 @@ class JSON_API Reader {
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<Value*> Nodes;
Nodes nodes_;
Errors errors_;
Expand Down
2 changes: 2 additions & 0 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions include/json/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
/** \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();

Expand All @@ -156,7 +156,7 @@ class JSON_API Writer {
* \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();
Expand Down Expand Up @@ -209,7 +209,7 @@ class JSON_API FastWriter : public Writer {
* \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 {}
Expand Down Expand Up @@ -267,12 +267,14 @@ class JSON_API StyledWriter : public Writer {
* 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() {}

Expand Down
33 changes: 31 additions & 2 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<size_t>(end - begin));
Reader::Location current = begin;
Expand Down Expand Up @@ -1019,6 +1019,9 @@ class OurReader {
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<Value*> Nodes;
Nodes nodes_;
Errors errors_;
Expand All @@ -1036,6 +1039,13 @@ class OurReader {

// 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_(),
Expand Down Expand Up @@ -1345,6 +1355,25 @@ bool OurReader::readComment() {
return true;
}

JSONCPP_STRING OurReader::normalizeEOL(OurReader::Location begin, OurReader::Location end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not duplicate so much code. Is there a simpler way?

JSONCPP_STRING normalized;
normalized.reserve(static_cast<size_t>(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_);
Expand Down
9 changes: 7 additions & 2 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" : "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems slow. And this might alter the behavior of toStyledString().

out += Json::writeString(builder, *this);
out += "\n";

return out;
}

Value::const_iterator Value::begin() const {
Expand Down